Exemple #1
0
        internal static T GetRequiredSingleAttribute <T>(CustomAttributeProvider attrProvider, Type[] attrTypeGroup)
            where T : class
        {
            T result = GetSingleAttribute <T>(attrProvider, attrTypeGroup);

            if (result == null)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.Format(SR.couldnTFindRequiredAttributeOfTypeOn2, typeof(T), attrProvider.ToString())));
            }
            return(result);
        }
Exemple #2
0
        internal static T GetSingleAttribute <T>(CustomAttributeProvider attrProvider) where T : class
        {
            Type attrType = typeof(T);

            object[] attrs = GetCustomAttributes(attrProvider, attrType);
            if (attrs.Length == 0)
            {
                return(null);
            }
            else if (attrs.Length > 1)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.Format(SR.tooManyAttributesOfTypeOn2, attrType, attrProvider.ToString())));
            }
            else
            {
                return(attrs[0] as T);
            }
        }