예제 #1
0
        public Type ReadFromAttribute(String classIdAttribute, String classNameAttribute, String classNamespaceAttribute, String classMemberAttribute, IReader reader)
        {
            String classIdValue = reader.GetAttributeValue(classIdAttribute);
            int    classId      = 0;

            if (classIdValue != null && classIdValue.Length > 0)
            {
                classId = Int32.Parse(classIdValue);
            }
            Type typeObj = (Type)reader.GetObjectById(classId, false);

            if (typeObj != null)
            {
                return(typeObj);
            }
            String name            = reader.GetAttributeValue(classNameAttribute);
            String namespaceString = reader.GetAttributeValue(classNamespaceAttribute);

            int dimensionCount = 0;

            while (name.EndsWith("[]"))
            {
                dimensionCount++;
                name = name.Substring(0, name.Length - 2);
            }
            typeObj = XmlTypeRegistry.GetType(name, namespaceString);

            String classMemberValue = reader.GetAttributeValue(classMemberAttribute);

            if (classMemberValue != null)
            {
                ITypeInfo       typeInfo    = TypeInfoProvider.GetTypeInfo(typeObj);
                String[]        memberNames = classMemberValue.Split(' ');
                ITypeInfoItem[] members     = new ITypeInfoItem[memberNames.Length];

                for (int a = memberNames.Length; a-- > 0;)
                {
                    String        memberName = memberNames[a];
                    ITypeInfoItem member     = typeInfo.GetMemberByXmlName(memberName);
                    if (member == null)
                    {
                        throw new Exception("No member found with xml name '" + memberName + "' on entity '" + typeObj.FullName + "'");
                    }
                    members[a] = member;
                }
                reader.PutMembersOfType(typeObj, members);
            }
            String gtIdValue           = classIdAttribute.Equals("gti") ? null : reader.GetAttributeValue("gti");
            Type   genericArgumentType = null;

            if (gtIdValue != null && gtIdValue.Length > 0)
            {
                genericArgumentType = ReadFromAttribute("gti", "gn", "gns", "gm", reader);
                typeObj             = typeObj.MakeGenericType(genericArgumentType);
            }
            while (dimensionCount-- > 0)
            {
                typeObj = typeObj.MakeArrayType();
            }
            reader.PutObjectWithId(typeObj, classId);
            return(typeObj);
        }