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; }
/// <summary> /// Removes all properties. /// </summary> public virtual void RemoveAllProperties() { foreach (var property in ClrType.GetProperties(BindingFlags.Public | BindingFlags.Instance)) { RemoveProperty(property); } }
/// <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(); }
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)); }
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); }
// Get a list of all properites in this type. public override PropertyInfo[] GetProperties(BindingFlags bindingAttr) { CheckCreated(); return(type.GetProperties(bindingAttr)); }
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"); }