JJ.Framework.Reflection.Legacy
0.250.3304
Prefix Reserved
dotnet add package JJ.Framework.Reflection.Legacy --version 0.250.3304
NuGet\Install-Package JJ.Framework.Reflection.Legacy -Version 0.250.3304
<PackageReference Include="JJ.Framework.Reflection.Legacy" Version="0.250.3304" />
<PackageVersion Include="JJ.Framework.Reflection.Legacy" Version="0.250.3304" />
<PackageReference Include="JJ.Framework.Reflection.Legacy" />
paket add JJ.Framework.Reflection.Legacy --version 0.250.3304
#r "nuget: JJ.Framework.Reflection.Legacy, 0.250.3304"
#:package JJ.Framework.Reflection.Legacy@0.250.3304
#addin nuget:?package=JJ.Framework.Reflection.Legacy&version=0.250.3304
#tool nuget:?package=JJ.Framework.Reflection.Legacy&version=0.250.3304
JJ.Framework.Reflection.Legacy
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 Private => 3;
}
You can run that private method, that would otherwise not be available:
var obj = new MyClass();
var acc = new MyAccessor(obj);
int num = acc.Private;
You can do that by writing the following wrapper class:
class MyAccessor(MyClass myObject)
{
Accessor _accessor = new(myObject);
public int Private
=> _accessor.GetPropertyValue(() => Private);
}
Limitations
Accessor
may suffice for most use cases, but there are some cases where 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
IsNullableType
- Returns
true
if the given type is a value type that allowsnull
, likeint?
orNullable<bool>
.
- Returns
GetUnderlyingNullableType
- Slightly faster than
Nullable.GetUnderlyingType
.
- Slightly faster than
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
💬 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. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.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.Legacy (>= 0.250.3304)
- JJ.Framework.PlatformCompatibility.Legacy (>= 0.250.3304)
-
.NETStandard 2.1
- JJ.Framework.Common.Legacy (>= 0.250.3304)
- JJ.Framework.PlatformCompatibility.Legacy (>= 0.250.3304)
-
net8.0
- JJ.Framework.Common.Legacy (>= 0.250.3304)
- JJ.Framework.PlatformCompatibility.Legacy (>= 0.250.3304)
-
net9.0
- JJ.Framework.Common.Legacy (>= 0.250.3304)
- JJ.Framework.PlatformCompatibility.Legacy (>= 0.250.3304)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last Updated |
---|---|---|
0.250.3304 | 67 | 7/5/2025 |
0.250.3301 | 82 | 7/5/2025 |
0.250.3296 | 129 | 7/3/2025 |
0.250.3283 | 131 | 7/3/2025 |
0.250.3272 | 180 | 7/2/2025 |
0.250.3271 | 132 | 7/2/2025 |