예제 #1
0
        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;
        }
예제 #2
0
 public EdiStructure(EdiStructureType structureType, EdiStructure parent, EdiPropertyDescriptor property, object instance, int index, Queue <EdiEntry> cache)
 {
     ValidationUtils.ArgumentNotNull(instance, "instance");
     _StructureType      = structureType;
     _Container          = parent;
     _Instance           = instance;
     _Index              = index;
     _Descriptor         = typeStore.Get(instance.GetType());
     _CachedReads        = cache;
     _Conditions         = Descriptor.Attributes.OfType <EdiConditionAttribute>().Concat(property?.Conditions ?? new EdiConditionAttribute[0]).ToArray();
     _ConditionStackMode = _Conditions.Length > 0 && (
         property?.ConditionStackMode == EdiConditionStackMode.Any ||
         Descriptor.Attributes.OfType <EdiAnyAttribute>().Any())
         ? EdiConditionStackMode.Any : EdiConditionStackMode.All;
 }
예제 #3
0
        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;
        }