示例#1
0
 public override bool Process(Type type, IMethodRemover methodRemover, IFacetHolder holder) {
     Attribute attribute = type.GetCustomAttributeByReflection<RegularExpressionAttribute>();
     if (attribute == null) {
         attribute = type.GetCustomAttributeByReflection<RegExAttribute>();
     }
     return FacetUtils.AddFacet(Create(attribute, holder));
 }
        /// <summary>
        ///     Returns a <see cref="IValueFacet" /> implementation.
        /// </summary>
        private static IValueFacet Create(Type type, IFacetHolder holder) {
            // create from annotation, if present
            var annotation = type.GetCustomAttributeByReflection<ValueAttribute>();
            if (annotation != null) {
                if (annotation.SemanticsProviderClass != null || annotation.SemanticsProviderName.Length != 0) {
                    Type annotationType = annotation.SemanticsProviderClass;
                    if (annotationType == null && !string.IsNullOrEmpty(annotation.SemanticsProviderName)) {
                        annotationType = TypeUtils.GetType(annotation.SemanticsProviderName);
                    }
                    PropertyInfo method = annotationType.GetProperty("Parser");
                    Type propertyType = method.PropertyType.GetGenericArguments()[0];
                    if (!propertyType.IsAssignableFrom(type)) {
                        throw new ModelException(string.Format(Resources.NakedObjects.SemanticProviderMismatch, type, propertyType, holder.Identifier.ClassName));
                    }
                }

                var facet = TypeUtils.CreateGenericInstance<IValueFacet>(typeof (ValueFacetAnnotation<>),
                                                                         new[] {type},
                                                                         new object[] {type, holder});
                if (facet.IsValid) {
                    return facet;
                }
            }


            return null;
        }
        public override bool Process(Type type, IMethodRemover methodRemover, IFacetHolder facetHolder) {
            MethodInfo method = FindMethod(type, MethodType.Object, PrefixesAndRecognisedMethods.IconNameMethod, typeof (string), Type.EmptyTypes);
            var attribute = type.GetCustomAttributeByReflection<IconNameAttribute>();
            if (method != null) {
                RemoveMethod(methodRemover, method);
                return FacetUtils.AddFacet(new IconFacetViaMethod(method, facetHolder, attribute == null ? null : attribute.Value));
            }

            return FacetUtils.AddFacet(Create(attribute, facetHolder));
        }
        /// <summary>
        ///     Returns a <see cref="IEncodeableFacet" /> implementation.
        /// </summary>
        private static IEncodeableFacet Create(Type type, IFacetHolder holder) {
            // create from annotation, if present
            var annotation = type.GetCustomAttributeByReflection<EncodeableAttribute>();
            if (annotation != null) {
                var facet = TypeUtils.CreateGenericInstance<IEncodeableFacet>(typeof (EncodeableFacetAnnotation<>),
                                                                              new[] {type},
                                                                              new object[] {type, holder});


                if (facet.IsValid) {
                    return facet;
                }
            }
            return null;
        }
 public override bool Process(Type type, IMethodRemover methodRemover, IFacetHolder holder) {
     var attribute = type.GetCustomAttributeByReflection<FieldOrderAttribute>();
     return FacetUtils.AddFacet(Create(attribute, holder));
 }
 public override bool Process(Type type, IMethodRemover methodRemover, IFacetHolder holder) {
     Attribute attribute = type.GetCustomAttributeByReflection<DisplayNameAttribute>() ?? (Attribute) type.GetCustomAttributeByReflection<NamedAttribute>();
     return FacetUtils.AddFacet(Create(attribute, holder));
 }
 public override bool Process(Type type, IMethodRemover methodRemover, IFacetHolder holder) {
     Attribute ctAttribute = type.GetCustomAttributeByReflection<ComplexTypeAttribute>();
     return FacetUtils.AddFacet(Create(ctAttribute, holder));
 }