internal void AddTypeToTypeManager(CodeStatementCollection elementDictionaryStatements, CodeStatementCollection wrapperDictionaryStatements) { base.AddTypeToTypeManager(elementDictionaryStatements, "elementDictionary"); string innerTypeFullName = null; if (!this.innerTypeName.Contains(this.innerTypeNs)) { innerTypeFullName = string.Concat("global::", this.innerTypeNs, ".", this.innerTypeName); } CodeExpression[] codeExpressionArray = new CodeExpression[] { CodeDomHelper.Typeof(this.clrTypeInfo.clrFullTypeName), CodeDomHelper.Typeof(innerTypeFullName) }; wrapperDictionaryStatements.Add(CodeDomHelper.CreateMethodCallFromField("wrapperDictionary", "Add", codeExpressionArray)); }
internal void AddTypeToTypeManager(CodeStatementCollection dictionaryStatements, string dictionaryName) { string typeRef = string.Concat("global::", this.clrTypeInfo.clrFullTypeName); CodeExpression[] codeExpressionArray = new CodeExpression[] { CodeDomHelper.XNameGetExpression(this.clrTypeInfo.schemaName, this.clrTypeInfo.schemaNs), CodeDomHelper.Typeof(typeRef) }; dictionaryStatements.Add(CodeDomHelper.CreateMethodCallFromField(dictionaryName, "Add", codeExpressionArray)); }
internal override void CreateProperty(ClrBasePropertyInfo propertyInfo, List <ClrAnnotation> annotations) { if ((!this.clrTypeInfo.InlineBaseType ? false : propertyInfo.FromBaseType)) { propertyInfo.IsNew = true; } this.propertyBuilder.GenerateCode(propertyInfo, annotations); if ((propertyInfo.ContentType != ContentType.Property ? false : !propertyInfo.IsDuplicate)) { CodeStatementCollection codeStatementCollection = this.propertyDictionaryAddStatements; CodeExpression[] codeExpressionArray = new CodeExpression[] { CodeDomHelper.XNameGetExpression(propertyInfo.SchemaName, propertyInfo.PropertyNs), CodeDomHelper.Typeof(propertyInfo.ClrTypeName) }; codeStatementCollection.Add(CodeDomHelper.CreateMethodCallFromField("localElementDictionary", "Add", codeExpressionArray)); } }
internal static CodeTypeDeclaration CreateTypeManager(XmlQualifiedName rootElementName, bool enableServiceReference, CodeStatementCollection typeDictionaryStatements, CodeStatementCollection elementDictionaryStatements, CodeStatementCollection wrapperDictionaryStatements) { string servicesClassName = NameGenerator.GetServicesClassName(); CodeTypeDeclaration servicesTypeDecl = new CodeTypeDeclaration(servicesClassName) { Attributes = MemberAttributes.Public }; CodeMemberField singletonField = CodeDomHelper.CreateMemberField("typeManagerSingleton", servicesClassName, MemberAttributes.Static, true); CodeMemberProperty singletonProperty = CodeDomHelper.CreateProperty("Instance", null, singletonField, MemberAttributes.Abstract | MemberAttributes.Final | MemberAttributes.Static | MemberAttributes.FamilyAndAssembly | MemberAttributes.FamilyOrAssembly | MemberAttributes.Public, false); MemberAttributes privateStatic = MemberAttributes.Abstract | MemberAttributes.Final | MemberAttributes.Static | MemberAttributes.Assembly | MemberAttributes.FamilyOrAssembly | MemberAttributes.Private; CodeTypeConstructor staticServicesConstructor = new CodeTypeConstructor(); CodeTypeReference returnType = CodeDomHelper.CreateDictionaryType("XName", "System.Type"); CodeTypeReference wrapperReturnType = CodeDomHelper.CreateDictionaryType("System.Type", "System.Type"); CodeMemberProperty typeDictProperty = null; if (typeDictionaryStatements.Count <= 0) { typeDictProperty = CodeDomHelper.CreateInterfaceImplProperty("GlobalTypeDictionary", "ILinqToXsdTypeManager", returnType); typeDictProperty.GetStatements.Add(new CodeMethodReturnStatement(new CodeFieldReferenceExpression(new CodeTypeReferenceExpression("XTypedServices"), "EmptyDictionary"))); } else { typeDictProperty = CodeDomHelper.CreateInterfaceImplProperty("GlobalTypeDictionary", "ILinqToXsdTypeManager", returnType, "typeDictionary"); CodeMemberField staticTypeDictionary = CodeDomHelper.CreateDictionaryField("typeDictionary", "XName", "System.Type"); CodeMemberMethod buildTypeDictionary = CodeDomHelper.CreateMethod("BuildTypeDictionary", privateStatic, null); buildTypeDictionary.Statements.AddRange(typeDictionaryStatements); staticServicesConstructor.Statements.Add(CodeDomHelper.CreateMethodCall(null, "BuildTypeDictionary", new CodeExpression[0])); servicesTypeDecl.Members.Add(staticTypeDictionary); servicesTypeDecl.Members.Add(buildTypeDictionary); } CodeMemberProperty elementDictProperty = null; if (elementDictionaryStatements.Count <= 0) { elementDictProperty = CodeDomHelper.CreateInterfaceImplProperty("GlobalElementDictionary", "ILinqToXsdTypeManager", returnType); elementDictProperty.GetStatements.Add(new CodeMethodReturnStatement(new CodeFieldReferenceExpression(new CodeTypeReferenceExpression("XTypedServices"), "EmptyDictionary"))); } else { elementDictProperty = CodeDomHelper.CreateInterfaceImplProperty("GlobalElementDictionary", "ILinqToXsdTypeManager", returnType, "elementDictionary"); CodeMemberField staticElementDictionary = CodeDomHelper.CreateDictionaryField("elementDictionary", "XName", "System.Type"); CodeMemberMethod buildElementDictionary = CodeDomHelper.CreateMethod("BuildElementDictionary", privateStatic, null); buildElementDictionary.Statements.AddRange(elementDictionaryStatements); staticServicesConstructor.Statements.Add(CodeDomHelper.CreateMethodCall(null, "BuildElementDictionary", new CodeExpression[0])); servicesTypeDecl.Members.Add(staticElementDictionary); servicesTypeDecl.Members.Add(buildElementDictionary); } CodeMemberProperty wrapperDictProperty = null; if (wrapperDictionaryStatements.Count <= 0) { wrapperDictProperty = CodeDomHelper.CreateInterfaceImplProperty("RootContentTypeMapping", "ILinqToXsdTypeManager", wrapperReturnType); wrapperDictProperty.GetStatements.Add(new CodeMethodReturnStatement(new CodeFieldReferenceExpression(new CodeTypeReferenceExpression("XTypedServices"), "EmptyTypeMappingDictionary"))); } else { wrapperDictProperty = CodeDomHelper.CreateInterfaceImplProperty("RootContentTypeMapping", "ILinqToXsdTypeManager", wrapperReturnType, "wrapperDictionary"); CodeMemberField staticWrapperDictionary = CodeDomHelper.CreateDictionaryField("wrapperDictionary", "System.Type", "System.Type"); CodeMemberMethod buildWrapperDictionary = CodeDomHelper.CreateMethod("BuildWrapperDictionary", privateStatic, null); buildWrapperDictionary.Statements.AddRange(wrapperDictionaryStatements); staticServicesConstructor.Statements.Add(CodeDomHelper.CreateMethodCall(null, "BuildWrapperDictionary", new CodeExpression[0])); servicesTypeDecl.Members.Add(staticWrapperDictionary); servicesTypeDecl.Members.Add(buildWrapperDictionary); } string schemaSetFieldName = "schemaSet"; CodeTypeReference schemaSetType = new CodeTypeReference("XmlSchemaSet"); CodeMemberField schemaSetField = new CodeMemberField(schemaSetType, schemaSetFieldName) { Attributes = MemberAttributes.Abstract | MemberAttributes.Final | MemberAttributes.Static | MemberAttributes.Assembly | MemberAttributes.FamilyOrAssembly | MemberAttributes.Private }; CodeMemberMethod addSchemasMethod = CodeDomHelper.CreateMethod("AddSchemas", MemberAttributes.Abstract | MemberAttributes.Final | MemberAttributes.Static | MemberAttributes.FamilyOrAssembly, null); addSchemasMethod.Parameters.Add(new CodeParameterDeclarationExpression("XmlSchemaSet", "schemas")); CodeStatementCollection statements = addSchemasMethod.Statements; CodeVariableReferenceExpression codeVariableReferenceExpression = new CodeVariableReferenceExpression("schemas"); CodeExpression[] codeFieldReferenceExpression = new CodeExpression[] { new CodeFieldReferenceExpression(null, schemaSetFieldName) }; statements.Add(CodeDomHelper.CreateMethodCall(codeVariableReferenceExpression, "Add", codeFieldReferenceExpression)); CodeTypeReferenceExpression interLockedType = new CodeTypeReferenceExpression("System.Threading.Interlocked"); CodeMemberProperty schemaSetProperty = CodeDomHelper.CreateInterfaceImplProperty("Schemas", "ILinqToXsdTypeManager", schemaSetType); CodeFieldReferenceExpression schemaSetFieldRef = new CodeFieldReferenceExpression(null, schemaSetFieldName); CodeDirectionExpression schemaSetParam = new CodeDirectionExpression(FieldDirection.Ref, schemaSetFieldRef); CodeStatementCollection getStatements = schemaSetProperty.GetStatements; CodeBinaryOperatorExpression codeBinaryOperatorExpression = new CodeBinaryOperatorExpression(schemaSetFieldRef, CodeBinaryOperatorType.IdentityEquality, new CodePrimitiveExpression(null)); CodeStatement[] codeVariableDeclarationStatement = new CodeStatement[] { new CodeVariableDeclarationStatement(schemaSetType, "tempSet", new CodeObjectCreateExpression(schemaSetType, new CodeExpression[0])), null }; codeFieldReferenceExpression = new CodeExpression[] { schemaSetParam, new CodeVariableReferenceExpression("tempSet"), new CodePrimitiveExpression(null) }; codeVariableDeclarationStatement[1] = new CodeExpressionStatement(CodeDomHelper.CreateMethodCall(interLockedType, "CompareExchange", codeFieldReferenceExpression)); getStatements.Add(new CodeConditionStatement(codeBinaryOperatorExpression, codeVariableDeclarationStatement)); schemaSetProperty.GetStatements.Add(new CodeMethodReturnStatement(new CodeVariableReferenceExpression(schemaSetFieldName))); schemaSetProperty.SetStatements.Add(new CodeAssignStatement(schemaSetFieldRef, new CodePropertySetValueReferenceExpression())); servicesTypeDecl.Members.Add(schemaSetField); servicesTypeDecl.Members.Add(schemaSetProperty); servicesTypeDecl.Members.Add(addSchemasMethod); servicesTypeDecl.Members.Add(typeDictProperty); servicesTypeDecl.Members.Add(elementDictProperty); servicesTypeDecl.Members.Add(wrapperDictProperty); servicesTypeDecl.BaseTypes.Add("ILinqToXsdTypeManager"); CodeMemberMethod getRootType = new CodeMemberMethod() { Attributes = MemberAttributes.Abstract | MemberAttributes.Final | MemberAttributes.Static | MemberAttributes.FamilyAndAssembly | MemberAttributes.FamilyOrAssembly | MemberAttributes.Public, Name = "GetRootType", ReturnType = new CodeTypeReference("System.Type") }; if (!rootElementName.IsEmpty) { CodeStatementCollection codeStatementCollection = getRootType.Statements; CodeFieldReferenceExpression codeFieldReferenceExpression1 = CodeDomHelper.CreateFieldReference(null, "elementDictionary"); codeFieldReferenceExpression = new CodeExpression[] { CodeDomHelper.XNameGetExpression(rootElementName.Name, rootElementName.Namespace) }; codeStatementCollection.Add(new CodeMethodReturnStatement(new CodeIndexerExpression(codeFieldReferenceExpression1, codeFieldReferenceExpression))); } else { getRootType.Statements.Add(new CodeMethodReturnStatement(CodeDomHelper.Typeof("Xml.Schema.Linq.XTypedElement"))); } servicesTypeDecl.Members.Add(staticServicesConstructor); servicesTypeDecl.Members.Add(getRootType); servicesTypeDecl.Members.Add(singletonField); servicesTypeDecl.Members.Add(singletonProperty); return(servicesTypeDecl); }