System.MonoCustomAttrs.GetCustomAttribute C# (CSharp) Метод

GetCustomAttribute() статический приватный Метод

static private GetCustomAttribute ( ICustomAttributeProvider obj, Type attributeType, bool inherit ) : Attribute
obj ICustomAttributeProvider
attributeType Type
inherit bool
Результат Attribute
		internal static Attribute GetCustomAttribute (ICustomAttributeProvider obj,
								Type attributeType,
								bool inherit)
		{
			object[] res = GetCustomAttributes (obj, attributeType, inherit);
			if (res.Length == 0)
			{
				return null;
			}
			else if (res.Length > 1)
			{
				string msg = "'{0}' has more than one attribute of type '{1}";
				msg = String.Format (msg, obj, attributeType);
				throw new AmbiguousMatchException (msg);
			}

			return (Attribute) res[0];
		}

Usage Example

Пример #1
0
        public static Attribute GetCustomAttribute(MemberInfo element, Type attributeType, bool inherit)
        {
            // neither parameter is allowed to be null
            CheckParameters(element, attributeType);

            // MemberInfo inheritance hierarchies can be searched for attributes, so the second
            // parameter of GetCustomAttribute () is respected.
            return(MonoCustomAttrs.GetCustomAttribute(element, attributeType, inherit));
        }