public static ChangeClrName ( string clrName, NameOptions options ) : string | ||
clrName | string | |
options | NameOptions | |
return | string |
internal void Init(string innerTypeFullName, string innerTypeNs, TypeAttributes innerTypeAttributes) { base.InnerInit(); this.memberName = NameGenerator.ChangeClrName("Content", NameOptions.MakeField); this.innerTypeName = innerTypeFullName; this.innerTypeNs = innerTypeNs; this.innerTypeAttributes = innerTypeAttributes; }
internal override CodeMemberProperty AddToType(CodeTypeDeclaration parentTypeDecl, List <ClrAnnotation> annotations) { CodeMemberProperty codeMemberProperty; bool flag; if (this.IsDuplicate) { flag = false; } else { flag = (!this.FromBaseType ? true : this.IsNew); } if (flag) { this.CreateFixedDefaultValue(parentTypeDecl); CodeMemberProperty clrProperty = CodeDomHelper.CreateProperty(this.ReturnType, this.hasSet); clrProperty.Name = this.propertyName; this.SetPropertyAttributes(clrProperty); if (this.IsNew) { CodeMemberProperty attributes = clrProperty; attributes.Attributes = attributes.Attributes | MemberAttributes.New; } if (!this.IsList) { this.AddGetStatements(clrProperty.GetStatements); if (this.hasSet) { this.AddSetStatements(clrProperty.SetStatements); } } else { CodeTypeReference listType = this.GetListType(); string listName = NameGenerator.ChangeClrName(this.propertyName, NameOptions.MakeField); this.AddMemberField(listName, listType, parentTypeDecl); this.AddListGetStatements(clrProperty.GetStatements, listType, listName); if (this.hasSet) { this.AddListSetStatements(clrProperty.SetStatements, listType, listName); } } this.ApplyAnnotations(clrProperty, annotations); parentTypeDecl.Members.Add(clrProperty); codeMemberProperty = clrProperty; } else { codeMemberProperty = null; } return(codeMemberProperty); }
internal virtual void InsertDefaultFixedValueInDefaultCtor(CodeConstructor ctor) { if (this.FixedValue != null) { ctor.Statements.Add(new CodeAssignStatement(CodeDomHelper.CreateFieldReference(null, this.propertyName), CodeDomHelper.CreateFieldReference(null, NameGenerator.ChangeClrName(this.propertyName, NameOptions.MakeFixedValueField)))); } else if (this.DefaultValue != null) { ctor.Statements.Add(new CodeAssignStatement(CodeDomHelper.CreateFieldReference(null, this.propertyName), CodeDomHelper.CreateFieldReference(null, NameGenerator.ChangeClrName(this.propertyName, NameOptions.MakeDefaultValueField)))); } }
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); }
protected void CreateFixedDefaultValue(CodeTypeDeclaration typeDecl) { if (this.fixedDefaultValue != null) { CodeMemberField fixedOrDefaultField = null; CodeTypeReference returnType = this.ReturnType; if (this.unionDefaultType != null) { returnType = new CodeTypeReference(this.unionDefaultType.ToString()); } fixedOrDefaultField = (this.FixedValue == null ? new CodeMemberField(returnType, NameGenerator.ChangeClrName(base.PropertyName, NameOptions.MakeDefaultValueField)) : new CodeMemberField(returnType, NameGenerator.ChangeClrName(base.PropertyName, NameOptions.MakeFixedValueField))); CodeDomHelper.AddBrowseNever(fixedOrDefaultField); fixedOrDefaultField.Attributes = fixedOrDefaultField.Attributes & (MemberAttributes.Abstract | MemberAttributes.Final | MemberAttributes.Static | MemberAttributes.Override | MemberAttributes.Const | MemberAttributes.New | MemberAttributes.Overloaded | MemberAttributes.ScopeMask | MemberAttributes.VTableMask) & (MemberAttributes.New | MemberAttributes.Overloaded | MemberAttributes.Assembly | MemberAttributes.FamilyAndAssembly | MemberAttributes.Family | MemberAttributes.FamilyOrAssembly | MemberAttributes.Private | MemberAttributes.Public | MemberAttributes.AccessMask | MemberAttributes.VTableMask) | MemberAttributes.Private | MemberAttributes.Static; fixedOrDefaultField.InitExpression = SimpleTypeCodeDomHelper.CreateFixedDefaultValueExpression(returnType, this.fixedDefaultValue); typeDecl.Members.Add(fixedOrDefaultField); } }
private CodeStatement CreateDefaultValueAssignStmt(object value) { CodeStatement codeAssignStatement = new CodeAssignStatement(CodeDomHelper.CreateFieldReference(null, this.propertyName), CodeDomHelper.CreateFieldReference(null, NameGenerator.ChangeClrName(this.propertyName, NameOptions.MakeDefaultValueField))); return(codeAssignStatement); }
internal override void AddToConstructor(CodeConstructor functionalConstructor) { if (!this.IsList) { functionalConstructor.Parameters.Add(new CodeParameterDeclarationExpression(this.ReturnType, this.propertyName)); if (!this.FromBaseType) { functionalConstructor.Statements.Add(new CodeAssignStatement(CodeDomHelper.CreateFieldReference("this", this.propertyName), new CodeVariableReferenceExpression(this.propertyName))); } else { functionalConstructor.BaseConstructorArgs.Add(new CodeVariableReferenceExpression(this.propertyName)); } } else { CodeParameterDeclarationExpressionCollection parameters = functionalConstructor.Parameters; CodeTypeReference[] codeTypeReference = new CodeTypeReference[] { new CodeTypeReference(this.clrTypeName) }; parameters.Add(new CodeParameterDeclarationExpression(new CodeTypeReference("IEnumerable", codeTypeReference), this.propertyName)); if (!this.FromBaseType) { CodeTypeReference listType = this.GetListType(); functionalConstructor.Statements.Add(new CodeAssignStatement(CodeDomHelper.CreateFieldReference("this", NameGenerator.ChangeClrName(this.propertyName, NameOptions.MakeField)), new CodeMethodInvokeExpression(new CodeTypeReferenceExpression(listType), "Initialize", this.GetListParameters(true, true)))); } else { functionalConstructor.BaseConstructorArgs.Add(new CodeVariableReferenceExpression(this.propertyName)); } } }
private void AddListGetStatements(CodeStatementCollection getStatements, CodeTypeReference listType, string listName) { if (this.FixedValue == null) { CodeBinaryOperatorExpression codeBinaryOperatorExpression = new CodeBinaryOperatorExpression(new CodeFieldReferenceExpression(new CodeThisReferenceExpression(), listName), CodeBinaryOperatorType.IdentityEquality, new CodePrimitiveExpression(null)); CodeStatement[] codeAssignStatement = new CodeStatement[] { new CodeAssignStatement(new CodeFieldReferenceExpression(new CodeThisReferenceExpression(), listName), new CodeObjectCreateExpression(listType, this.GetListParameters(false, false))) }; getStatements.Add(new CodeConditionStatement(codeBinaryOperatorExpression, codeAssignStatement)); getStatements.Add(new CodeMethodReturnStatement(new CodeFieldReferenceExpression(new CodeThisReferenceExpression(), listName))); } else { getStatements.Add(new CodeMethodReturnStatement(new CodeFieldReferenceExpression(null, NameGenerator.ChangeClrName(this.propertyName, NameOptions.MakeFixedValueField)))); } }
private void AddGetStatements(CodeStatementCollection getStatements) { CodeExpression[] simpleTypeClassExpression; if (!this.IsSubstitutionHead) { CodeExpression returnExp = null; if (this.FixedValue == null) { getStatements.Add(this.GetValueMethodCall()); this.CheckOccurrence(getStatements); CodeVariableReferenceExpression returnValueExp = new CodeVariableReferenceExpression("x"); if ((this.IsRef ? true : !this.typeRef.IsSimpleType)) { returnExp = new CodeCastExpression(this.ReturnType, returnValueExp); } else { CodeTypeReference parseType = this.ReturnType; if ((!this.typeRef.IsValueType ? false : this.IsNullable)) { parseType = new CodeTypeReference(this.clrTypeName); } if (!this.IsUnion) { string parseMethodName = null; CodeExpression simpleTypeExpression = this.GetSchemaDatatypeExpression(); if (!this.IsSchemaList) { parseMethodName = "ParseValue"; } else { parseMethodName = "ParseListValue"; parseType = new CodeTypeReference(this.clrTypeName); } CodeTypeReferenceExpression codeTypeReferenceExpression = CodeDomHelper.CreateTypeReferenceExp("XTypedServices"); simpleTypeClassExpression = new CodeExpression[] { returnValueExp, simpleTypeExpression }; returnExp = CodeDomHelper.CreateGenericMethodCall(codeTypeReferenceExpression, parseMethodName, parseType, simpleTypeClassExpression); if (this.DefaultValue != null) { ((CodeMethodInvokeExpression)returnExp).Parameters.Add(new CodeFieldReferenceExpression(null, NameGenerator.ChangeClrName(this.propertyName, NameOptions.MakeDefaultValueField))); } } else { CodeTypeReferenceExpression codeTypeReferenceExpression1 = CodeDomHelper.CreateTypeReferenceExp("XTypedServices"); simpleTypeClassExpression = new CodeExpression[] { returnValueExp, this.GetSimpleTypeClassExpression() }; returnExp = CodeDomHelper.CreateMethodCall(codeTypeReferenceExpression1, "ParseUnionValue", simpleTypeClassExpression); } } getStatements.Add(new CodeMethodReturnStatement(returnExp)); } else { getStatements.Add(new CodeMethodReturnStatement(new CodeFieldReferenceExpression(null, NameGenerator.ChangeClrName(this.propertyName, NameOptions.MakeFixedValueField)))); } } else { this.AddSubstGetStatements(getStatements); } }
protected void AddFixedValueChecking(CodeStatementCollection setStatements) { if (this.FixedValue != null) { CodeExpression fixedValueExpr = new CodeFieldReferenceExpression(null, NameGenerator.ChangeClrName(this.propertyName, NameOptions.MakeFixedValueField)); CodePropertySetValueReferenceExpression codePropertySetValueReferenceExpression = new CodePropertySetValueReferenceExpression(); CodeExpression[] codeExpressionArray = new CodeExpression[] { fixedValueExpr }; CodeMethodInvokeExpression codeMethodInvokeExpression = CodeDomHelper.CreateMethodCall(codePropertySetValueReferenceExpression, "Equals", codeExpressionArray); CodeStatement[] codeStatementArray = new CodeStatement[0]; CodeStatement[] codeThrowExceptionStatement = new CodeStatement[1]; Type type = typeof(LinqToXsdFixedValueException); codeExpressionArray = new CodeExpression[] { new CodePropertySetValueReferenceExpression(), fixedValueExpr }; codeThrowExceptionStatement[0] = new CodeThrowExceptionStatement(new CodeObjectCreateExpression(type, codeExpressionArray)); setStatements.Add(new CodeConditionStatement(codeMethodInvokeExpression, codeStatementArray, codeThrowExceptionStatement)); } }