/// <summary> /// Determines whether the property is an indexed property. /// </summary> /// <param name="property">The property.</param> /// <returns> /// <c>true</c> if the property is an indexed property; otherwise, <c>false</c>. /// </returns> public static bool IsIndexedProperty(PropertyInfo property) { ValidationUtils.ArgumentNotNull(property, nameof(property)); return(property.GetIndexParameters().Length > 0); }
public static Attribute[] GetAttributes(object attributeProvider, Type attributeType, bool inherit) { ValidationUtils.ArgumentNotNull(attributeProvider, nameof(attributeProvider)); object provider = attributeProvider; // http://hyperthink.net/blog/getcustomattributes-gotcha/ // ICustomAttributeProvider doesn't do inheritance if (provider is Type) { Type t = (Type)provider; object[] a = (attributeType != null) ? t.GetCustomAttributes(attributeType, inherit) : t.GetCustomAttributes(inherit); Attribute[] attributes = a.Cast <Attribute>().ToArray(); #if (NET20 || NET35) // ye olde .NET GetCustomAttributes doesn't respect the inherit argument if (inherit && t.BaseType != null) { attributes = attributes.Union(GetAttributes(t.BaseType, attributeType, inherit)).ToArray(); } #endif return(attributes); } if (provider is Assembly) { Assembly a = (Assembly)provider; return((attributeType != null) ? Attribute.GetCustomAttributes(a, attributeType) : Attribute.GetCustomAttributes(a)); } if (provider is MemberInfo) { MemberInfo m = (MemberInfo)provider; return((attributeType != null) ? Attribute.GetCustomAttributes(m, attributeType, inherit) : Attribute.GetCustomAttributes(m, inherit)); } #if !PORTABLE40 if (provider is Module) { Module m = (Module)provider; return((attributeType != null) ? Attribute.GetCustomAttributes(m, attributeType, inherit) : Attribute.GetCustomAttributes(m, inherit)); } #endif if (provider is ParameterInfo) { ParameterInfo p = (ParameterInfo)provider; return((attributeType != null) ? Attribute.GetCustomAttributes(p, attributeType, inherit) : Attribute.GetCustomAttributes(p, inherit)); } #if !PORTABLE40 ICustomAttributeProvider customAttributeProvider = (ICustomAttributeProvider)attributeProvider; object[] result = (attributeType != null) ? customAttributeProvider.GetCustomAttributes(attributeType, inherit) : customAttributeProvider.GetCustomAttributes(inherit); return((Attribute[])result); #else throw new Exception("Cannot get attributes from '{0}'.".FormatWith(CultureInfo.InvariantCulture, provider)); #endif }
public static bool IsNullableType(Type t) { ValidationUtils.ArgumentNotNull(t, nameof(t)); return(t.IsGenericType() && t.GetGenericTypeDefinition() == typeof(Nullable <>)); }