コード例 #1
0
ファイル: TypesToCodeDom.cs プロジェクト: dipdapdop/linqtoxsd
        private CodeTypeDeclaration ProcessType(ClrContentTypeInfo typeInfo, string parentIdentifier, bool globalType)
        {
            SetFullTypeName(typeInfo, parentIdentifier);

            if(globalType) {
                currentNamespace = typeInfo.clrtypeNs;
            }
            //Build type using TypeBuilder
            typeBuilder = GetTypeBuilder();
            typeBuilder.CreateTypeDeclaration(typeInfo);
            ProcessProperties(typeInfo.Content, typeInfo.Annotations);
            typeBuilder.CreateFunctionalConstructor(typeInfo.Annotations);
            typeBuilder.ImplementInterfaces(settings.EnableServiceReference);
            typeBuilder.ApplyAnnotations(typeInfo);
            if (globalType) {
                if (typeInfo.typeOrigin == SchemaOrigin.Fragment) {
                    typeBuilder.AddTypeToTypeManager(typeDictionaryAddStatements, Constants.TypeDictionaryField);
                }
                else {
                    typeBuilder.AddTypeToTypeManager(elementDictionaryAddStatements, Constants.ElementDictionaryField);
                }
            }
            CodeTypeDeclaration builtType = typeBuilder.TypeDeclaration;
            ProcessNestedTypes(typeInfo.NestedTypes, builtType, typeInfo.clrFullTypeName);
            return builtType;
        }
コード例 #2
0
ファイル: TypesToCodeDom.cs プロジェクト: dipdapdop/linqtoxsd
 private TypeBuilder GetEmptyTypeBuilder()
 {
     if (emptyTypeBuilder == null) {
         emptyTypeBuilder = new XEmptyTypedElementBuilder();
     }
     else {
         emptyTypeBuilder.Init();
     }
     return emptyTypeBuilder;
 }
コード例 #3
0
ファイル: TypesToCodeDom.cs プロジェクト: dipdapdop/linqtoxsd
 private TypeBuilder GetTypeBuilder()
 {
     if (typeBuilder == null) {
         typeBuilder = new XTypedElementBuilder();
     }
     else {
         typeBuilder.Init();
     }
     return typeBuilder;
 }
コード例 #4
0
        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);
            }
        }