private void ProcessWrapperTypes() { if (wrapperRootElements == null) { //No Globalelements with global types return; } XWrapperTypedElementBuilder wrapperBuilder = new XWrapperTypedElementBuilder(); XSimpleTypedElementBuilder simpleTypeBuilder = new XSimpleTypedElementBuilder(); TypeBuilder builder = null; ClrPropertyInfo typedValPropertyInfo = null; foreach (ClrWrapperTypeInfo typeInfo in wrapperRootElements) { SetFullTypeName(typeInfo, null); ClrTypeReference innerType = typeInfo.InnerType; if (innerType.IsSimpleType) { typedValPropertyInfo = InitializeTypedValuePropertyInfo(typeInfo, typedValPropertyInfo, innerType); simpleTypeBuilder.Init(typedValPropertyInfo.ClrTypeName, innerType.IsSchemaList); simpleTypeBuilder.CreateTypeDeclaration(typeInfo); simpleTypeBuilder.CreateFunctionalConstructor(typeInfo.Annotations); typedValPropertyInfo.SetFixedDefaultValue(typeInfo); simpleTypeBuilder.CreateProperty(typedValPropertyInfo, typeInfo.Annotations); simpleTypeBuilder.AddTypeToTypeManager(elementDictionaryAddStatements, Constants.ElementDictionaryField); simpleTypeBuilder.ApplyAnnotations(typeInfo); builder = simpleTypeBuilder; } else { string innerTypeName = null; string innerTypeFullName = innerType.GetClrFullTypeName(typeInfo.clrtypeNs, nameMappings, out innerTypeName); string innerTypeNs = innerType.Namespace; CodeNamespace innerTypeCodeNamespace = GetCodeNamespace(innerTypeNs); CodeTypeDeclaration innerTypeDecl = GetCodeTypeDeclaration(innerTypeName, innerTypeCodeNamespace); TypeAttributes innerTypeAttributes = TypeAttributes.Class; if (innerTypeDecl != null) { innerTypeAttributes = innerTypeDecl.TypeAttributes; } else if (innerTypeName != Constants.XTypedElement) { continue; } currentNamespace = typeInfo.clrtypeNs; wrapperBuilder.Init(innerTypeFullName, innerTypeNs, innerTypeAttributes); wrapperBuilder.CreateTypeDeclaration(typeInfo); wrapperBuilder.CreateFunctionalConstructor(typeInfo.Annotations); wrapperBuilder.ApplyAnnotations(typeInfo); wrapperBuilder.AddTypeToTypeManager(elementDictionaryAddStatements, wrapperDictionaryAddStatements); if (!typeInfo.HasBaseContentType) { //Add innerType properties only if the wrapper's type is not the same as the substitutionGroup head type ClrWrappingPropertyInfo wrappingPropertyInfo = null; //Create forwarding properties if (innerTypeName != Constants.XTypedElement) { //If the wrapped type is xs:anyType, no forwarding properties to create wrappingPropertyInfo = new ClrWrappingPropertyInfo(); foreach(CodeTypeMember member in innerTypeDecl.Members) { CodeMemberProperty memberProperty = member as CodeMemberProperty; if (ForwardProperty(memberProperty)) { //Do not forward over TypeManager, SchemaName etc wrappingPropertyInfo.Init(memberProperty); wrapperBuilder.CreateProperty(wrappingPropertyInfo, typeInfo.Annotations); } } } } builder = wrapperBuilder; } builder.ImplementInterfaces(settings.EnableServiceReference); codeNamespace = GetCodeNamespace(typeInfo.clrtypeNs); codeNamespace.Types.Add(builder.TypeDeclaration); List<CodeTypeDeclaration> types; codeNamespace = GetCodeNamespace(typeInfo.clrtypeNs); if (!xroots.TryGetValue(codeNamespace, out types)) { types = new List<CodeTypeDeclaration>(); xroots.Add(codeNamespace, types); } types.Add(builder.TypeDeclaration); } }
private void ProcessWrapperTypes() { if (wrapperRootElements == null) { //No Globalelements with global types return; } XWrapperTypedElementBuilder wrapperBuilder = new XWrapperTypedElementBuilder(settings); XSimpleTypedElementBuilder simpleTypeBuilder = new XSimpleTypedElementBuilder(settings); TypeBuilder builder = null; ClrPropertyInfo typedValPropertyInfo = null; foreach (ClrWrapperTypeInfo typeInfo in wrapperRootElements) { SetFullTypeName(typeInfo, null); ClrTypeReference innerType = typeInfo.InnerType; if (innerType.IsSimpleType) { typedValPropertyInfo = InitializeTypedValuePropertyInfo(typeInfo, typedValPropertyInfo, innerType); simpleTypeBuilder.Init(typedValPropertyInfo.ClrTypeName, innerType.IsSchemaList); simpleTypeBuilder.CreateTypeDeclaration(typeInfo); simpleTypeBuilder.CreateFunctionalConstructor(typeInfo.Annotations); typedValPropertyInfo.SetFixedDefaultValue(typeInfo); simpleTypeBuilder.CreateProperty(typedValPropertyInfo, typeInfo.Annotations); simpleTypeBuilder.AddTypeToTypeManager(elementDictionaryAddStatements, Constants.ElementDictionaryField); simpleTypeBuilder.ApplyAnnotations(typeInfo); builder = simpleTypeBuilder; } else { string innerTypeName = null; string innerTypeFullName = innerType.GetClrFullTypeName(typeInfo.clrtypeNs, nameMappings, out innerTypeName); string innerTypeNs = innerType.Namespace; CodeNamespace innerTypeCodeNamespace = GetCodeNamespace(innerTypeNs); CodeTypeDeclaration innerTypeDecl = GetCodeTypeDeclaration(innerTypeName, innerTypeCodeNamespace); TypeAttributes innerTypeAttributes = TypeAttributes.Class; if (innerTypeDecl != null) { innerTypeAttributes = innerTypeDecl.TypeAttributes; } else if (innerTypeName != Constants.XTypedElement) { continue; } currentNamespace = typeInfo.clrtypeNs; wrapperBuilder.Init(innerTypeFullName, innerTypeNs, innerTypeAttributes); wrapperBuilder.CreateTypeDeclaration(typeInfo); wrapperBuilder.CreateFunctionalConstructor(typeInfo.Annotations); wrapperBuilder.ApplyAnnotations(typeInfo); wrapperBuilder.AddTypeToTypeManager(elementDictionaryAddStatements, wrapperDictionaryAddStatements); if (!typeInfo.HasBaseContentType) { //Add innerType properties only if the wrapper's type is not the same as the substitutionGroup head type ClrWrappingPropertyInfo wrappingPropertyInfo = null; //Create forwarding properties if (innerTypeName != Constants.XTypedElement) { //If the wrapped type is xs:anyType, no forwarding properties to create wrappingPropertyInfo = new ClrWrappingPropertyInfo(); foreach (CodeTypeMember member in innerTypeDecl.Members) { CodeMemberProperty memberProperty = member as CodeMemberProperty; if (ForwardProperty(memberProperty)) { //Do not forward over TypeManager, SchemaName etc wrappingPropertyInfo.Init(memberProperty); wrapperBuilder.CreateProperty(wrappingPropertyInfo, typeInfo.Annotations); } } } } builder = wrapperBuilder; } builder.ImplementInterfaces(settings.EnableServiceReference); codeNamespace = GetCodeNamespace(typeInfo.clrtypeNs); codeNamespace.Types.Add(builder.TypeDeclaration); List <CodeTypeDeclaration> types; codeNamespace = GetCodeNamespace(typeInfo.clrtypeNs); if (!xroots.TryGetValue(codeNamespace, out types)) { types = new List <CodeTypeDeclaration>(); xroots.Add(codeNamespace, types); } types.Add(builder.TypeDeclaration); } }
private void ProcessWrapperTypes() { List <CodeTypeDeclaration> types; if (this.wrapperRootElements != null) { XWrapperTypedElementBuilder wrapperBuilder = new XWrapperTypedElementBuilder(); XSimpleTypedElementBuilder simpleTypeBuilder = new XSimpleTypedElementBuilder(); TypeBuilder builder = null; ClrPropertyInfo typedValPropertyInfo = null; foreach (ClrWrapperTypeInfo typeInfo in this.wrapperRootElements) { this.SetFullTypeName(typeInfo, null); ClrTypeReference innerType = typeInfo.InnerType; if (!innerType.IsSimpleType) { string innerTypeName = null; string innerTypeFullName = innerType.GetClrFullTypeName(typeInfo.clrtypeNs, this.nameMappings, out innerTypeName); string innerTypeNs = innerType.Namespace; CodeTypeDeclaration innerTypeDecl = this.GetCodeTypeDeclaration(innerTypeName, this.GetCodeNamespace(innerTypeNs)); TypeAttributes innerTypeAttributes = TypeAttributes.NotPublic; if (innerTypeDecl != null) { innerTypeAttributes = innerTypeDecl.TypeAttributes; } else if (innerTypeName != "XTypedElement") { continue; } this.currentNamespace = typeInfo.clrtypeNs; wrapperBuilder.Init(innerTypeFullName, innerTypeNs, innerTypeAttributes); wrapperBuilder.CreateTypeDeclaration(typeInfo); wrapperBuilder.CreateFunctionalConstructor(typeInfo.Annotations); wrapperBuilder.ApplyAnnotations(typeInfo); wrapperBuilder.AddTypeToTypeManager(CodeDomTypesGenerator.elementDictionaryAddStatements, CodeDomTypesGenerator.wrapperDictionaryAddStatements); if (!typeInfo.HasBaseContentType) { ClrWrappingPropertyInfo wrappingPropertyInfo = null; if (innerTypeName != "XTypedElement") { wrappingPropertyInfo = new ClrWrappingPropertyInfo(); foreach (CodeTypeMember member in innerTypeDecl.Members) { CodeMemberProperty memberProperty = member as CodeMemberProperty; if (this.ForwardProperty(memberProperty)) { wrappingPropertyInfo.Init(memberProperty); wrapperBuilder.CreateProperty(wrappingPropertyInfo, typeInfo.Annotations); } } } } builder = wrapperBuilder; } else { typedValPropertyInfo = this.InitializeTypedValuePropertyInfo(typeInfo, typedValPropertyInfo, innerType); simpleTypeBuilder.Init(typedValPropertyInfo.ClrTypeName, innerType.IsSchemaList); simpleTypeBuilder.CreateTypeDeclaration(typeInfo); simpleTypeBuilder.CreateFunctionalConstructor(typeInfo.Annotations); typedValPropertyInfo.SetFixedDefaultValue(typeInfo); simpleTypeBuilder.CreateProperty(typedValPropertyInfo, typeInfo.Annotations); simpleTypeBuilder.AddTypeToTypeManager(CodeDomTypesGenerator.elementDictionaryAddStatements, "elementDictionary"); simpleTypeBuilder.ApplyAnnotations(typeInfo); builder = simpleTypeBuilder; } builder.ImplementInterfaces(this.settings.EnableServiceReference); this.codeNamespace = this.GetCodeNamespace(typeInfo.clrtypeNs); this.codeNamespace.Types.Add(builder.TypeDeclaration); this.codeNamespace = this.GetCodeNamespace(typeInfo.clrtypeNs); if (!this.xroots.TryGetValue(this.codeNamespace, out types)) { types = new List <CodeTypeDeclaration>(); this.xroots.Add(this.codeNamespace, types); } types.Add(builder.TypeDeclaration); } } }