internal void CreateTypeDeclaration(ClrTypeInfo clrTypeInfo) { this.clrTypeInfo = clrTypeInfo; this.SetElementWildCardFlag(clrTypeInfo.HasElementWildCard); string schemaName = clrTypeInfo.schemaName; string schemaNs = clrTypeInfo.schemaNs; string clrTypeName = clrTypeInfo.clrtypeName; SchemaOrigin typeOrigin = clrTypeInfo.typeOrigin; CodeTypeDeclaration typeDecl = CodeDomHelper.CreateTypeDeclaration(clrTypeName, this.InnerType); if (clrTypeInfo.IsAbstract) { CodeTypeDeclaration typeAttributes = typeDecl; typeAttributes.TypeAttributes = typeAttributes.TypeAttributes | TypeAttributes.Abstract; } else if (clrTypeInfo.IsSealed) { CodeTypeDeclaration codeTypeDeclaration = typeDecl; codeTypeDeclaration.TypeAttributes = codeTypeDeclaration.TypeAttributes | TypeAttributes.Sealed; } this.decl = typeDecl; this.AddBaseType(); this.CreateServicesMembers(); this.CreateDefaultConstructor(clrTypeInfo.Annotations); }
private void SetFullTypeName(ClrTypeInfo typeInfo, string parentIdentifier) { if (parentIdentifier == null) { if (typeInfo.clrtypeNs == string.Empty) { currentFullTypeName = typeInfo.clrtypeName; } else { currentFullTypeName = typeInfo.clrtypeNs + "." + typeInfo.clrtypeName; } } else { currentFullTypeName = parentIdentifier + "." + typeInfo.clrtypeName; } typeInfo.clrFullTypeName = currentFullTypeName; XmlQualifiedName baseTypeName = typeInfo.BaseTypeName; if (baseTypeName != XmlQualifiedName.Empty) { string clrNamespace = settings.GetClrNamespace(baseTypeName.Namespace); string baseTypeIdentifier = null; if (nameMappings.TryGetValue(typeInfo.baseType, out baseTypeIdentifier)) { typeInfo.baseTypeClrName = baseTypeIdentifier; typeInfo.baseTypeClrNs = clrNamespace; } } if (typeInfo.typeOrigin == SchemaOrigin.Element && (rootElementName.IsEmpty || typeInfo.IsRoot)) { rootElementName = new XmlQualifiedName(typeInfo.schemaName, typeInfo.schemaNs); } }
private void AppendRegExInformation(ClrTypeInfo typeInfo) { if ((typeInfo.ContentModelRegEx == null ? false : typeInfo.ContentModelRegEx.Length > 0)) { string text = string.Concat("Regular expression: ", typeInfo.ContentModelRegEx); this.AppendMessage(typeInfo.Annotations, "summaryRegEx", text); } }
private void AppendRegExInformation(ClrTypeInfo typeInfo) { if (typeInfo.ContentModelRegEx != null && typeInfo.ContentModelRegEx.Length > 0) { string text = "Regular expression: " + typeInfo.ContentModelRegEx; AppendMessage(typeInfo.Annotations, "summaryRegEx", text); } }
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); } }
private ClrPropertyInfo BuildProperty(XmlSchemaAttribute attribute, bool fromBaseType, bool isNew, ClrTypeInfo containingType = null) { string schemaName = attribute.QualifiedName.Name; string schemaNs = attribute.QualifiedName.Namespace; string propertyName = localSymbolTable.AddAttribute(attribute); Occurs attrPropertyOccurs = attribute.Use == XmlSchemaUse.Required ? Occurs.One : Occurs.ZeroOrOne; ClrPropertyInfo propertyInfo = new ClrPropertyInfo(propertyName, schemaNs, schemaName, attrPropertyOccurs); propertyInfo.Origin = SchemaOrigin.Attribute; propertyInfo.FromBaseType = fromBaseType; propertyInfo.IsNew = isNew; propertyInfo.VerifyRequired = configSettings.VerifyRequired; XmlSchemaSimpleType schemaType = attribute.AttributeSchemaType; var isInlineEnum = attribute.AttributeSchemaType.IsEnum() && attribute.AttributeSchemaType.IsDerivedByRestriction() && ((attribute.AttributeSchemaType.Content as XmlSchemaSimpleTypeRestriction)?.Facets .Cast <XmlSchemaObject>().Any() ?? false); var isAnonymous = !attribute.AttributeSchemaType.IsGlobal() && !attribute.AttributeSchemaType.IsBuiltInSimpleType(); var qName = schemaType.QualifiedName; if (qName.IsEmpty) { qName = attribute.QualifiedName; } // http://linqtoxsd.codeplex.com/WorkItem/View.aspx?WorkItemId=4106 ClrTypeReference typeRef = BuildTypeReference(schemaType, qName, isAnonymous, true); if (isInlineEnum && isAnonymous) { typeRef.Name += "Enum"; if (typeRef.ClrFullTypeName.IsNullOrEmpty()) { var typeScopedResolutionString = containingType?.GetNestedTypeScopedResolutionString(); if (typeScopedResolutionString.IsNullOrEmpty()) // if this is empty, then take the referencing element { var closestNamedParent = attribute.GetClosestNamedParent().GetPotentialName(); typeScopedResolutionString = closestNamedParent; } typeRef.UpdateClrFullTypeName(propertyInfo, typeScopedResolutionString); } } propertyInfo.TypeReference = typeRef; Debug.Assert(schemaType.Datatype != null); SetFixedDefaultValue(attribute, propertyInfo); return(propertyInfo); }
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); } }
private ClrPropertyInfo InitializeTypedValuePropertyInfo(ClrTypeInfo typeInfo, ClrPropertyInfo typedValPropertyInfo, ClrTypeReference innerType) { if (typedValPropertyInfo == null) { typedValPropertyInfo = new ClrPropertyInfo(Constants.SInnerTypePropertyName, string.Empty, Constants.SInnerTypePropertyName, Occurs.One); typedValPropertyInfo.Origin = SchemaOrigin.Text; } else { typedValPropertyInfo.Reset(); } typedValPropertyInfo.TypeReference = innerType; if (typeInfo.IsSubstitutionMember()) { typedValPropertyInfo.IsNew = true; } typedValPropertyInfo.UpdateTypeReference(currentFullTypeName, currentNamespace, nameMappings); return(typedValPropertyInfo); }
private void SetFullTypeName(ClrTypeInfo typeInfo, string parentIdentifier) { bool flag; if (parentIdentifier != null) { this.currentFullTypeName = string.Concat(parentIdentifier, ".", typeInfo.clrtypeName); } else if (!(typeInfo.clrtypeNs == string.Empty)) { this.currentFullTypeName = string.Concat(typeInfo.clrtypeNs, ".", typeInfo.clrtypeName); } else { this.currentFullTypeName = typeInfo.clrtypeName; } typeInfo.clrFullTypeName = this.currentFullTypeName; XmlQualifiedName baseTypeName = typeInfo.BaseTypeName; if (baseTypeName != XmlQualifiedName.Empty) { string clrNamespace = this.settings.GetClrNamespace(baseTypeName.Namespace); string baseTypeIdentifier = null; if (this.nameMappings.TryGetValue(typeInfo.baseType, out baseTypeIdentifier)) { typeInfo.baseTypeClrName = baseTypeIdentifier; typeInfo.baseTypeClrNs = clrNamespace; } } if (typeInfo.typeOrigin != SchemaOrigin.Element) { flag = true; } else { flag = (this.rootElementName.IsEmpty ? false : !typeInfo.IsRoot); } if (!flag) { this.rootElementName = new XmlQualifiedName(typeInfo.schemaName, typeInfo.schemaNs); } }
private ClrPropertyInfo InitializeTypedValuePropertyInfo(ClrTypeInfo typeInfo, ClrPropertyInfo typedValPropertyInfo, ClrTypeReference innerType) { if (typedValPropertyInfo != null) { typedValPropertyInfo.Reset(); } else { typedValPropertyInfo = new ClrPropertyInfo("TypedValue", string.Empty, "TypedValue", Occurs.One) { Origin = SchemaOrigin.Text }; } typedValPropertyInfo.TypeReference = innerType; if (typeInfo.IsSubstitutionMember()) { typedValPropertyInfo.IsNew = true; } typedValPropertyInfo.UpdateTypeReference(this.currentFullTypeName, this.currentNamespace, this.nameMappings); return(typedValPropertyInfo); }
private void SetFullTypeName(ClrTypeInfo typeInfo, string parentIdentifier) { if(parentIdentifier == null) { if(typeInfo.clrtypeNs == string.Empty) currentFullTypeName = typeInfo.clrtypeName; else currentFullTypeName = typeInfo.clrtypeNs + "." + typeInfo.clrtypeName; } else { currentFullTypeName = parentIdentifier + "." + typeInfo.clrtypeName; } typeInfo.clrFullTypeName = currentFullTypeName; XmlQualifiedName baseTypeName = typeInfo.BaseTypeName; if (baseTypeName != XmlQualifiedName.Empty) { string clrNamespace = settings.GetClrNamespace(baseTypeName.Namespace); string baseTypeIdentifier = null; if (nameMappings.TryGetValue(typeInfo.baseType, out baseTypeIdentifier)) { typeInfo.baseTypeClrName = baseTypeIdentifier; typeInfo.baseTypeClrNs = clrNamespace; } } if (typeInfo.typeOrigin == SchemaOrigin.Element && (rootElementName.IsEmpty || typeInfo.IsRoot)) { rootElementName = new XmlQualifiedName(typeInfo.schemaName, typeInfo.schemaNs); } }
private ClrPropertyInfo InitializeTypedValuePropertyInfo(ClrTypeInfo typeInfo, ClrPropertyInfo typedValPropertyInfo, ClrTypeReference innerType) { if (typedValPropertyInfo == null) { typedValPropertyInfo = new ClrPropertyInfo(Constants.SInnerTypePropertyName, string.Empty, Constants.SInnerTypePropertyName, Occurs.One); typedValPropertyInfo.Origin = SchemaOrigin.Text; } else { typedValPropertyInfo.Reset(); } typedValPropertyInfo.TypeReference = innerType; if (typeInfo.IsSubstitutionMember()) { typedValPropertyInfo.IsNew = true; } typedValPropertyInfo.UpdateTypeReference(currentFullTypeName, currentNamespace, nameMappings); return typedValPropertyInfo; }
protected void InnerInit() { decl = null; clrTypeInfo = null; }
internal static void ApplyAnnotations(CodeTypeMember typeDecl, ClrTypeInfo typeInfo) { ApplyAnnotations(typeDecl, typeInfo.Annotations, null); }
internal void ApplyAnnotations(ClrTypeInfo typeInfo) { ApplyAnnotations(decl, typeInfo); }
internal void CreateTypeDeclaration(ClrTypeInfo clrTypeInfo) { this.clrTypeInfo = clrTypeInfo; SetElementWildCardFlag(clrTypeInfo.HasElementWildCard); string schemaName = clrTypeInfo.schemaName; string schemaNs = clrTypeInfo.schemaNs; string clrTypeName = clrTypeInfo.clrtypeName; SchemaOrigin typeOrigin = clrTypeInfo.typeOrigin; CodeTypeDeclaration typeDecl = CodeDomHelper.CreateTypeDeclaration(clrTypeName, InnerType); if (clrTypeInfo.IsAbstract) { typeDecl.TypeAttributes |= TypeAttributes.Abstract; } else if (clrTypeInfo.IsSealed) { typeDecl.TypeAttributes |= TypeAttributes.Sealed; } decl = typeDecl; AddBaseType(); CreateServicesMembers(); CreateDefaultConstructor(clrTypeInfo.Annotations); }
protected void InnerInit() { this.decl = null; this.clrTypeInfo = null; }
internal static void ApplyAnnotations(CodeTypeMember typeDecl, ClrTypeInfo typeInfo) { TypeBuilder.ApplyAnnotations(typeDecl, typeInfo.Annotations, null); }
internal void ApplyAnnotations(ClrTypeInfo typeInfo) { TypeBuilder.ApplyAnnotations(this.decl, typeInfo); }
private void BuildAnnotationInformation(ClrTypeInfo typeInfo, XmlSchemaObject schemaObject) { AppendXsdDocumentationInformation(typeInfo.Annotations, schemaObject); AppendRegExInformation(typeInfo); }