示例#1
0
        public Segment(PropertyInfo propertyInfo, SegmentAttribute sAttr, object instance = null)
            : this(propertyInfo.GetGenericType(), propertyInfo.Name, sAttr.Id, instance)
        {
            if (sAttr.First != null)
            {
                var eAttr = (EdiCodesAttribute)sAttr.First.GetTypeInfo().GetCustomAttributes(typeof(EdiCodesAttribute)).SingleOrDefault();
                if (eAttr == null)
                {
                    throw new Exception(string.Format("Type {0} is not annotated with {1}.",
                                                      sAttr.First.Name, typeof(EdiCodesAttribute).Name));
                }
                _firstMatchValues = eAttr.Codes.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries).ToList();

                if (sAttr.Second != null)
                {
                    var eAttrS = (EdiCodesAttribute)sAttr.Second.GetTypeInfo().GetCustomAttributes(typeof(EdiCodesAttribute)).SingleOrDefault();
                    if (eAttrS == null)
                    {
                        throw new Exception(string.Format("Type {0} is not annotated with {1}.",
                                                          sAttr.Second.Name, typeof(EdiCodesAttribute).Name));
                    }
                    _secondMatchValues = eAttrS.Codes.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries).ToList();
                }
            }
        }
示例#2
0
        public static string AttrsToString(SegmentAttribute attrs)
        {
            StringBuilder sb = new StringBuilder();

            for (int i = 0; i < 16; i++)
            {
                int bit = 1 << i;
                if (((int)attrs & bit) != 0)
                {
                    SegmentAttribute attr = (SegmentAttribute)bit;
                    sb.Append(' ');
                    sb.Append(attr.ToString());
                }
            }
            return(sb.ToString());
        }