private CodeMethodInvokeExpression SetNameMethodCall() { CodeTypeReferenceExpression codeTypeReferenceExpression = new CodeTypeReferenceExpression("XTypedServices"); CodeExpression[] codeExpressionArray = new CodeExpression[] { CodeDomHelper.This(), CodeDomHelper.CreateFieldReference("this", this.memberName) }; return(new CodeMethodInvokeExpression(codeTypeReferenceExpression, "SetName", codeExpressionArray)); }
internal void AddGetStatements(CodeStatementCollection getStatements) { CodeThisReferenceExpression codeThisReferenceExpression = CodeDomHelper.This(); CodeExpression[] codeExpressionArray = new CodeExpression[] { CodeDomHelper.CreateFieldReference("WildCard", "DefaultWildCard") }; getStatements.Add(new CodeMethodReturnStatement(CodeDomHelper.CreateMethodCall(codeThisReferenceExpression, "GetWildCards", codeExpressionArray))); }
private void AddSubstGetStatements(CodeStatementCollection getStatements) { Debug.Assert(this.propertyOrigin == SchemaOrigin.Element); CodeExpression[] substParams = new CodeExpression[this.substitutionMembers.Count + 2]; substParams[0] = CodeDomHelper.This(); substParams[1] = CodeDomHelper.SingletonTypeManager(); int i = 2; foreach (XmlSchemaElement elem in this.substitutionMembers) { int num = i; i = num + 1; substParams[num] = CodeDomHelper.XNameGetExpression(elem.QualifiedName.Name, elem.QualifiedName.Namespace); } getStatements.Add(new CodeVariableDeclarationStatement("XTypedElement", "x", CodeDomHelper.CreateMethodCall(new CodeTypeReferenceExpression("XTypedServices"), "ToSubstitutedXTypedElement", substParams))); this.CheckOccurrence(getStatements); getStatements.Add(new CodeMethodReturnStatement(new CodeCastExpression(this.ReturnType, new CodeVariableReferenceExpression("x")))); }
private CodeVariableDeclarationStatement GetValueMethodCall() { CodeVariableDeclarationStatement codeVariableDeclarationStatement; CodeExpression[] codeExpressionArray; switch (this.propertyOrigin) { case SchemaOrigin.None: case SchemaOrigin.Fragment: { throw new InvalidOperationException(); } case SchemaOrigin.Element: { CodeThisReferenceExpression codeThisReferenceExpression = CodeDomHelper.This(); codeExpressionArray = new CodeExpression[] { this.xNameGetExpression }; codeVariableDeclarationStatement = new CodeVariableDeclarationStatement("XElement", "x", CodeDomHelper.CreateMethodCall(codeThisReferenceExpression, "GetElement", codeExpressionArray)); break; } case SchemaOrigin.Attribute: { CodeThisReferenceExpression codeThisReferenceExpression1 = CodeDomHelper.This(); codeExpressionArray = new CodeExpression[] { this.xNameGetExpression }; codeVariableDeclarationStatement = new CodeVariableDeclarationStatement("XAttribute", "x", CodeDomHelper.CreateMethodCall(codeThisReferenceExpression1, "Attribute", codeExpressionArray)); break; } case SchemaOrigin.Text: { codeVariableDeclarationStatement = new CodeVariableDeclarationStatement("XElement", "x", new CodePropertyReferenceExpression(CodeDomHelper.This(), "Untyped")); break; } default: { throw new InvalidOperationException(); } } return(codeVariableDeclarationStatement); }
private CodeMethodInvokeExpression SetValueMethodCall() { CodeExpression[] codeExpressionArray; CodeMethodInvokeExpression methodCall = null; string setMethodName = "Set"; bool isUnion = (!this.IsUnion ? false : this.propertyOrigin != SchemaOrigin.Element); if (!(this.IsRef ? true : !this.IsSchemaList)) { setMethodName = string.Concat(setMethodName, "List"); } else if (isUnion) { setMethodName = string.Concat(setMethodName, "Union"); } bool validation = this.Validation; bool xNameParm = true; switch (this.propertyOrigin) { case SchemaOrigin.None: case SchemaOrigin.Fragment: { throw new InvalidOperationException(); } case SchemaOrigin.Element: { setMethodName = string.Concat(setMethodName, "Element"); break; } case SchemaOrigin.Attribute: { validation = false; setMethodName = string.Concat(setMethodName, "Attribute"); break; } case SchemaOrigin.Text: { setMethodName = string.Concat(setMethodName, "Value"); xNameParm = false; break; } default: { throw new InvalidOperationException(); } } if (isUnion) { if (!xNameParm) { CodeThisReferenceExpression codeThisReferenceExpression = CodeDomHelper.This(); codeExpressionArray = new CodeExpression[] { CodeDomHelper.SetValue(), new CodePrimitiveExpression(this.propertyName), CodeDomHelper.This(), this.GetSimpleTypeClassExpression() }; methodCall = CodeDomHelper.CreateMethodCall(codeThisReferenceExpression, setMethodName, codeExpressionArray); } else { CodeThisReferenceExpression codeThisReferenceExpression1 = CodeDomHelper.This(); codeExpressionArray = new CodeExpression[] { CodeDomHelper.SetValue(), new CodePrimitiveExpression(this.propertyName), CodeDomHelper.This(), this.xNameGetExpression, this.GetSimpleTypeClassExpression() }; methodCall = CodeDomHelper.CreateMethodCall(codeThisReferenceExpression1, setMethodName, codeExpressionArray); } } else if (validation) { setMethodName = string.Concat(setMethodName, "WithValidation"); if (!xNameParm) { CodeThisReferenceExpression codeThisReferenceExpression2 = CodeDomHelper.This(); codeExpressionArray = new CodeExpression[] { CodeDomHelper.SetValue(), new CodePrimitiveExpression(base.PropertyName), this.GetSimpleTypeClassExpression() }; methodCall = CodeDomHelper.CreateMethodCall(codeThisReferenceExpression2, setMethodName, codeExpressionArray); } else { CodeThisReferenceExpression codeThisReferenceExpression3 = CodeDomHelper.This(); codeExpressionArray = new CodeExpression[] { this.xNameGetExpression, CodeDomHelper.SetValue(), new CodePrimitiveExpression(base.PropertyName), this.GetSimpleTypeClassExpression() }; methodCall = CodeDomHelper.CreateMethodCall(codeThisReferenceExpression3, setMethodName, codeExpressionArray); } } else if (!xNameParm) { CodeThisReferenceExpression codeThisReferenceExpression4 = CodeDomHelper.This(); codeExpressionArray = new CodeExpression[] { CodeDomHelper.SetValue(), this.GetSchemaDatatypeExpression() }; methodCall = CodeDomHelper.CreateMethodCall(codeThisReferenceExpression4, setMethodName, codeExpressionArray); } else { CodeThisReferenceExpression codeThisReferenceExpression5 = CodeDomHelper.This(); codeExpressionArray = new CodeExpression[] { this.xNameGetExpression, CodeDomHelper.SetValue() }; methodCall = CodeDomHelper.CreateMethodCall(codeThisReferenceExpression5, setMethodName, codeExpressionArray); if ((this.IsRef ? false : this.typeRef.IsSimpleType)) { methodCall.Parameters.Add(this.GetSchemaDatatypeExpression()); } } return(methodCall); }
private CodeExpression[] GetListParameters(bool set, bool constructor) { CodeExpression[] listParameters = null; int paramCount = 2; CodeExpression typeParam = null; CodeExpression nameOrValue = null; if (set) { paramCount++; if (!constructor) { nameOrValue = CodeDomHelper.SetValue(); } else { nameOrValue = new CodeVariableReferenceExpression(this.propertyName); } } if (!this.IsSubstitutionHead) { paramCount++; if (!this.typeRef.IsSimpleType) { typeParam = CodeDomHelper.SingletonTypeManager(); } else { typeParam = this.GetSchemaDatatypeExpression(); if (this.fixedDefaultValue != null) { paramCount++; } } } else { paramCount += this.substitutionMembers.Count; typeParam = CodeDomHelper.SingletonTypeManager(); } listParameters = new CodeExpression[paramCount]; int paramIndex = 0; int num = paramIndex; paramIndex = num + 1; listParameters[num] = CodeDomHelper.This(); int num1 = paramIndex; paramIndex = num1 + 1; listParameters[num1] = typeParam; if (nameOrValue != null) { int num2 = paramIndex; paramIndex = num2 + 1; listParameters[num2] = nameOrValue; } if (!this.IsSubstitutionHead) { int num3 = paramIndex; paramIndex = num3 + 1; listParameters[num3] = this.xNameGetExpression; } else { foreach (XmlSchemaElement elem in this.substitutionMembers) { int num4 = paramIndex; paramIndex = num4 + 1; listParameters[num4] = CodeDomHelper.XNameGetExpression(elem.QualifiedName.Name, elem.QualifiedName.Namespace); } } if (this.fixedDefaultValue != null) { if (this.FixedValue == null) { int num5 = paramIndex; paramIndex = num5 + 1; listParameters[num5] = new CodeFieldReferenceExpression(null, NameGenerator.ChangeClrName(this.propertyName, NameOptions.MakeDefaultValueField)); } else { int num6 = paramIndex; paramIndex = num6 + 1; listParameters[num6] = new CodeFieldReferenceExpression(null, NameGenerator.ChangeClrName(this.propertyName, NameOptions.MakeFixedValueField)); } } return(listParameters); }
public static CodeConstructor CreateXRootFunctionalConstructor(string typeName) { CodeConstructor constructor = CodeDomHelper.CreateConstructor(MemberAttributes.Public); constructor.Parameters.Add(new CodeParameterDeclarationExpression(new CodeTypeReference(typeName), "root")); CodeStatementCollection statements = constructor.Statements; CodeFieldReferenceExpression codeFieldReferenceExpression = new CodeFieldReferenceExpression(CodeDomHelper.This(), "doc"); CodeExpression[] codePropertyReferenceExpression = new CodeExpression[] { new CodePropertyReferenceExpression(new CodeVariableReferenceExpression("root"), "Untyped") }; statements.Add(new CodeAssignStatement(codeFieldReferenceExpression, new CodeObjectCreateExpression("XDocument", codePropertyReferenceExpression))); constructor.Statements.Add(new CodeAssignStatement(new CodeFieldReferenceExpression(CodeDomHelper.This(), "rootObject"), new CodeVariableReferenceExpression("root"))); return(constructor); }
internal void CreateServicesMembers() { CodeMethodInvokeExpression callClone; CodeExpression[] codeCastExpression; string innerType = this.InnerType; string clrTypeName = this.clrTypeInfo.clrtypeName; bool useAutoTyping = (this.clrTypeInfo.IsAbstract ? true : this.clrTypeInfo.IsSubstitutionHead); if (this.clrTypeInfo.typeOrigin == SchemaOrigin.Element) { CodeTypeMember load = CodeDomHelper.CreateStaticMethod("Load", clrTypeName, innerType, "xmlFile", "System.String", useAutoTyping); CodeTypeMember loadReader = CodeDomHelper.CreateStaticMethod("Load", clrTypeName, innerType, "xmlFile", "System.IO.TextReader", useAutoTyping); CodeTypeMember parse = CodeDomHelper.CreateStaticMethod("Parse", clrTypeName, innerType, "xml", "System.String", useAutoTyping); if (!this.clrTypeInfo.IsDerived) { this.decl.Members.Add(CodeDomHelper.CreateSave("xmlFile", "System.String")); this.decl.Members.Add(CodeDomHelper.CreateSave("tw", "System.IO.TextWriter")); this.decl.Members.Add(CodeDomHelper.CreateSave("xmlWriter", "System.Xml.XmlWriter")); } else { CodeTypeMember attributes = load; attributes.Attributes = attributes.Attributes | MemberAttributes.New; CodeTypeMember codeTypeMember = parse; codeTypeMember.Attributes = codeTypeMember.Attributes | MemberAttributes.New; } this.decl.Members.Add(load); this.decl.Members.Add(loadReader); this.decl.Members.Add(parse); } CodeTypeMember cast = CodeDomHelper.CreateCast(clrTypeName, innerType, useAutoTyping); this.decl.Members.Add(cast); if (!this.clrTypeInfo.IsAbstract) { CodeMemberMethod clone = CodeDomHelper.CreateMethod("Clone", MemberAttributes.Override | MemberAttributes.FamilyAndAssembly | MemberAttributes.FamilyOrAssembly | MemberAttributes.Public, new CodeTypeReference("XTypedElement")); if (innerType != null) { callClone = CodeDomHelper.CreateMethodCall(new CodePropertyReferenceExpression(CodeDomHelper.This(), "Content"), "Clone", new CodeExpression[0]); CodeStatementCollection statements = clone.Statements; codeCastExpression = new CodeExpression[] { new CodeCastExpression(new CodeTypeReference(innerType), callClone) }; statements.Add(new CodeMethodReturnStatement(new CodeObjectCreateExpression(clrTypeName, codeCastExpression))); } else { CodeTypeReferenceExpression codeTypeReferenceExpression = new CodeTypeReferenceExpression("XTypedServices"); string str = string.Concat("CloneXTypedElement<", clrTypeName, ">"); codeCastExpression = new CodeExpression[] { new CodeThisReferenceExpression() }; callClone = CodeDomHelper.CreateMethodCall(codeTypeReferenceExpression, str, codeCastExpression); clone.Statements.Add(new CodeMethodReturnStatement(callClone)); } this.decl.Members.Add(clone); } }
internal override CodeConstructor CreateFunctionalConstructor(List <ClrAnnotation> annotations) { string parameterName = "content"; CodeConstructor constructor = CodeDomHelper.CreateConstructor(MemberAttributes.Public); CodeTypeReference returnType = null; if (!this.isSchemaList) { returnType = new CodeTypeReference(this.simpleTypeName); } else { CodeTypeReference[] codeTypeReference = new CodeTypeReference[] { new CodeTypeReference(this.simpleTypeName) }; returnType = new CodeTypeReference("IList", codeTypeReference); } constructor.Parameters.Add(new CodeParameterDeclarationExpression(returnType, parameterName)); constructor.Statements.Add(new CodeAssignStatement(new CodePropertyReferenceExpression(CodeDomHelper.This(), "TypedValue"), new CodeVariableReferenceExpression(parameterName))); TypeBuilder.ApplyAnnotations(constructor, annotations, null); this.decl.Members.Add(constructor); return(constructor); }