private static void DropDefaultAttribute(Accessor accessor, CodeCommentStatementCollection comments, string type) { if (!accessor.IsFixed && accessor.IsOptional) { CodeExporter.AddWarningComment(comments, Res.GetString("XmlDropDefaultAttribute", new object[] { type })); } }
private void AddDefaultValueAttribute(CodeMemberField field, CodeAttributeDeclarationCollection metadata, object defaultValue, TypeMapping mapping, CodeCommentStatementCollection comments, TypeDesc memberTypeDesc, Accessor accessor, CodeConstructor ctor) { string str = accessor.IsFixed ? "fixed" : "default"; if (!memberTypeDesc.HasDefaultSupport) { if ((comments != null) && (defaultValue is string)) { DropDefaultAttribute(accessor, comments, memberTypeDesc.FullName); CodeExporter.AddWarningComment(comments, Res.GetString("XmlDropAttributeValue", new object[] { str, mapping.TypeName, defaultValue.ToString() })); } } else if (memberTypeDesc.IsArrayLike && (accessor is ElementAccessor)) { if ((comments != null) && (defaultValue is string)) { DropDefaultAttribute(accessor, comments, memberTypeDesc.FullName); CodeExporter.AddWarningComment(comments, Res.GetString("XmlDropArrayAttributeValue", new object[] { str, defaultValue.ToString(), ((ElementAccessor)accessor).Name })); } } else if ((mapping.TypeDesc.IsMappedType && (field != null)) && (defaultValue is string)) { SchemaImporterExtension extension = mapping.TypeDesc.ExtendedType.Extension; CodeExpression init = extension.ImportDefaultValue((string)defaultValue, mapping.TypeDesc.FullName); if (init != null) { if (ctor != null) { AddInitializationStatement(ctor, field, init); } else { field.InitExpression = extension.ImportDefaultValue((string)defaultValue, mapping.TypeDesc.FullName); } } if (comments != null) { DropDefaultAttribute(accessor, comments, mapping.TypeDesc.FullName); if (init == null) { CodeExporter.AddWarningComment(comments, Res.GetString("XmlNotKnownDefaultValue", new object[] { extension.GetType().FullName, str, (string)defaultValue, mapping.TypeName, mapping.Namespace })); } } } else { object obj2 = null; if ((defaultValue is string) || (defaultValue == null)) { obj2 = this.ImportDefault(mapping, (string)defaultValue); } if (obj2 != null) { if (!(mapping is PrimitiveMapping)) { DropDefaultAttribute(accessor, comments, memberTypeDesc.FullName); CodeExporter.AddWarningComment(comments, Res.GetString("XmlDropNonPrimitiveAttributeValue", new object[] { str, defaultValue.ToString() })); } else { PrimitiveMapping mapping2 = (PrimitiveMapping)mapping; if (((comments != null) && !mapping2.TypeDesc.HasDefaultSupport) && mapping2.TypeDesc.IsMappedType) { DropDefaultAttribute(accessor, comments, mapping2.TypeDesc.FullName); } else if (obj2 == DBNull.Value) { if (comments != null) { CodeExporter.AddWarningComment(comments, Res.GetString("XmlDropAttributeValue", new object[] { str, mapping2.TypeName, defaultValue.ToString() })); } } else { CodeAttributeArgument[] arguments = null; CodeExpression initExpression = null; if (mapping2.IsList) { object[] objArray = (object[])obj2; CodeExpression[] initializers = new CodeExpression[objArray.Length]; for (int i = 0; i < objArray.Length; i++) { this.GetDefaultValueArguments(mapping2, objArray[i], out initializers[i]); } initExpression = new CodeArrayCreateExpression(field.Type, initializers); } else { arguments = this.GetDefaultValueArguments(mapping2, obj2, out initExpression); } if (field != null) { if (ctor != null) { AddInitializationStatement(ctor, field, initExpression); } else { field.InitExpression = initExpression; } } if (((arguments != null) && mapping2.TypeDesc.HasDefaultSupport) && (accessor.IsOptional && !accessor.IsFixed)) { CodeAttributeDeclaration declaration = new CodeAttributeDeclaration(typeof(DefaultValueAttribute).FullName, arguments); metadata.Add(declaration); } else if (comments != null) { DropDefaultAttribute(accessor, comments, memberTypeDesc.FullName); } } } } } }