A dotnetstandard2.0 library containing some commonly implemented reflection helpers.
v2.0 has many breaking changes. See the Version History for details.
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<int>("InternalGetField");
Console.WriteLine(val);
- Kristian Hellang on GitHub for the 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.
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 toGetMethods
- The filter parameter was moved to the last parameter on an overload of
GetMethods
(formerlyFilterMethods
). - Renamed
EnumerationSettings
toFilter
inMemberInfoEnumerator
,FieldOrPropertyEnumerator
, andMethodInfoEnumerator
- Moved and renamed type from
MethodInfoEnumerator.Settings
toMethodInfoFilter
. - Moved predefined instances of
MethodInfoEnumerator.Settings
fromMethodInfoEnumerator
toMethodInfoFilter
. - Moved and renamed type from
MemberInfoEnumerator.Settings
toMemberInfoFilter
. - Moved and renamed type from
FieldOrPropertyEnumerator.Settings
toFieldOrPropertyInfoFilter
. MethodInfoFilter
,MemberInfoFilter
,FieldOrPropertyInfoFilter
fields are now get-only properties, requiring a call tonew
to create new instances.- To facilitate the use of init properties on
MethodInfoFilter
,MemberInfoFilter
,FieldOrPropertyInfoFilter
types, a customIsExternalInit
is required of target frameworks not supporting it. See this project's source code for an example (IsExternalInit.cs
). - Extension methods
GetCusomAttributes
andHasAttribute
were moved into classes named after the underlying method. This will only break non-extension invocations.