{"id":13445667,"url":"https://github.com/ReflectionMagic/ReflectionMagic","last_synced_at":"2025-03-20T21:30:59.494Z","repository":{"id":1603858,"uuid":"2183925","full_name":"ReflectionMagic/ReflectionMagic","owner":"ReflectionMagic","description":"Framework to drastically simplify your private reflection code using C# dynamic","archived":false,"fork":false,"pushed_at":"2024-01-29T17:14:08.000Z","size":119,"stargazers_count":330,"open_issues_count":0,"forks_count":46,"subscribers_count":17,"default_branch":"master","last_synced_at":"2024-09-19T08:38:26.973Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"http://blogs.msdn.com/b/davidebb/archive/2010/01/18/use-c-4-0-dynamic-to-drastically-simplify-your-private-reflection-code.aspx","language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":"commonsense/conceptnet5","license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ReflectionMagic.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null}},"created_at":"2011-08-10T07:32:51.000Z","updated_at":"2024-08-21T02:45:25.000Z","dependencies_parsed_at":"2023-07-06T15:46:26.989Z","dependency_job_id":null,"html_url":"https://github.com/ReflectionMagic/ReflectionMagic","commit_stats":{"total_commits":77,"total_committers":9,"mean_commits":8.555555555555555,"dds":"0.33766233766233766","last_synced_commit":"5ea49de41d6f02234eb4f17e1478e937f302fcb2"},"previous_names":["davidebbo/reflectionmagic"],"tags_count":9,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ReflectionMagic%2FReflectionMagic","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ReflectionMagic%2FReflectionMagic/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ReflectionMagic%2FReflectionMagic/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ReflectionMagic%2FReflectionMagic/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ReflectionMagic","download_url":"https://codeload.github.com/ReflectionMagic/ReflectionMagic/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":221807771,"owners_count":16883643,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-07-31T05:00:37.594Z","updated_at":"2025-03-20T21:30:59.488Z","avatar_url":"https://github.com/ReflectionMagic.png","language":"C#","readme":"# ReflectionMagic\n[![Build Status](https://dev.azure.com/jvandertil/OpenSource/_apis/build/status/github/ReflectionMagic/ReflectionMagic/Continuous%20Integration?branchName=master)](https://dev.azure.com/jvandertil/OpenSource/_build/latest?definitionId=3\u0026branchName=master)\n\nPrivate reflection allows you to access private and internal members in other assemblies.  Generally, it’s considered to be a bad thing to do, as it ties you to undocumented implementation details which can later break you.  Also, it’s not usable in medium trust.\n\nThe purpose of this library is not to encourage anyone to use private reflection in situations where you would not have done it anyway.  Instead, the purpose is to allow you to do it much more easily if you decide that you need to use it. \n\n_Putting it a different way, I’m not telling you to break the law, but I’m telling you how to break the law more efficiently if that’s what you’re into!_\n\n## The scenario\n\nAssume you are using an assembly that has code like this:\n\n```cs\npublic class Foo1 \n{\n    private Foo2 GetOtherClass() \n    { \n        // Omitted\n    }\n}\n\ninternal class Foo2 \n{\n    private string SomeProp { get { /* Omitted */ } }\n}\n```\nAnd assume you have an instance _foo1_ of the public class Foo1 and your evil self tells you that you want to call the private method _GetOtherClass()_ and then get the _SomeProp_ property off that.\n\n### Using reflection\nUsing plain old reflection this would be something like this:\n\n```cs\nobject foo2 = typeof(Foo1).InvokeMember(\"GetOtherClass\", \n                BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.InvokeMethod,\n                null, foo1, null);\n                \nPropertyInfo propInfo = foo2.GetType().GetProperty(\"SomeProp\",    \n                BindingFlags.Instance | BindingFlags.NonPublic);\n\nstring val = (string)propInfo.GetValue(foo2, null);\n```\nWhich works, but is pretty ugly.\n\n### Using ReflectionMagic\nDoing the same but using the ReflectionMagic library:\n```cs\nstring val = foo1.AsDynamic().GetOtherClass().SomeProp;\n```\n\n## Download\n\nThis library is available through [NuGet](https://www.nuget.org/packages/ReflectionMagic).\n\n## More info\n\nFor more information look at the original blog post by David Ebbo: https://blogs.msdn.microsoft.com/davidebb/2010/01/18/use-c-4-0-dynamic-to-drastically-simplify-your-private-reflection-code/\n\n## Known limitations\nSupport for 'out' and 'ref' parameters is not available on .NET Core 1.x runtimes. This is a runtime limitation and results in a PlatformNotSupportedException.\n","funding_links":[],"categories":["Frameworks, Libraries and Tools","框架, 库和工具"],"sub_categories":["Misc","大杂烩"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FReflectionMagic%2FReflectionMagic","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FReflectionMagic%2FReflectionMagic","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FReflectionMagic%2FReflectionMagic/lists"}