The documentation comes from the Markdown files in the source code, so is always up-to-date but available only in English. Enjoy!
Some extensions to enrich [Reflection API][http://msdn.microsoft.com/en-us/library/f7ykdhsy(VS.80).aspx]. See also ReflectionUtils.
Extension methods over System.Type to deal with Nullable Types.
public static bool IsNullable(this Type type)
public static Type Nullify(this Type type)
public static Type UnNullify(this Type type)
Examples:
Type intType = typeof(int);
Console.WriteLine(intType.IsNullable()); //false
Type nIntType = intType.Nullify();
Console.WriteLine(nIntType.IsNullable()); //true
Console.WriteLine(nIntType.UnNullify() == intType); //true
Gets the returning type for a PropertyInfo, FieldInfo, MethodInfo, ConstructorInfo or EventInfo in a... carefree way. Returns null for System.Type (i.e: nested Type).
public static Type ReturningType(this MemberInfo m)
Example:
MemberInfo member = typeof(Person).GetMember(DateTime.Today.Day % 2 == 0 ? "_name" : "Name");
member.ReturningType();
//Returns string type, whether a FieldInfo or a PropertyInfo is retrieved.
Allows to know easily if a MemeberInfo contains attributes of some type and retrieves them (if any).
public static bool HasAttribute<T>(this ICustomAttributeProvider mi) where T : Attribute
public static T SingleAttribute<T>(this ICustomAttributeProvider mi) where T : Attribute
Example:
[Serializable]
public class Person
{
}
typeof(Person).HasAttribute<SerializableAttribute>(); //Returns true
typeof(Person).SingleAttribute<SerializableAttribute>(); //returns the SerializableAttribute
Fast way to know if a System.Type represents a 'concretization' of a generic type.
public static bool IsInstantiationOf(this Type type, Type genericType)
Example:
typeof(List<int>).IsInstantiationOf(typeof(List<>)); // returns true
Simple way to compare a FieldInfo (or PropertyInfo) using [Reflection|Strong Typed Reflection].
public static bool FieldEquals<T>(this FieldInfo fi, Expression<Func<T, object>> lambdaToFiel)
public static bool PropertyEquals<T>(this PropertyInfo fi, Expression<Func<T, object>> lambdaToProperty)
Example:
typeof(string).GetProperty("Length").PropertyEquals((string s) => s.Length); //returns true
Returns whether a property has no setter or it's not public.
public static bool IsReadOnly(this PropertyInfo pi)
Example:
typeof(string).GetProperty("Length").IsReadOnly(); //returns true
© Signum Software. All Rights Reserved.
Powered by Signum Framework