コード例 #1
0
        internal static IModelBinder GetBinderFromAttributes(Type type, Action <Type> errorAction)
        {
            AttributeList allAttrs            = new AttributeList(TypeDescriptorHelper.Get(type).GetAttributes());
            CustomModelBinderAttribute binder = allAttrs.SingleOfTypeDefaultOrError <Attribute, CustomModelBinderAttribute, Type>(errorAction, type);

            return(binder == null ? null : binder.GetBinder());
        }
コード例 #2
0
        internal static IModelBinder GetBinderFromAttributes(ICustomAttributeProvider element, Action <ICustomAttributeProvider> errorAction)
        {
            CustomModelBinderAttribute[] attrs = (CustomModelBinderAttribute[])element.GetCustomAttributes(typeof(CustomModelBinderAttribute), true /* inherit */);
            // For compatibility, return null if no attributes.
            if (attrs == null)
            {
                return(null);
            }
            CustomModelBinderAttribute binder = attrs.SingleDefaultOrError(errorAction, element);

            return(binder == null ? null : binder.GetBinder());
        }
コード例 #3
0
ファイル: ModelBinders.cs プロジェクト: nobled/mono
        private static IModelBinder GetBinderFromAttributesImpl(CustomModelBinderAttribute[] attrs, Func<string> errorMessageAccessor) {
            // this method is used to get a custom binder based on the attributes of the element passed to it.
            // it will return null if a binder cannot be detected based on the attributes alone.

            if (attrs == null) {
                return null;
            }

            switch (attrs.Length) {
                case 0:
                    return null;

                case 1:
                    IModelBinder binder = attrs[0].GetBinder();
                    return binder;

                default:
                    string errorMessage = errorMessageAccessor();
                    throw new InvalidOperationException(errorMessage);
            }
        }