https://github.com/jason-c-daniels/jcd.reflection
A set of reflection helpers.
https://github.com/jason-c-daniels/jcd.reflection
c-sharp csharp dotnet netstandard20 reflection reflection-library
Last synced: 9 months ago
JSON representation
A set of reflection helpers.
- Host: GitHub
- URL: https://github.com/jason-c-daniels/jcd.reflection
- Owner: jason-c-daniels
- License: mit
- Created: 2021-10-08T21:21:13.000Z (over 4 years ago)
- Default Branch: main
- Last Pushed: 2024-03-31T20:25:31.000Z (almost 2 years ago)
- Last Synced: 2025-03-15T23:36:26.701Z (10 months ago)
- Topics: c-sharp, csharp, dotnet, netstandard20, reflection, reflection-library
- Language: C#
- Homepage:
- Size: 481 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Jcd.Reflection
A _dotnetstandard2.0_ library containing some commonly implemented reflection helpers.
v2.0 has many breaking changes. See the [Version History](#version-history) for details.
## Examples
```csharp
internal static class Program
{
private static void Main()
{
var c = new TestClass();
// set the private field, _field
c.SetValue("_field",10);
// now get its value.
var val = (int)c.GetValue("_field");
Console.WriteLine(val);
// Now set a private property with a backing field.
c.SetValue("PrivateProperty",20);
// Now call a private helper method that returns the value from the backing field.
val = c.Invoke("InternalGetField");
Console.WriteLine(val);
```
## Special Thanks To
* [Kristian Hellang on GitHub](https://github.com/khellang) for the [Scrutor](https://github.com/khellang/Scrutor)
project.
Scrutor inspired the technique I'm using for finding implementations of specific types as well as
a couple of other handy utility methods.
## Badges
[](https://github.com/jason-c-daniels/Jcd.Reflection/blob/main/LICENSE)
[](https://ci.appveyor.com/project/jason-c-daniels/jcd-reflection)
[](https://www.codefactor.io/repository/github/jason-c-daniels/jcd.reflection)
[](https://www.myget.org/feed/jason-c-daniels/package/nuget/Jcd.Reflection)
[](https://www.nuget.org/packages/Jcd.Reflection)
[](https://github.com/jason-c-daniels/Jcd.Reflection/blob/main/docs/Jcd.Reflection.md)
## Version History
### v2.0 Breaking Changes
Version 2.0 comes with a significant number of breaking changes for advanced use cases. These are listed below
- `ExpandoObjectExtensions` was removed. It wasn't functioning as planned. An overhaul of the approach is needed.
- All overloads of `FilterMethods` were renamed to `GetMethods`
- The filter parameter was moved to the last parameter on an overload of `GetMethods` (formerly `FilterMethods`).
- Renamed `EnumerationSettings` to `Filter` in `MemberInfoEnumerator`, `FieldOrPropertyEnumerator`,
and `MethodInfoEnumerator`
- Moved and renamed type from `MethodInfoEnumerator.Settings` to `MethodInfoFilter`.
- Moved predefined instances of `MethodInfoEnumerator.Settings` from `MethodInfoEnumerator` to `MethodInfoFilter`.
- Moved and renamed type from `MemberInfoEnumerator.Settings` to `MemberInfoFilter`.
- Moved and renamed type from `FieldOrPropertyEnumerator.Settings` to `FieldOrPropertyInfoFilter`.
- `MethodInfoFilter`, `MemberInfoFilter`, `FieldOrPropertyInfoFilter` fields are now get-only properties, requiring a
call to `new` to create new instances.
- To facilitate the use of init properties on `MethodInfoFilter`, `MemberInfoFilter`, `FieldOrPropertyInfoFilter`
types, a custom `IsExternalInit` is required of target frameworks not supporting it. See this project's source code
for an example ([`IsExternalInit.cs`](Jcd.Reflection/IsExternalInit.cs)).
- Extension methods `GetCusomAttributes` and `HasAttribute` were moved into classes named after the underlying method.
This will only break non-extension invocations.