https://github.com/vikashchauhan51/reflector
Reflection `Type` helper utility.
https://github.com/vikashchauhan51/reflector
dotnet dotnet-core reflection reflection-api reflection-utils types
Last synced: 10 months ago
JSON representation
Reflection `Type` helper utility.
- Host: GitHub
- URL: https://github.com/vikashchauhan51/reflector
- Owner: VikashChauhan51
- License: mit
- Created: 2021-12-05T10:37:46.000Z (about 4 years ago)
- Default Branch: main
- Last Pushed: 2025-01-22T05:43:41.000Z (about 1 year ago)
- Last Synced: 2025-02-22T07:17:00.095Z (12 months ago)
- Topics: dotnet, dotnet-core, reflection, reflection-api, reflection-utils, types
- Language: C#
- Homepage:
- Size: 73.2 KB
- Stars: 1
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# VReflector
[](https://www.nuget.org/packages/VReflector/)
[](https://www.nuget.org/packages/VReflector/)
[](https://github.com/VikashChauhan51/resultify/actions)
[](https://github.com/VikashChauhan51/resultify/blob/main/LICENSE)
**VReflector** is `Object`,`Type`,`Constructor`,`Method`,`Member`,`Event`,`Field`,`Property`,`Parameter`,`Assembly`,`StackTrace`,`Numerics` `String`,`DateTime`,`DateOnly`,`TimeOnly`,`TimeSpan` and `DateTimeOffset` helpers utility.
## Installation
You can install the VReflector package via NuGet:
```shell
dotnet add package VReflector
```
Or you can use the NuGet Package Manager:
```shell
Install-Package VReflector
```
## Basic usage
```C#
// Check type is mutable or not.
public class ImmutableUser
{
public readonly int Id;
public string Name { get; init; }
public static readonly int status;
public static string Message { get; }
}
public class MutableUser
{
public readonly int Id;
public string Name { get; init; }
public static string Message { get; private set; }
}
var result1 = typeof(ImmutableUser).GetTypeInfo().IsMutable();
var result2 = typeof(MutableUser).GetTypeInfo().IsMutable();
```
```C#
// Deep check type is mutable or not.
public abstract class A
{
public int Id { get; private set; }
public string? Name { get; init; }
}
public class B : A
{
}
public class C : B
{
public A? MyProperty { get; }
}
public class D : C
{
public B? MyProperty2 { get; }
public IA? MyProperty3 { get; init; }
}
var result1 = typeof(D).GetTypeInfo().IsMutable();
var result2 = typeof(D).IsDeepMutable();
```
```C#
// Get all parents.
public abstract class A
{
public int Id { get; private set; }
public string? Name { get; init; }
}
public class B : A
{
}
public class C : B
{
public A? MyProperty { get; }
}
public class D : C
{
public B? MyProperty2 { get; }
public IA? MyProperty3 { get; init; }
}
var result = typeof(D).GetParentTypes();
```
## Check static class
``` C#
public static class MyStaticClass
{
}
typeof(MyStaticClass).IsStatic() //true
```
## Check record class
``` C#
public record MyEmptyRecord
{
}
typeof(MyEmptyRecord).IsRecordClass() //true
```
## Check anonymous class
``` C#
// Create an anonymous type.
var anonType = new
{
Name = "Bill",
Age = 30
};
var type = anonType.GetType();
var result = type.IsAnonymous(); //true
```
## Get Class,Enum and Struct Access modifier and modifiers
``` C#
// Create an anonymous type.
protected internal abstract class PublicClass
{
}
var type = typeof(PublicClass);
var result = type.GetAccessModifier(); // protected internal
var info = type.GetTypeModifiers(); // abstract class
```
## Get Method Access modifier and modifiers
``` C#
// Create an anonymous type.
protected internal abstract class PublicClass
{
}
var type = typeof(PublicClass);
var method = type.GetMethod("ToString");
var result = method.GetMethodAccessModifier(); // public
var info = method.GetMethodModifiers(); // virtual
```
Lot more...