コード例 #1
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;
        }
コード例 #2
0
 /// <summary>
 /// Removes all properties.
 /// </summary>
 public virtual void RemoveAllProperties()
 {
     foreach (var property in ClrType.GetProperties(BindingFlags.Public | BindingFlags.Instance))
     {
         RemoveProperty(property);
     }
 }
コード例 #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();
        }
コード例 #4
0
        private void AddKeys()
        {
            if (_keyProperties.Count == 0)
            {
                PropertyInfo?key = ClrType.GetPropertyIgnoreCaseOrNull("id");
                if (key != null)
                {
                    var edmProperty = (EdmStructuralProperty)EdmType.GetPropertyIgnoreCase(key.Name);
                    _keyProperties.Add(new KeyValuePair <PropertyInfo, EdmStructuralProperty>(key, edmProperty));
                }
                else
                {
                    key = ClrType.GetPropertyIgnoreCaseOrNull(ClrType.Name + "id");
                    if (key == null)
                    {
                        key = ClrType.GetProperties().Where(prop => prop.Name == "UserId").First();
                    }
                    if (key == null)
                    {
                        //Special Handling IdentityUser

                        if (EdmType.Key().Any() || ClrType.IsAbstract)
                        {
                            return;
                        }

                        throw new InvalidOperationException("Key property not matching");
                    }

                    var edmProperty = (EdmStructuralProperty)EdmType.GetPropertyIgnoreCase(key.Name);
                    _keyProperties.Add(new KeyValuePair <PropertyInfo, EdmStructuralProperty>(key, edmProperty));
                }
            }

            if (_keyProperties.Count == 1)
            {
                EdmType.AddKeys(_keyProperties[0].Value);
                return;
            }

            var keys = new ValueTuple <EdmStructuralProperty, int> [_keyProperties.Count];

            for (int i = 0; i < _keyProperties.Count; i++)
            {
                int order = _metadataProvider.GetOrder(_keyProperties[i].Key);
                if (order == -1)
                {
                    EdmType.AddKeys(_keyProperties.Select(p => p.Value));
                    return;
                }

                keys[i] = new ValueTuple <EdmStructuralProperty, int>(_keyProperties[i].Value, order);
            }
            EdmType.AddKeys(keys.OrderBy(p => p.Item2).Select(p => p.Item1));
        }
コード例 #5
0
ファイル: EntityType.cs プロジェクト: xlgwr/Blazor.FlexGrid
        private IReadOnlyCollection <PropertyInfo> GetClrTypeCollectionProperties()
        {
            var collectionProperties = new List <PropertyInfo>();

            foreach (var property in ClrType.GetProperties())
            {
                if (property.PropertyType != typeof(string) &&
                    property.PropertyType.GetInterface(nameof(System.Collections.IEnumerable)) != null)
                {
                    collectionProperties.Add(property);
                }
            }

            return(collectionProperties);
        }
コード例 #6
0
 // Get a list of all properites in this type.
 public override PropertyInfo[] GetProperties(BindingFlags bindingAttr)
 {
     CheckCreated();
     return(type.GetProperties(bindingAttr));
 }
コード例 #7
0
    private void PrintProperties()
    {
        var propertyList = ClrType.GetProperties().Select(z => $"  {z.PropertyType.Name,14} {z.Name}");

        _stringBuilder.AppendLine($" Properties are:\r\n{string.Join(Environment.NewLine, propertyList)}\r\n");
    }