Exemplo n.º 1
0
 public void AddTag(TlvTagConfig tagConfig)
 {
     if (_tagMap.ContainsKey(tagConfig.Name))
     {
         throw new ConfigParserException("Duplicate tag name (name=" + tagConfig.Name
                                         + ") inside tlv element (id=" + this.Id + ")");
     }
     _tagMap[tagConfig.Name] = tagConfig;
     _tags.Add(tagConfig);
 }
Exemplo n.º 2
0
        private void ParseTlvTags(Type tlvType, TlvConfig cfg)
        {
            int fieldCount = 0;

            foreach (var propInfo in tlvType.GetProperties())
            {
                var attr = GetAttribute <TlvTagAttribute>(propInfo);
                if (attr == null)
                {
                    continue;
                }
                fieldCount++;

                TlvTagConfig ccfg = new TlvTagConfig();
                ccfg.Name = propInfo.Name;

                ccfg.Splitter = null;
                if (attr.Type == TlvTagType.Array)
                {
                    ccfg.Splitter = Trim(attr.Splitter);
                    if (ccfg.Splitter == String.Empty)
                    {
                        ccfg.Splitter = ";";
                    }
                }

                if (attr.Type == TlvTagType.BitContent)
                {
                    ccfg.BitContent = ParseBitContent(propInfo.PropertyType, "Check attribute for " + propInfo.Name + " of "
                                                      + tlvType.FullName + " class.");
                }

                cfg.AddTag(ccfg);
            }

            if (fieldCount <= 0)
            {
                throw new ConfigParserException(tlvType.FullName + " class defines TlvAttribute but there is no property which "
                                                + "defines TlvTagAttribute");
            }
        }