示例#1
0
        public void ReadXml(XmlReader reader)
        {
            // read aliases
            reader.ReadToFollowing("Aliases");
            reader.MoveToContent();
            reader.Read(); // skip Aliases tag
            _aliases = (List <TypeAlias>)ReadObject(reader, typeof(List <TypeAlias>));

            // read items
            reader.ReadToFollowing("Items");
            reader.MoveToFirstAttribute();
            int count = int.Parse(reader.Value);

            if (count > 0)
            {
                reader.MoveToContent();
                reader.Read(); // skip Items tag
                for (int i = 0; i < count; i++)
                {
                    TypeAlias typeAlias = GetAliasByName(reader.LocalName);
                    Guard.NotNull(typeAlias, "TypeAlias:{0} not found", reader.LocalName);

                    Add((T)ReadObject(reader, typeAlias.Type, typeAlias.Alias));
                }
            }

            reader.ReadToFollowing("End");
            reader.Read();
            reader.ReadEndElement();
        }
示例#2
0
        private string GetAliasByType(Type type)
        {
            TypeAlias alias      = new TypeAlias(type.Name, type);
            TypeAlias existAlias = GetAliasByName(alias.Alias);

            if (existAlias != null)
            {
                if (existAlias.TypeDesc != alias.TypeDesc)
                {
                    int i = 0;
                    while (GetAliasByName(alias.Alias + i) != null)
                    {
                        i++;
                    }

                    alias.Alias = alias.Alias + 1;
                    _aliases.Add(alias);
                }
            }
            else
            {
                _aliases.Add(alias);
            }

            return(alias.Alias);
        }