private void CreateXRoots() { // For the global XRoot structure, we union the lists of types List <CodeTypeDeclaration> allTypes = new List <CodeTypeDeclaration>(); List <CodeNamespace> allNamespaces = new List <CodeNamespace>(); string rootClrNamespace = settings.GetClrNamespace(rootElementName.Namespace); CodeNamespace rootCodeNamespace = null; if (!codeNamespacesTable.TryGetValue(rootClrNamespace, out rootCodeNamespace)) //This might happen if the schema set has no global elements and only global types { rootCodeNamespace = codeNamespacesTable.Values.FirstOrDefault(); //then you can create a root tag with xsi:type // rootCodeNamespace may still be null if schema has only simple typed global elements or simple types which we are ignoring for now } //Build list of types that will need to be included //in XRoot foreach (CodeNamespace codeNamespace in xroots.Keys) { if (rootCodeNamespace == null) { rootCodeNamespace = codeNamespace; } for (int i = 0; i < xroots[codeNamespace].Count; i++) { allTypes.Add(xroots[codeNamespace][i]); allNamespaces.Add(codeNamespace); } CreateXRoot(codeNamespace, "XRootNamespace", xroots[codeNamespace], null); } CreateXRoot(rootCodeNamespace, "XRoot", allTypes, allNamespaces); }
protected SymbolEntry AddSymbol( XmlQualifiedName qname, XmlSchemaObject schemaObject, string suffix) { var symbol = new SymbolEntry(); symbol.xsdNamespace = qname.Namespace; symbol.clrNamespace = configSettings.GetClrNamespace(qname.Namespace); symbol.symbolName = qname.Name; var identifierName = NameGenerator.MakeValidIdentifier( symbol.symbolName, this.configSettings.NameMangler2); symbol.identifierName = identifierName; int id = 0; if (symbols.ContainsKey(symbol)) { identifierName = identifierName + suffix; symbol.identifierName = identifierName; while (symbols.ContainsKey(symbol)) { id++; symbol.identifierName = identifierName + id.ToString(CultureInfo.InvariantCulture.NumberFormat); } } if (symbol.isNameFixed()) { nFixedNames++; } symbols.Add(symbol, symbol); // Type vs typeName schemaNameToIdentifiers.Add(schemaObject, symbol.identifierName); return(symbol); }
internal void UpdateClrTypeName(Dictionary <XmlSchemaObject, string> nameMappings, LinqToXsdSettings settings) { string identifier = null; string typeName = this.innerType.QualifiedName.Name; string clrNameSpace = settings.GetClrNamespace(this.innerType.QualifiedName.Namespace); if (!nameMappings.TryGetValue(this.innerType, out identifier)) { this.clrtypeName = typeName; } else { this.clrtypeName = identifier; } if (clrNameSpace != string.Empty) { this.clrtypeName = string.Concat(clrNameSpace, ".", this.clrtypeName); } }
private void BuildNestedTypes(ClrContentTypeInfo typeInfo) { List <AnonymousType> anonymousTypes = localSymbolTable.GetAnonymousTypes(); foreach (AnonymousType at in anonymousTypes) { XmlQualifiedName qname = null; XmlSchemaComplexType complexType = null; XmlSchemaElement elem = at.parentElement; if (elem == null) { //case 1: "dummy" type for text content in a complex type, with restrictions complexType = at.wrappingType; qname = complexType.QualifiedName; } else { //case 2: anonymous type can also be nested under an element qname = elem.QualifiedName; complexType = elem.ElementSchemaType as XmlSchemaComplexType; } if (complexType != null) { if (complexType.GetContentType() == XmlSchemaContentType.TextOnly && complexType.IsDerivedByRestriction()) { //In this case, we take care of the content/text part only. No nesting types exist. ClrSimpleTypeInfo nestedTypeInfo = ClrSimpleTypeInfo .CreateSimpleTypeInfo( complexType); //Generate its "simple type" version to save restrictions nestedTypeInfo.clrtypeName = at.identifier; nestedTypeInfo.clrtypeNs = configSettings.GetClrNamespace(qname.Namespace); nestedTypeInfo.schemaName = qname.Name; nestedTypeInfo.schemaNs = qname.Namespace; nestedTypeInfo.typeOrigin = SchemaOrigin.Fragment; nestedTypeInfo.IsNested = true; BuildAnnotationInformation(nestedTypeInfo, complexType); typeInfo.NestedTypes.Add(nestedTypeInfo); } else { ClrContentTypeInfo nestedTypeInfo = new ClrContentTypeInfo() { Parent = typeInfo }; localSymbolTable.Init(at.identifier); nestedTypeInfo.clrtypeName = at.identifier; nestedTypeInfo.clrtypeNs = configSettings.GetClrNamespace(qname.Namespace); nestedTypeInfo.schemaName = qname.Name; nestedTypeInfo.schemaNs = qname.Namespace; nestedTypeInfo.typeOrigin = SchemaOrigin.Fragment; nestedTypeInfo.IsNested = true; nestedTypeInfo.baseType = BaseType(complexType); BuildProperties(elem, complexType, nestedTypeInfo); BuildNestedTypes(nestedTypeInfo); BuildAnnotationInformation(nestedTypeInfo, complexType); typeInfo.NestedTypes.Add(nestedTypeInfo); } } //Also handle simple types XmlSchemaSimpleType simpleType = null; if (elem != null) { simpleType = elem.ElementSchemaType as XmlSchemaSimpleType; } if (simpleType != null) { ClrSimpleTypeInfo nestedTypeInfo = ClrSimpleTypeInfo.CreateSimpleTypeInfo(simpleType); nestedTypeInfo.clrtypeName = at.identifier; nestedTypeInfo.clrtypeNs = configSettings.GetClrNamespace(qname.Namespace); nestedTypeInfo.schemaName = qname.Name; nestedTypeInfo.schemaNs = qname.Namespace; nestedTypeInfo.typeOrigin = SchemaOrigin.Fragment; nestedTypeInfo.IsNested = true; BuildAnnotationInformation(nestedTypeInfo, simpleType); typeInfo.NestedTypes.Add(nestedTypeInfo); } } }
internal void UpdateClrTypeName(Dictionary<XmlSchemaObject, string> nameMappings, LinqToXsdSettings settings) { string identifier = null; string typeName = innerType.QualifiedName.Name; string clrNameSpace = settings.GetClrNamespace(innerType.QualifiedName.Namespace); if (nameMappings.TryGetValue(innerType, out identifier)) { clrtypeName = identifier; } else { clrtypeName = typeName; } if (clrNameSpace != string.Empty) { clrtypeName = clrNameSpace + "." + clrtypeName; } }