public EdiPropertyDescriptor(PropertyInfo info, IEnumerable <EdiAttribute> attributes) { _Info = info; if (attributes == null) { attributes = info.GetCustomAttributes <EdiAttribute>() .Concat(info.PropertyType.GetTypeInfo().GetCustomAttributes <EdiAttribute>()); if (info.PropertyType.IsCollectionType()) { var itemType = default(Type); if (info.PropertyType.HasElementType) { itemType = info.PropertyType.GetElementType(); } else { itemType = Info.PropertyType.GetGenericArguments().First(); } attributes = attributes.Concat(itemType.GetTypeInfo().GetCustomAttributes <EdiAttribute>()); } } _Attributes = attributes.ToList(); _PathInfo = Attributes.OfType <EdiPathAttribute>().FirstOrDefault(); _ConditionInfo = Attributes.OfType <EdiConditionAttribute>().FirstOrDefault(); _ValueInfo = Attributes.OfType <EdiValueAttribute>().FirstOrDefault(); if (_ValueInfo != null && _ValueInfo.Path != null && _PathInfo == null) { _PathInfo = new EdiPathAttribute(_ValueInfo.Path); } }
public EdiPropertyDescriptor(PropertyInfo info, IEnumerable<EdiAttribute> attributes) { _Info = info; if (attributes == null) { attributes = info.GetCustomAttributes<EdiAttribute>() .Concat(info.PropertyType.GetTypeInfo().GetCustomAttributes<EdiAttribute>()); if (info.PropertyType.IsCollectionType()) { var itemType = default(Type); if (info.PropertyType.HasElementType) { itemType = info.PropertyType.GetElementType(); } else { itemType = Info.PropertyType.GetGenericArguments().First(); } attributes = attributes.Concat(itemType.GetTypeInfo().GetCustomAttributes<EdiAttribute>()); } } _Attributes = attributes.ToList(); _PathInfo = Attributes.OfType<EdiPathAttribute>().FirstOrDefault(); _ConditionInfo = Attributes.OfType<EdiConditionAttribute>().FirstOrDefault(); _ValueInfo = Attributes.OfType<EdiValueAttribute>().FirstOrDefault(); _SegmentGroupInfo = Attributes.OfType<EdiSegmentGroupAttribute>().FirstOrDefault(); if (_ValueInfo != null && _ValueInfo.Path != null && _PathInfo == null) { _PathInfo = new EdiPathAttribute(_ValueInfo.Path); } if (_SegmentGroupInfo != null && _SegmentGroupInfo.StartInternal.Segment != null && _PathInfo == null) { _PathInfo = new EdiPathAttribute(_SegmentGroupInfo.StartInternal.Segment); } }
public EdiPropertyDescriptor(PropertyInfo info, IEnumerable <EdiAttribute> attributes) { _Info = info; if (attributes == null) { attributes = info.GetCustomAttributes <EdiAttribute>() .Concat(info.PropertyType.GetTypeInfo().GetCustomAttributes <EdiAttribute>()); if (info.PropertyType.IsCollectionType()) { var itemType = default(Type); if (info.PropertyType.HasElementType) { itemType = info.PropertyType.GetElementType(); } else { itemType = Info.PropertyType.GetGenericArguments().First(); } attributes = attributes.Concat(itemType.GetTypeInfo().GetCustomAttributes <EdiAttribute>()); } } _Attributes = attributes.ToList(); var structureType = Attributes.InferStructure(); var pathInfo = Attributes.OfType <EdiPathAttribute>().FirstOrDefault(); var conditions = Attributes.OfType <EdiConditionAttribute>().ToArray(); _Conditions = conditions.Length > 0 ? conditions : null; _ValueInfo = Attributes.OfType <EdiValueAttribute>().FirstOrDefault(); _SegmentGroupInfo = Attributes.OfType <EdiSegmentGroupAttribute>().FirstOrDefault(); _AutoGenerationInfo = Attributes.OfType <EdiGeneratedAttribute>().FirstOrDefault(); if (_ValueInfo != null && _ValueInfo.Path != null && pathInfo == null) { pathInfo = new EdiPathAttribute(_ValueInfo.Path); } if (_SegmentGroupInfo != null && _SegmentGroupInfo.StartInternal.Segment != null && pathInfo == null) { pathInfo = new EdiPathAttribute(_SegmentGroupInfo.StartInternal.Segment); } if (pathInfo != null && structureType == EdiStructureType.None && pathInfo.PathInternal.Segment.IsWildcard) { var parentPathInfo = info.DeclaringType.GetTypeInfo().GetCustomAttributes <EdiPathAttribute>().FirstOrDefault(); if (parentPathInfo != null) { pathInfo = new EdiPathAttribute(new EdiPath(new EdiPathFragment(parentPathInfo.Segment), pathInfo.PathInternal.Element, pathInfo.PathInternal.Component)); } } if (pathInfo == null && structureType == EdiStructureType.Element) { pathInfo = info.DeclaringType.GetTypeInfo().GetCustomAttributes <EdiPathAttribute>().FirstOrDefault(); if (pathInfo != null) { pathInfo = new EdiPathAttribute(new EdiPath(new EdiPathFragment(pathInfo.Segment), new EdiPathFragment("*"), new EdiPathFragment(""))); } } _PathInfo = pathInfo; _ConditionStackMode = conditions.Length > 0 && Attributes.OfType <EdiAnyAttribute>().Any() ? EdiConditionStackMode.Any : EdiConditionStackMode.All; }
public EdiPropertyDescriptor(PropertyInfo info, IEnumerable <EdiAttribute> attributes) { _Info = info; if (attributes == null) { attributes = info.GetCustomAttributes <EdiAttribute>() .Concat(info.PropertyType.GetTypeInfo().GetCustomAttributes <EdiAttribute>()); if (info.PropertyType.IsCollectionType()) { var itemType = default(Type); if (info.PropertyType.HasElementType) { itemType = info.PropertyType.GetElementType(); } else { itemType = Info.PropertyType.GetGenericArguments().First(); } attributes = attributes.Concat(itemType.GetTypeInfo().GetCustomAttributes <EdiAttribute>()); } } _Attributes = attributes.ToList(); _PathInfo = Attributes.OfType <EdiPathAttribute>().FirstOrDefault(); var conditions = Attributes.OfType <EdiConditionAttribute>().ToArray(); _Conditions = conditions.Length > 0 ? conditions : null; _ValueInfo = Attributes.OfType <EdiValueAttribute>().FirstOrDefault(); _SegmentGroupInfo = Attributes.OfType <EdiSegmentGroupAttribute>().FirstOrDefault(); if (_ValueInfo != null && _ValueInfo.Path != null && _PathInfo == null) { _PathInfo = new EdiPathAttribute(_ValueInfo.Path); } if (_SegmentGroupInfo != null && _SegmentGroupInfo.StartInternal.Segment != null && _PathInfo == null) { _PathInfo = new EdiPathAttribute(_SegmentGroupInfo.StartInternal.Segment); } _ConditionStackMode = conditions.Length > 0 && Attributes.OfType <EdiAnyAttribute>().Any() ? EdiConditionStackMode.Any : EdiConditionStackMode.All; }