Class TypeExtensions
Contains methods to get friendly, human-readable type names even when using generics.
Original source: https://stackoverflow.com/a/41961738
Modified to be able to either use name or fullname and to adhere better to the coding style of this project. Added some comments.
Inheritance
object
TypeExtensions
Inherited Members
object.Equals(object)
object.Equals(object, object)
object.GetHashCode()
object.GetType()
object.MemberwiseClone()
object.ReferenceEquals(object, object)
object.ToString()
Namespace: InsaneScatterbrain.Extensions
Syntax
public static class TypeExtensions
Methods
GetAllPrivateFields(Type)
Gets private fields of a type, including all the private fields of its parent types.
Declaration
public static IEnumerable<FieldInfo> GetAllPrivateFields(this Type type)
Parameters
Type | Name | Description |
---|---|---|
System.Type | type | The type. |
Returns
Type | Description |
---|---|
System.Collections.Generic.IEnumerable<T><System.Reflection.FieldInfo> | Field info for all the private fields. |
GetAttribute<T>(Type)
Declaration
public static T GetAttribute<T>(this Type type) where T : Attribute
Parameters
Type | Name | Description |
---|---|---|
System.Type | type |
Returns
Type | Description |
---|---|
T |
Type Parameters
Name | Description |
---|---|
T |
GetAttributes<T>(Type)
Declaration
public static IEnumerable<T> GetAttributes<T>(this Type type) where T : Attribute
Parameters
Type | Name | Description |
---|---|---|
System.Type | type |
Returns
Type | Description |
---|---|
System.Collections.Generic.IEnumerable<T><T> |
Type Parameters
Name | Description |
---|---|
T |
GetFriendlyFullname(Type)
Gets a friendly human-readable fullname of the type, even when generics are involved.
Declaration
public static string GetFriendlyFullname(this Type type)
Parameters
Type | Name | Description |
---|---|---|
System.Type | type | The type. |
Returns
Type | Description |
---|---|
string | The friendly type fullname. |
GetFriendlyName(Type)
Gets a friendly human-readable name of the type, even when generics are involved.
Declaration
public static string GetFriendlyName(this Type type)
Parameters
Type | Name | Description |
---|---|---|
System.Type | type | The type. |
Returns
Type | Description |
---|---|
string | The friendly type name. |
GetPrivateFields(Type)
Declaration
public static IEnumerable<FieldInfo> GetPrivateFields(this Type type)
Parameters
Type | Name | Description |
---|---|---|
System.Type | type |
Returns
Type | Description |
---|---|
System.Collections.Generic.IEnumerable<T><System.Reflection.FieldInfo> |