C# Client Library
A C# Client Library for the AnalyzeRe REST API
Loading...
Searching...
No Matches
AnalyzeRe.Utilities.ReflectionUtilities Class Reference

Utilities that reflect on a type or property expression. More...

Static Public Member Functions

static object GetCustomAttributeFast (this MemberInfo member, Type attributeType)
 Gets the specified attribute from the member.
 
static T GetCustomAttributeFast< T > (this MemberInfo member)
 Gets the specified attribute from the member.
 
static MemberInfo GetMemberInfo< T > (Expression< T > expression)
 Get the MemberInfo associated with an Expression, if possible.
 
static string GetPropertyName< TObject > (Expression< Func< TObject, object > > propertyExpression)
 Gets the string name of a property from a LINQ expression such as GetPropertyName( ()=>SomeProperty ). This is a preferred method of generating string property names for property changed notification since it is not susceptible to property renaming or typos.
 
static FieldInfo[] GetPublicFields_Fast (this Type type)
 Get all public instance fields of a type, and cache the result so that future reflection on the same type is faster.
 
static PropertyInfo[] GetPublicProperties_Fast (this Type type)
 Get all public instance properties of a type, and cache the result so that future reflection on the same type is faster.
 
static PropertyInfo[] GetUserFacingProperties (this Type type, bool excludeServerGenerated=false, bool excludeNotWritable=false, bool excludeNotSerialized=false)
 Gets the "user-facing" PropertyInfo, which has been filtered from the set of all public properties of the specified type. Excludes from the list any properties that cannot be read, or that have the attribute ObsoleteAttribute and/or InternalMemberAttribute defined (which means those properties are intended for internal use). Optionally excludes properties based on other attributes depending on arguments.
 
static bool IsAttributeDefinedFast (this MemberInfo member, Type attributeType)
 Determines whether the member has the specified attribute defined.
 
static bool IsAttributeDefinedFast< T > (this MemberInfo member)
 Determines whether the member has the specified attribute defined.
 
static bool IsSubclassOfRawGeneric (this Type toCheck, Type generic)
 Checks if a type is a subclass of a generic type.
 
static bool PropertyHasAttribute< T > (Expression< T > expression, Type attributeType)
 Determines whether the property denoted by the expression has the specified attribute defined.
 
static T ShallowCopy< T > (T toCopy)
 Attempt to make a shallow copy of the specified object by reflecting on its public properties.
 

Static Public Attributes

const BindingFlags PublicInstanceBindingFlags
 Flags for retrieving all declared and inherited public instance members.
 

Detailed Description

Utilities that reflect on a type or property expression.

Definition at line 14 of file ReflectionUtilities.cs.

Member Function Documentation

◆ GetCustomAttributeFast()

static object AnalyzeRe.Utilities.ReflectionUtilities.GetCustomAttributeFast ( this MemberInfo  member,
Type  attributeType 
)
inlinestatic

Gets the specified attribute from the member.

Parameters
memberThe member to get the custom attribute of.
attributeTypeThe type of the attribute to look for.
Returns
True if the attribute is defined on the specified member.

Definition at line 108 of file ReflectionUtilities.cs.

◆ GetCustomAttributeFast< T >()

static T AnalyzeRe.Utilities.ReflectionUtilities.GetCustomAttributeFast< T > ( this MemberInfo  member)
inlinestatic

Gets the specified attribute from the member.

Template Parameters
TThe type of the attribute to look for.
Parameters
memberThe member to get the custom attribute of.
Returns
True if the attribute is defined on the specified member.

Definition at line 99 of file ReflectionUtilities.cs.

◆ GetMemberInfo< T >()

static MemberInfo AnalyzeRe.Utilities.ReflectionUtilities.GetMemberInfo< T > ( Expression< T >  expression)
inlinestatic

Get the MemberInfo associated with an Expression, if possible.

Parameters
expressionThe expression to get the MemberInfo from.
Template Parameters
TThe expression body type.
Returns
The MemberInfo, or throws an exception if none was found.
Exceptions
ArgumentExceptionNo MemberExpression found in expression.

Definition at line 35 of file ReflectionUtilities.cs.

◆ GetPropertyName< TObject >()

static string AnalyzeRe.Utilities.ReflectionUtilities.GetPropertyName< TObject > ( Expression< Func< TObject, object > >  propertyExpression)
static

Gets the string name of a property from a LINQ expression such as GetPropertyName( ()=>SomeProperty ). This is a preferred method of generating string property names for property changed notification since it is not susceptible to property renaming or typos.

Template Parameters
TObjectThe object type that contains the specified property.
Parameters
propertyExpressionA LINQ expression containing the property whose name is to be returned. e.g.: GetPropertyName( ()=>SomeProperty )
Returns
The name of the property in the LINQ expression.

