Beispiel #1
0
        /// <summary>
        /// Adds a primitive property to this edm type.
        /// </summary>
        /// <param name="propertyInfo">The property being added.</param>
        /// <returns>The <see cref="PrimitivePropertyConfiguration"/> so that the property can be configured further.</returns>
        public virtual PrimitivePropertyConfiguration AddPrimitiveProperty(PropertyInfo propertyInfo)
        {
            if (propertyInfo == null)
            {
                throw Error.ArgumentNull("propertyInfo");
            }

            if (!propertyInfo.DeclaringType.GetTypeInfo().IsAssignableFrom(ClrType.GetTypeInfo()))
            {
                throw Error.Argument("propertyInfo", SRResources.PropertyDoesNotBelongToType, propertyInfo.Name, ClrType.FullName);
            }

            ValidatePropertyNotAlreadyDefinedInBaseTypes(propertyInfo);
            ValidatePropertyNotAlreadyDefinedInDerivedTypes(propertyInfo);

            PrimitivePropertyConfiguration propertyConfiguration;

            if (!propertyInfo.IsIgnored(this))
            {
                propertyConfiguration = ExplicitProperties[propertyInfo] as PrimitivePropertyConfiguration;
                if (propertyConfiguration == null)
                {
                    throw Error.Argument("propertyInfo", SRResources.MustBePrimitiveProperty, propertyInfo.Name, ClrType.FullName);
                }
            }
            else
            {
                propertyConfiguration            = new PrimitivePropertyConfiguration(propertyInfo, this);
                ExplicitProperties[propertyInfo] = propertyConfiguration;
            }

            return(propertyConfiguration);
        }
Beispiel #2
0
        public EdiTypeDescriptor(Type clrType)
        {
            _ClrType    = clrType;
            _Properties = new List <EdiPropertyDescriptor>();
            // list inherited properties first; so SegmentGroups can inherit from there first Segment
            var clrProps = ClrType.GetProperties(BindingFlags.Public | BindingFlags.Instance).OrderBy(p => p.DeclaringType == clrType);
            var props    = clrProps.Select(pi => new EdiPropertyDescriptor(pi)).Where(pi => pi.Attributes.Any());

            // support for multiple value attributes on the same property. Bit hacky.
            foreach (var p in props)
            {
                var valueAttributes = p.Attributes.OfType <EdiValueAttribute>().ToArray();
                if (valueAttributes.Length > 1)
                {
                    foreach (var vAttr in valueAttributes)
                    {
                        _Properties.Add(new EdiPropertyDescriptor(p.Info, p.Attributes.Except(new[] { vAttr })));
                    }
                }
                else
                {
                    _Properties.Add(p);
                }
            }

            _Attributes = new List <EdiAttribute>();
            Attributes.AddRange(ClrType.GetTypeInfo().GetCustomAttributes <EdiAttribute>());
            _SegmentGroupInfo = Attributes.OfType <EdiSegmentGroupAttribute>().SingleOrDefault();
            _Path             = Attributes.OfType <EdiPathAttribute>().FirstOrDefault()?.PathInternal ?? _SegmentGroupInfo?.StartInternal;
        }
Beispiel #3
0
        /// <summary>
        /// Initializes a new instance of the <see cref="T:indice.Edi.Serialization.EdiTypeDescriptor"/> class.
        /// </summary>
        /// <param name="clrType">Clr type.</param>
        public EdiTypeDescriptor(Type clrType)
        {
            _ClrType    = clrType;
            _Properties = new List <EdiPropertyDescriptor>();
            var props = ClrType.GetProperties(BindingFlags.Public | BindingFlags.Instance).Select(pi => new EdiPropertyDescriptor(pi)).Where(pi => pi.Attributes.Any());

            // support for multiple value attributes on the same property. Bit hacky.
            foreach (var p in props)
            {
                var valueAttributes = p.Attributes.OfType <EdiValueAttribute>().ToArray();
                if (valueAttributes.Length > 1)
                {
                    foreach (var vAttr in valueAttributes)
                    {
                        _Properties.Add(new EdiPropertyDescriptor(p.Info, p.Attributes.Except(new[] { vAttr })));
                    }
                }
                else
                {
                    _Properties.Add(p);
                }
            }

            _Attributes = new List <EdiAttribute>();
            Attributes.AddRange(ClrType.GetTypeInfo().GetCustomAttributes <EdiAttribute>());
            _SegmentGroupInfo = Attributes.OfType <EdiSegmentGroupAttribute>().SingleOrDefault();
        }
        /// <summary>
        /// Set the metadata automatic.
        /// </summary>
        protected virtual void SetMetadata()
        {
            var display = GetAttribute <DisplayAttribute>();

            if (display != null)
            {
                SetDisplay(display);
            }
            else
            {
                Name = ClrName;
            }

            var hide = GetAttribute <HideAttribute>();

            if (hide != null)
            {
                SetHide(hide);
            }

            var authentication = GetAttribute <PropertyAuthenticationAttribute>();

            if (authentication != null)
            {
                SetAuthentication(authentication);
            }
            else
            {
                ViewRoles      = new string[0];
                AddRoles       = new string[0];
                EditRoles      = new string[0];
                AllowAnonymous = true;
            }

            var dataType = GetAttribute <CustomDataTypeAttribute>();

            if (dataType != null)
            {
                SetDataType(dataType);
            }

            IsKey      = GetAttribute <KeyAttribute>() != null;
            IsRequired = GetAttribute <RequiredAttribute>() != null || (ClrType.GetTypeInfo().IsValueType&& !ClrType.GetTypeInfo().IsGenericType);
            Searchable = GetAttribute <SearchableAttribute>() != null;
            IsDistinct = GetAttribute <DistinctAttribute>() != null;
            //IsExpended = GetAttribute<ExpendEntityAttribute>() != null || ClrType.GetCustomAttribute<ExpendEntityAttribute>() != null;
        }
Beispiel #5
0
        public virtual Property AddProperty([NotNull] PropertyInfo propertyInfo)
        {
            Check.NotNull(propertyInfo, nameof(propertyInfo));

            if (HasClrType)
            {
                if (!propertyInfo.DeclaringType.GetTypeInfo().IsAssignableFrom(ClrType.GetTypeInfo()))
                {
                    throw new ArgumentException(Strings.PropertyWrongEntityClrType(propertyInfo.Name, Name, propertyInfo.DeclaringType.Name));
                }
            }
            else
            {
                throw new InvalidOperationException(Strings.ClrPropertyOnShadowEntity(propertyInfo.Name, Name));
            }

            var property = AddProperty(propertyInfo.Name, propertyInfo.PropertyType);

            property.IsShadowProperty = false;
            return(property);
        }