protected SymbolEntry AddSymbol( XmlQualifiedName qname, XmlSchemaObject schemaObject, string suffix) { SymbolEntry symbol = new SymbolEntry(); symbol.xsdNamespace = qname.Namespace; symbol.clrNamespace = configSettings.GetClrNamespace(qname.Namespace); symbol.symbolName = qname.Name; string 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); schemaNameToIdentifiers.Add(schemaObject, symbol.identifierName); //Type vs typeName return symbol; }
public override bool Equals(object obj) { SymbolEntry se = obj as SymbolEntry; if (se != null) { return((xsdNamespace == se.xsdNamespace) && identifierName.Equals(se.identifierName, StringComparison.OrdinalIgnoreCase)); } return(false); }
internal void ElementsToTypes() { bool isRoot = false; int rootElementsCount = this.schemas.GlobalElements.Count; foreach (XmlSchemaElement elem in this.schemas.GlobalElements.Values) { SymbolEntry symbol = this.symbolTable.AddElement(elem); XmlSchemaType schemaType = elem.ElementSchemaType; string xsdNamespace = elem.QualifiedName.Namespace; ClrTypeInfo typeInfo = null; XmlSchemaElement headElement = null; if (!elem.SubstitutionGroup.IsEmpty) { headElement = (XmlSchemaElement)this.schemas.GlobalElements[elem.SubstitutionGroup]; } if (!schemaType.IsGlobal()) { ClrContentTypeInfo ctypeInfo = new ClrContentTypeInfo(); this.localSymbolTable.Init(symbol.identifierName); ctypeInfo.baseType = headElement; this.BuildProperties(elem, schemaType, ctypeInfo); this.BuildNestedTypes(ctypeInfo); typeInfo = ctypeInfo; } else { ClrWrapperTypeInfo wtypeInfo = new ClrWrapperTypeInfo((headElement == null ? false : headElement.ElementSchemaType == schemaType)); ClrTypeReference typeDef = this.BuildTypeReference(schemaType, schemaType.QualifiedName, false, true); wtypeInfo.InnerType = typeDef; typeInfo = wtypeInfo; typeInfo.baseType = headElement; } if (!isRoot) { if ((rootElementsCount == 1 ? true : this.CheckUnhandledAttributes(elem))) { typeInfo.IsRoot = true; isRoot = true; } } typeInfo.IsSubstitutionHead = this.IsSubstitutionGroupHead(elem) != null; typeInfo.IsAbstract = elem.IsAbstract; typeInfo.clrtypeName = symbol.identifierName; typeInfo.clrtypeNs = symbol.clrNamespace; typeInfo.schemaName = symbol.symbolName; typeInfo.schemaNs = xsdNamespace; typeInfo.typeOrigin = SchemaOrigin.Element; this.BuildAnnotationInformation(typeInfo, schemaType); this.binding.Types.Add(typeInfo); } }
internal void TypesToTypes() { foreach (XmlSchemaType st in schemas.GlobalTypes.Values) { XmlSchemaSimpleType simpleType = st as XmlSchemaSimpleType; if (simpleType != null) { SymbolEntry symbol = symbolTable.AddType(simpleType); string xsdNamespace = simpleType.QualifiedName.Namespace; ClrSimpleTypeInfo typeInfo = ClrSimpleTypeInfo .CreateSimpleTypeInfo(simpleType); //Create corresponding simple type info objects typeInfo.IsAbstract = false; typeInfo.clrtypeName = symbol.identifierName; typeInfo.clrtypeNs = symbol.clrNamespace; typeInfo.schemaName = symbol.symbolName; typeInfo.schemaNs = xsdNamespace; typeInfo.typeOrigin = SchemaOrigin.Fragment; BuildAnnotationInformation(typeInfo, st); binding.Types.Add(typeInfo); } else { XmlSchemaComplexType ct = st as XmlSchemaComplexType; if (ct != null && ct.TypeCode != XmlTypeCode.Item) { SymbolEntry symbol = symbolTable.AddType(ct); string xsdNamespace = ct.QualifiedName.Namespace; localSymbolTable.Init(symbol.identifierName); ClrContentTypeInfo typeInfo = new ClrContentTypeInfo(); typeInfo.IsAbstract = ct.IsAbstract; typeInfo.IsSealed = ct.IsFinal(); typeInfo.clrtypeName = symbol.identifierName; typeInfo.clrtypeNs = symbol.clrNamespace; typeInfo.schemaName = symbol.symbolName; typeInfo.schemaNs = xsdNamespace; typeInfo.typeOrigin = SchemaOrigin.Fragment; typeInfo.baseType = BaseType(ct); BuildProperties(null, ct, typeInfo); BuildNestedTypes(typeInfo); BuildAnnotationInformation(typeInfo, ct); binding.Types.Add(typeInfo); } } } }
public override bool Equals(object obj) { bool flag; SymbolEntry se = obj as SymbolEntry; if (se == null) { flag = false; } else { flag = (this.xsdNamespace != se.xsdNamespace ? false : this.identifierName.Equals(se.identifierName, StringComparison.OrdinalIgnoreCase)); } return(flag); }
internal void AddSimpleType(XmlQualifiedName name, XmlSchemaSimpleType simpleType) { SymbolEntry symbol = this.symbolTable.AddType(name, simpleType); string xsdNamespace = simpleType.QualifiedName.Namespace; ClrSimpleTypeInfo typeInfo = ClrSimpleTypeInfo.CreateSimpleTypeInfo(simpleType); typeInfo.IsAbstract = false; typeInfo.clrtypeName = symbol.identifierName; typeInfo.clrtypeNs = symbol.clrNamespace; typeInfo.schemaName = symbol.symbolName; typeInfo.schemaNs = xsdNamespace; typeInfo.typeOrigin = SchemaOrigin.Fragment; this.BuildAnnotationInformation(typeInfo, simpleType); this.binding.Types.Add(typeInfo); }
internal void ElementsToTypes() { bool isRoot = false; int rootElementsCount = schemas.GlobalElements.Count; foreach (XmlSchemaElement elem in schemas.GlobalElements.Values) { SymbolEntry symbol = symbolTable.AddElement(elem); XmlSchemaType schemaType = elem.ElementSchemaType; string xsdNamespace = elem.QualifiedName.Namespace; ClrTypeInfo typeInfo = null; XmlSchemaElement headElement = null; if (!elem.SubstitutionGroup.IsEmpty) { headElement = (XmlSchemaElement)schemas.GlobalElements[elem.SubstitutionGroup]; } if (schemaType.IsGlobal()) { //Global elem with global type, generate wrapper class for the element bool hasBaseContentType = headElement != null && headElement.ElementSchemaType == schemaType; ClrWrapperTypeInfo wtypeInfo = new ClrWrapperTypeInfo(hasBaseContentType); ClrTypeReference typeDef = BuildTypeReference(schemaType, schemaType.QualifiedName, false, true); //Save the fixed/default value of the element wtypeInfo.InnerType = typeDef; typeInfo = wtypeInfo; typeInfo.baseType = headElement; //If element is member of substitutionGroup, add derivation step } else { ClrContentTypeInfo ctypeInfo = new ClrContentTypeInfo(); localSymbolTable.Init(symbol.identifierName); ctypeInfo.baseType = headElement; //If element is member of substitutionGroup, add derivation step BuildProperties(elem, schemaType, ctypeInfo); BuildNestedTypes(ctypeInfo); typeInfo = ctypeInfo; } if (!isRoot) { if (rootElementsCount == 1 || CheckUnhandledAttributes(elem)) { typeInfo.IsRoot = true; isRoot = true; } } typeInfo.IsSubstitutionHead = IsSubstitutionGroupHead(elem) != null; typeInfo.IsAbstract = elem.IsAbstract; typeInfo.clrtypeName = symbol.identifierName; typeInfo.clrtypeNs = symbol.clrNamespace; typeInfo.schemaName = symbol.symbolName; typeInfo.schemaNs = xsdNamespace; typeInfo.typeOrigin = SchemaOrigin.Element; BuildAnnotationInformation(typeInfo, schemaType); binding.Types.Add(typeInfo); } }