◆ GetPublicFields_Fast()

static FieldInfo[] AnalyzeRe.Utilities.ReflectionUtilities.GetPublicFields_Fast ( this Type  type)
inlinestatic

Get all public instance fields of a type, and cache the result so that future reflection on the same type is faster.

Parameters
typeType to get public fields of.
Returns
Array of public fields
Exceptions
ArgumentNullExceptiontype is null.

Definition at line 253 of file ReflectionUtilities.cs.

◆ GetPublicProperties_Fast()

static PropertyInfo[] AnalyzeRe.Utilities.ReflectionUtilities.GetPublicProperties_Fast ( this Type  type)
inlinestatic

Get all public instance properties of a type, and cache the result so that future reflection on the same type is faster.

Parameters
typeType to get public properties of.
Returns
Array of public properties
Exceptions
ArgumentNullExceptiontype is null.

Definition at line 206 of file ReflectionUtilities.cs.

◆ GetUserFacingProperties()

static PropertyInfo[] AnalyzeRe.Utilities.ReflectionUtilities.GetUserFacingProperties ( this Type  type,
bool  excludeServerGenerated = false,
bool  excludeNotWritable = false,
bool  excludeNotSerialized = false 
)
inlinestatic

Gets the "user-facing" PropertyInfo, which has been filtered from the set of all public properties of the specified type. Excludes from the list any properties that cannot be read, or that have the attribute ObsoleteAttribute and/or InternalMemberAttribute defined (which means those properties are intended for internal use). Optionally excludes properties based on other attributes depending on arguments.

Parameters
typeType to get public properties of.
excludeServerGeneratedOptional (Default: False) Exclude properties that carry the ServerGenerated attribute, meaning that this property is normally assigned its value by the server, not the user.
excludeNotWritableOptional (Default: False) Exclude properties that cannot be assigned to (do not have a "set" method) from the list.
excludeNotSerializedOptional (Default: False) Exclude properties that carry the IgnoreDataMemberAttribute attribute, meaning that they are not serialized to JSON when transmitting the object to/from the API.
Returns
Array of public properties filtered b the specified parameters.
Exceptions
ArgumentNullExceptiontype is null.

Definition at line 147 of file ReflectionUtilities.cs.

◆ IsAttributeDefinedFast()

static bool AnalyzeRe.Utilities.ReflectionUtilities.IsAttributeDefinedFast ( this MemberInfo  member,
Type  attributeType 
)
inlinestatic

Determines whether the member has the specified attribute defined.

Parameters
memberThe member to check if an attribute is defined on.
attributeTypeThe type of the attribute to look for.
Returns
True if the attribute is defined.

Definition at line 90 of file ReflectionUtilities.cs.

◆ IsAttributeDefinedFast< T >()

static bool AnalyzeRe.Utilities.ReflectionUtilities.IsAttributeDefinedFast< T > ( this MemberInfo  member)
inlinestatic

Determines whether the member has the specified attribute defined.

Template Parameters
TThe type of the attribute to look for.
Parameters
memberThe member to check if an attribute is defined on.
Returns
True if the attribute is defined.

Definition at line 81 of file ReflectionUtilities.cs.

◆ IsSubclassOfRawGeneric()

static bool AnalyzeRe.Utilities.ReflectionUtilities.IsSubclassOfRawGeneric ( this Type  toCheck,
Type  generic 
)
inlinestatic

Checks if a type is a subclass of a generic type.

Definition at line 47 of file ReflectionUtilities.cs.

◆ PropertyHasAttribute< T >()

static bool AnalyzeRe.Utilities.ReflectionUtilities.PropertyHasAttribute< T > ( Expression< T >  expression,
Type  attributeType 
)
inlinestatic

Determines whether the property denoted by the expression has the specified attribute defined.

Template Parameters
TThe expression body type.
Parameters
expressionThe expression to get the MemberInfo from.
attributeTypeThe type of the attribute to look for
Returns
True if the attribute is defined.

Definition at line 65 of file ReflectionUtilities.cs.

◆ ShallowCopy< T >()

static T AnalyzeRe.Utilities.ReflectionUtilities.ShallowCopy< T > ( toCopy)
inlinestatic

Attempt to make a shallow copy of the specified object by reflecting on its public properties.

Parameters
toCopythe object to copy.

Definition at line 266 of file ReflectionUtilities.cs.

Member Data Documentation

◆ PublicInstanceBindingFlags

const BindingFlags AnalyzeRe.Utilities.ReflectionUtilities.PublicInstanceBindingFlags
static
Initial value:
=
BindingFlags.FlattenHierarchy | BindingFlags.Public | BindingFlags.Instance

Flags for retrieving all declared and inherited public instance members.

Definition at line 17 of file ReflectionUtilities.cs.


The documentation for this class was generated from the following file: