List <GenClassPivot> FilterClassesPivot(List <GenClassPivot> aInput) { Queue <GenClassPivot> aTemp = new Queue <GenClassPivot>(); List <GenClassPivot> aRes = new List <GenClassPivot>(); string[] aTargetTypes = new string[] { "CT_PivotCacheDefinition", "CT_PivotCacheRecords", "CT_pivotTableDefinition" }; //string[] aTargetTypes = new string[] { "CT_Workbook" }; //string[] aTargetTypes = new string[] { "CT_Comments" }; Dictionary <string, bool> mapTargetSubTypes = new Dictionary <string, bool>(); Dictionary <string, bool> namspaces = new Dictionary <string, bool>(); Dictionary <string, GenClassPivot> mapAllClasses = new Dictionary <string, GenClassPivot>(); for (int i = 0; i < aInput.Count; ++i) { GenClassPivot oGenClass = aInput[i]; if (0 == aTargetTypes.Length || -1 != Array.IndexOf(aTargetTypes, oGenClass.sName)) { aTemp.Enqueue(oGenClass); } mapAllClasses[oGenClass.sName] = oGenClass; } while (aTemp.Count > 0) { GenClassPivot oGenClass = aTemp.Dequeue(); if (!mapTargetSubTypes.ContainsKey(oGenClass.sName)) { mapTargetSubTypes.Add(oGenClass.sName, true); aRes.Add(oGenClass); for (int j = 0; j < oGenClass.aMembers.Count; ++j) { GenMemberPivot oGenMember = oGenClass.aMembers[j]; GenClassPivot oTempClass; if (null != oGenMember.sType && mapAllClasses.TryGetValue(oGenMember.sType, out oTempClass)) { namspaces[oTempClass.sNamespace] = true; aTemp.Enqueue(oTempClass); } if (null != oGenMember.aArrayTypes) { for (int k = 0; k < oGenMember.aArrayTypes.Count; ++k) { GenMemberPivot oGenMemberArrayTypes = oGenMember.aArrayTypes[k]; if (null != oGenMemberArrayTypes.sType && mapAllClasses.TryGetValue(oGenMemberArrayTypes.sType, out oTempClass)) { aTemp.Enqueue(oTempClass); } } } } } } return(aRes); }
List <GenClassPivot> PreProcess(CodeNamespace code, XmlSchema schema) { List <GenClassPivot> aGenClasses = new List <GenClassPivot>(); for (int i = 0; i < code.Types.Count; ++i) { GenClassPivot oNewClass = PreProcessClass(aGenClasses, code.Types[i]); if (null != oNewClass) { aGenClasses.Add(oNewClass); } } return(aGenClasses); }
GenMemberPivot PreProcessProperty(List <GenClassPivot> aGenClasses, CodeMemberProperty codeMemberProperty, GenClassPivot oGenClass, ref int nItemsElementName) { GenMemberPivot oGenMember = new GenMemberPivot(codeMemberProperty.Name); bool bIgnore = false; InitMemberType(oGenMember, codeMemberProperty.Type.BaseType); if (null != codeMemberProperty.Type.ArrayElementType) { oGenMember.nArrayRank = codeMemberProperty.Type.ArrayElementType.ArrayRank; } bool bXmlElementAttribute = false; List <GenMemberPivot> aTempMemebers = new List <GenMemberPivot>(); for (int i = 0; i < codeMemberProperty.CustomAttributes.Count; i++) { CodeAttributeDeclaration attribute = codeMemberProperty.CustomAttributes[i]; if (attribute.Name == "System.Xml.Serialization.XmlAttributeAttribute") { oGenMember.bQualified = false; oGenMember.bIsAttribute = true; ParseArguments(attribute.Arguments, oGenMember); //todo могут быть повторы имен атрибутов и child nodes. } else if (attribute.Name == "System.ComponentModel.DefaultValueAttribute") { if (attribute.Arguments.Count > 0) { CodeExpression oCodeExpression = attribute.Arguments[attribute.Arguments.Count - 1].Value; //todo other if (oCodeExpression is CodePrimitiveExpression) { oGenMember.sDefAttribute = ((oCodeExpression as CodePrimitiveExpression)).Value.ToString(); } else if (oCodeExpression is CodeFieldReferenceExpression) { oGenMember.sDefAttribute = ((oCodeExpression as CodeFieldReferenceExpression)).FieldName; } } } else if (attribute.Name == "System.Xml.Serialization.XmlIgnoreAttribute") { bIgnore = true; } else if (attribute.Name == "System.Xml.Serialization.XmlElementAttribute") { bXmlElementAttribute = true; GenMemberPivot oTemp = new GenMemberPivot(null); ParseArguments(attribute.Arguments, oTemp); aTempMemebers.Add(oTemp); } else if (attribute.Name == "System.Xml.Serialization.XmlArrayItemAttribute") { GenMemberPivot oTemp = new GenMemberPivot(null); ParseArguments(attribute.Arguments, oTemp); aTempMemebers.Add(oTemp); } else if (attribute.Name == "System.Xml.Serialization.XmlArrayAttribute") { ParseArguments(attribute.Arguments, oGenMember); } //todo не всегда прописан //else if (attribute.Name == "System.Xml.Serialization.XmlChoiceIdentifierAttribute") //{ // if (attribute.Arguments.Count > 0) // { // CodePrimitiveExpression oPrimitiveExpression = attribute.Arguments[0].Value as CodePrimitiveExpression; // oGenMember.sChoiceIdentifier = oPrimitiveExpression.Value.ToString(); // } //} } if (bIgnore) { return(null); } else { if (aTempMemebers.Count > 0) { if (1 == aTempMemebers.Count) { GenMemberPivot TempMember = aTempMemebers[0]; TempMember.merge(oGenMember); TempMember.nArrayRank = null; } oGenMember.aArrayTypes = aTempMemebers; if (bXmlElementAttribute) { oGenMember.bIsArrayTypesHidden = true; } else { oGenMember.bIsArrayTypesHidden = false; } } else { oGenMember.nArrayRank = null; } oGenMember.completeDefaults(); return(oGenMember); } }
GenClassPivot PreProcessClass(List <GenClassPivot> aGenClasses, CodeTypeDeclaration type) { GenClassPivot oGenClass = null; //получаем xml namespace string sNamespace = null; bool bIncludeInSchema = true; string sRootName = ""; for (int i = 0; i < type.CustomAttributes.Count; i++) { CodeAttributeDeclaration attribute = type.CustomAttributes[i]; if (attribute.Name == "System.Xml.Serialization.XmlTypeAttribute") { foreach (CodeAttributeArgument argument in attribute.Arguments) { if (argument.Name == "Namespace") { sNamespace = ((CodePrimitiveExpression)argument.Value).Value.ToString(); } else if (argument.Name == "IncludeInSchema") { bIncludeInSchema = Convert.ToBoolean(((CodePrimitiveExpression)argument.Value).Value); } //todo argument.Name == "TypeName" } } else if (attribute.Name == "System.Xml.Serialization.XmlRootAttribute") { foreach (CodeAttributeArgument argument in attribute.Arguments) { if (argument.Name == "Namespace") { sNamespace = ((CodePrimitiveExpression)argument.Value).Value.ToString(); } else if ("" == argument.Name) { sRootName = ((CodePrimitiveExpression)argument.Value).Value.ToString(); } } } } if (bIncludeInSchema) { oGenClass = new GenClassPivot(type.Name, sNamespace); oGenClass.sRootName = sRootName; int nItemsElementName = 0; if (type.IsEnum) { oGenClass.bIsEnum = true; for (int i = 0; i < type.Members.Count; ++i) { CodeTypeMember member = type.Members[i]; GenMemberPivot oGenMember = new GenMemberPivot(member.Name); for (int j = 0; j < member.CustomAttributes.Count; j++) { CodeAttributeDeclaration attribute = member.CustomAttributes[j]; if (attribute.Name == "System.Xml.Serialization.XmlEnumAttribute") { ParseArguments(attribute.Arguments, oGenMember); } } oGenClass.aMembers.Add(oGenMember); } } else { for (int i = 0; i < type.Members.Count; ++i) { CodeTypeMember member = type.Members[i]; //CodeMemberField пропускаем CodeMemberProperty codeMemberProperty = member as CodeMemberProperty; if (codeMemberProperty != null) { GenMemberPivot oNewGenMember = PreProcessProperty(aGenClasses, codeMemberProperty, oGenClass, ref nItemsElementName); if (null != oNewGenMember) { oGenClass.aMembers.Add(oNewGenMember); } } } } } return(oGenClass); }