public DnsResourceDataNamingAuthorityPointer(ushort order, ushort preference, DataSegment flags, DataSegment services, DataSegment regularExpression, DnsDomainName replacement) { if (flags == null) { throw new ArgumentNullException("flags"); } if (!IsLegalFlags(flags)) { throw new ArgumentException( string.Format(CultureInfo.InvariantCulture, "Flags ({0}) contain a non [a-zA-Z0-9] character.", Encoding.ASCII.GetString(flags.Buffer, flags.StartOffset, flags.Length)), "flags"); } Order = order; Preference = preference; Flags = flags.All(flag => flag <'a' || flag> 'z') && flags.IsStrictOrdered() ? flags : new DataSegment(flags.Select(flag => flag >= 'a' && flag <= 'z' ? (byte)(flag + 'A' - 'a') : flag) .Distinct().OrderBy(flag => flag).ToArray()); Services = services; RegularExpression = regularExpression; Replacement = replacement; }
/// <summary> /// 判断所有数据规则段出现的次数 /// </summary> /// yaoy 16.09.20 /// <param name="infoTypeId"></param> /// <param name="messageInfo"></param> /// <returns></returns> public bool TimesValidate(int infoTypeId, MessageInfo messageInfo) { bool result = true; // 根据信息类型ID获取所有数据段 List <DataSegmentInfo> dataSegmentList = new DataSegment().GetByInfoTypeId(infoTypeId); PropertyInfo[] ps = messageInfo.GetType().GetProperties(); foreach (PropertyInfo pi in ps) { List <Dictionary <string, string> > list = (List <Dictionary <string, string> >)pi.GetValue(messageInfo); // list集合不为空且段名称包含在数据段集合中 if (list != null && dataSegmentList.Select(m => m.ParagraphCode).Contains(pi.Name)) { // 异常情况描述 var temp = string.Empty; //根据信息类型ID和段编码获取实体 DataSegmentInfo dataSegmentInfo = new DataSegment().GetByInfoTypeIdAndCode(infoTypeId, pi.Name); switch (dataSegmentInfo.times) { case "1:1": temp = "次数为一"; result &= list.Count() == 1; break; case "1:n": temp = "次数大于等于一"; result &= list.Count() >= 1; break; case "0:1": temp = "次数小于等于一"; result &= list.Count() <= 1; break; default: break; } if (!result) { throw new ApplicationException(dataSegmentInfo.ParagraphName + "必须满足" + temp); } } } return(result); }