JJ.Framework.Reflection
0.250.2323
Prefix Reserved
See the version list below for details.
dotnet add package JJ.Framework.Reflection --version 0.250.2323
NuGet\Install-Package JJ.Framework.Reflection -Version 0.250.2323
<PackageReference Include="JJ.Framework.Reflection" Version="0.250.2323" />
<PackageVersion Include="JJ.Framework.Reflection" Version="0.250.2323" />
<PackageReference Include="JJ.Framework.Reflection" />
paket add JJ.Framework.Reflection --version 0.250.2323
#r "nuget: JJ.Framework.Reflection, 0.250.2323"
#addin nuget:?package=JJ.Framework.Reflection&version=0.250.2323
#tool nuget:?package=JJ.Framework.Reflection&version=0.250.2323
JJ.Framework.Reflection
Extensions to the System.Reflection
and System.Linq.Expressions
namespaces.
Work with expressions and reflection. Turn lambdas into text: "myParam.MyList[i].MyProperty"
. Extract structured method call data: { "MyMethod", Parameters = { "myParameter", int, 3 } }
. Find types and implementations for plug-ins. Access private members with Accessors
. Use ReflectionCache
for fast access to properties, fields, methods and indexers. Includes helpers like IsIndexer
, IsStatic
and more!
ExpressionHelper
Converts many types of lambda expressions into text or retrieves its resulting value. Here are some of the things it can do:
For instance:
GetText(() => myParam.MyProperty.MyList[i].MySomething)
Will return the string:
"myParam.MyProperty.MyList[i].MySomething"
Similarly you can retrieve its value:
GetValue(() => myParam.MyProperty.MyList[i].MySomething)
which can return:
3
It can also give you method info, parameter names and parameter value info from lambda expressions.
For instance:
GetMethodCallInfo(() => MyMethod(3));
Will return:
MethodCallInfo
{
Name = "MyMethod",
Parameters =
{
ParameterType = typeof(int),
Name = "myParameter",
Value = 3
}
};
Accessor
Allows easy access to the internal, private or protected elements of an assembly or class.
For instance if you have the following private method in a class:
class MyClass
{
private int MyPrivateMethod(int myParameter)
{
return 3;
}
}
You can run that private method, that would otherwise not be available:
var myObject = new MyClass();
var accessor = new MyAccessor(myObject);
int myInt = accessor.MyPrivateMethod(1);
You can do that by writing the following wrapper class:
class MyAccessor
{
Accessor _accessor;
public MyAccessor(MyClass myObject) => _accessor = new Accessor(myObject);
public int MyPrivateMethod(int myParameter)
=> _accessor.InvokeMethod(() => MyPrivateMethod((myParameter));
}
Limitations
If Accessor
doesn't suffice for some use case, it might be an idea to use System.Reflection
directly or PrivateObject
and PrivateType
from a test framework you might use. Those may have slightly more complex syntax, but may offer a diversion where this Accessor
class might not be able to help you.
ReflectionCache
Makes using reflection much faster in certain cases. For instance the GetProperties
method can be expensive, which is much faster through the ReflectionCache
class.
Example:
private static readonly ReflectionCache _reflectionCache
= new ReflectionCache(BindingFlags.Public | BindingFlags.Instance);
PropertyInfo[] properties
= _reflectionCache.GetProperties(typeof(MyClass));
You can also get other types of constructs in a fast way:
Methods
Indexers
Fields
Constructor
GetTypeByShortName
In this version, some of the options may only be available in the StaticReflectionCache
variant. That variant may perform slightly less fast.
Reflection Helpers
Various helper methods, but one of the most useful features is the GetImplementation
method and variations thereof, which allow you to retrieve implementations of a specified base class or interface from an assembly, which is useful for plug-in development.
GetImplementations
- Allows you to retrieve implementations of a specified base class or interface from an assembly, which is useful for plug-in development.
GetItemType
- Gets the item type of a collection type.
IsIndexerMethod
- Can tell you if a
MethodInfo
points to an indexer property.
- Can tell you if a
IsStatic
- Can tell you if a
MemberInfo
is static.
- Can tell you if a
TypesFromObjects
- You can pass objects to it, and it will return the concrete types of those objects, with some tolerance for nulls.
IsAssignableFrom
/IsAssignableTo
- Similar to the original
Type.IsAssignableFrom
, but now also anIsAssignableTo
variation, if you find that more intuitive.
- Similar to the original
GetFieldOrException
Type.GetField
returns null if the field does not exist. This method is a little safer than that and throws a clear exception if the field does not exist.
💬 Feedback
Found an issue? Let me know.
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 is compatible. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. |
.NET Core | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
.NET Standard | netstandard2.0 is compatible. netstandard2.1 is compatible. |
.NET Framework | net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
MonoAndroid | monoandroid was computed. |
MonoMac | monomac was computed. |
MonoTouch | monotouch was computed. |
Tizen | tizen40 was computed. tizen60 was computed. |
Xamarin.iOS | xamarinios was computed. |
Xamarin.Mac | xamarinmac was computed. |
Xamarin.TVOS | xamarintvos was computed. |
Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETStandard 2.0
- JJ.Framework.Common (>= 0.250.2323)
- JJ.Framework.PlatformCompatibility (>= 0.250.2323)
-
.NETStandard 2.1
- JJ.Framework.Common (>= 0.250.2323)
- JJ.Framework.PlatformCompatibility (>= 0.250.2323)
-
net8.0
- JJ.Framework.Common (>= 0.250.2323)
- JJ.Framework.PlatformCompatibility (>= 0.250.2323)
-
net9.0
- JJ.Framework.Common (>= 0.250.2323)
- JJ.Framework.PlatformCompatibility (>= 0.250.2323)
NuGet packages (7)
Showing the top 5 NuGet packages that depend on JJ.Framework.Reflection:
Package | Downloads |
---|---|
JJ.Framework.Exceptions
Contains many exception classes for common basic errors. Clear messages, concise syntax, strongly-typed, good performance. Generates messages like "myParent.MyChildren[0].MyProperty is null.", "height of 2 is less than 10.", "Customer with key { customerNumber = 1234, customerType = Subscriber } not found." |
|
JJ.Framework.Conversion
Makes it easier to convert simple types. |
|
JJ.Framework.Xml
XmlToObjectConverter converts an XmlDocument or string to an object graph. The way to map XML to classes is easier than the classic ways in .NET. XmlHelper allows you to access XML in a null-safe and multiplicity-safe way. It uses XmlDocument as the underlying .NET API. |
|
JJ.Framework.Collections
LINQ overloads. SelectRecursive SelectAncestors Add Remove AddRange Concat CrossJoin Distinct DistinctMany Except FirstWithClearException SingleOrDefaultWithClearException SingleWithClearException ForEach IndexOf TryGetIndexOf MinOrDefault MaxOrDefault PeekOrDefault PopOrDefault Product RemoveFirst Repeat ToHashSet ToNonUniqueDictionary TrimAll TryRemoveFirst Union Zip item.AsArray item.AsList item.AsEnumerable. Also a RedBlackTree and KeyValuePairHelper ConvertNamesAndValuesListToKeyValuePairs and ConvertNamesAndValuesListToDictionary. |
|
JJ.Framework.Testing
Helper for unit tests. Mimics the Assert class, but will display the tested expression in error messages, instead of being vague about it or laborious to program. It also offers methods to evaluate if the right exception goes off in the right spot with the right exception type and / or the right message. |
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last updated |
---|---|---|
1.5.6877.41324 | 11,409 | 10/31/2018 |
1.4.6874.33783 | 9,259 | 10/27/2018 |
1.4.6870.35782 | 8,691 | 10/23/2018 |
1.4.6870.35459 | 9,797 | 10/23/2018 |
1.4.6862.40441 | 14,815 | 10/15/2018 |
1.3.6681.33420 | 7,758 | 4/17/2018 |
1.2.6640.39173 | 6,802 | 3/7/2018 |
1.1.0.31224 | 7,227 | 3/4/2018 |
1.0.6633.36153 | 1,901 | 2/28/2018 |
1.0.6633.34565 | 11,938 | 2/28/2018 |
0.250.2324 | 137 | 4/27/2025 |
0.250.2323 | 140 | 4/27/2025 |
0.250.2322 | 139 | 4/27/2025 |
0.250.2313 | 173 | 4/27/2025 |