private void PrintClassHeaders(List <CSElement> arrElements, ref string headerFileContent) { string curType = ""; int count = arrElements.Count; for (int i = 0; i < count; i++) { CSElement el = arrElements[i]; if (string.IsNullOrEmpty(el.parentName)) { continue; } // change of parent type if (el.parentName != curType) { headerFileContent += "\r\n"; headerFileContent += string.Format("/// <summary> C{0}XmlSerializable </summary>\r\n", GetPascalCaseName(el.parentName)); headerFileContent += string.Format("class DLL_EXP C{0}XmlSerializable : public CXMLSerializable \r\n", GetPascalCaseName(el.parentName)); headerFileContent += "{\r\n"; headerFileContent += "\t\r\n"; headerFileContent += "public:\r\n"; headerFileContent += "\t/// <summary>Стандартен конструктор</summary>\r\n"; headerFileContent += string.Format("\tC{0}XmlSerializable();", GetPascalCaseName(el.parentName)); headerFileContent += "\r\n"; headerFileContent += "\r\n"; if (i == count - 2) { headerFileContent += string.Format( "\t// CXMLSerializable имплементация\r\n" + "\tLPCTSTR GetTypeName() const {{ return \"{0}\"; }}; \r\n\r\n" + "\tconst long GetSize() const {{ return sizeof( m_rec{1} ); }}\r\n\r\n" + "\tvirtual void * GetPoiner() {{ return (void*)&m_rec{1}; }}\r\n\r\n" + "\tvoid FillTypeInfo();\r\n", el.parentName, GetPascalCaseName(el.parentName)); headerFileContent += string.Format("\r\n\t{0} m_rec{1};\r\n\r\n", el.parentName.ToUpper(), GetPascalCaseName(el.parentName)); } else { headerFileContent += string.Format( "\t// CXMLSerializable имплементация\r\n" + "\tLPCTSTR GetTypeName() const {{ return \"{0}\"; }}; \r\n\r\n" + "\tconst long GetSize() const {{ return sizeof( *this ); }}\r\n\r\n" + "\tvirtual void * GetPoiner() {{ return (void*)this; }}\r\n\r\n" + "\tvoid FillTypeInfo();\r\n", el.parentName); } headerFileContent += "};\r\n"; } // if el.parentName != curType // change of parent type curType = el.parentName; } // for }
private static int CompareCSElements(CSElement el1, CSElement el2) { if (el1.depth == el2.depth && el1.parentName == el2.parentName) { return(0); } if (el1.depth > el2.depth) { return(-1); } if (el2.depth > el1.depth) { return(1); } if (el1.depth == el2.depth) { return(string.Compare(el1.parentName, el2.parentName)); }// if return(0); }
private void LoadCSElementsArrayFromXsdRecrusive(XmlSchemaElement element, XmlSchemaElement parentElement, ref List <CSElement> arrElements, int depth) { if (element == null) { return; } string strType = "", strParentName = ""; if (parentElement != null) { strParentName = parentElement.Name; } try { strType = element.ElementSchemaType.Datatype.ToString(); strType = strType.Substring(strType.LastIndexOf('_') + 1); } catch (Exception ex) { } CSElement csEl = new CSElement(); csEl.name = element.Name; csEl.parentName = strParentName; csEl.type = strType; csEl.depth = depth; arrElements.Add(csEl); // Get the complex type of the element. XmlSchemaComplexType complexType = element.ElementSchemaType as XmlSchemaComplexType; if (complexType == null) { return; } //// If the complex type has any attributes, get an enumerator //// and write each attribute name to the console. //if( complexType.AttributeUses.Count > 0 ) //{ // IDictionaryEnumerator enumerator = // complexType.AttributeUses.GetEnumerator(); // while( enumerator.MoveNext() ) // { // XmlSchemaAttribute attribute = // (XmlSchemaAttribute)enumerator.Value; // strBuf = string.Format( "{1}Attribute: {0}\r\n", attribute.Name, GetMultipliedString( " ", ( depth + 1 ) * spacePadCount ) ); // strOutput += strBuf; // }// while //}// if // Get the sequence particle of the complex type. XmlSchemaSequence sequence = complexType.ContentTypeParticle as XmlSchemaSequence; if (sequence == null) { return; } foreach (XmlSchemaObject oElement in sequence.Items) { if (oElement.GetType() == typeof(XmlSchemaElement)) { XmlSchemaElement childElement = (XmlSchemaElement)oElement; LoadCSElementsArrayFromXsdRecrusive(childElement, element, ref arrElements, depth + 1); }// if if (oElement.GetType() == typeof(XmlSchemaChoice)) { foreach (XmlSchemaElement childElement in ((XmlSchemaChoice)oElement).Items) { LoadCSElementsArrayFromXsdRecrusive(childElement, element, ref arrElements, depth + 1); } }// if } }