diff --git a/src/System.Drawing.Common/src/CompatibilitySuppressions.xml b/src/System.Drawing.Common/src/CompatibilitySuppressions.xml index f05c3bdda4e..87049cd61f1 100644 --- a/src/System.Drawing.Common/src/CompatibilitySuppressions.xml +++ b/src/System.Drawing.Common/src/CompatibilitySuppressions.xml @@ -25,6 +25,32 @@ lib/netstandard2.0/System.Drawing.Common.dll lib/net462/System.Drawing.Common.dll + + CP0015 + P:System.Drawing.Image.Height:[T:System.ComponentModel.DefaultValueAttribute] + lib/net10.0/System.Drawing.Common.dll + lib/net10.0/System.Drawing.Common.dll + true + + + CP0015 + P:System.Drawing.Image.Width:[T:System.ComponentModel.DefaultValueAttribute] + lib/net10.0/System.Drawing.Common.dll + lib/net10.0/System.Drawing.Common.dll + true + + + CP0015 + P:System.Drawing.Image.Height:[T:System.ComponentModel.DefaultValueAttribute] + lib/netstandard2.0/System.Drawing.Common.dll + lib/net10.0/System.Drawing.Common.dll + + + CP0015 + P:System.Drawing.Image.Width:[T:System.ComponentModel.DefaultValueAttribute] + lib/netstandard2.0/System.Drawing.Common.dll + lib/net10.0/System.Drawing.Common.dll + CP0015 P:System.Drawing.Font.Name:[T:System.ComponentModel.EditorAttribute] @@ -67,4 +93,4 @@ lib/netstandard2.0/System.Drawing.Common.dll lib/net462/System.Drawing.Common.dll - \ No newline at end of file + diff --git a/src/System.Drawing.Common/src/System/Drawing/Image.cs b/src/System.Drawing.Common/src/System/Drawing/Image.cs index b9c855e7d04..79c89e25fcd 100644 --- a/src/System.Drawing.Common/src/System/Drawing/Image.cs +++ b/src/System.Drawing.Common/src/System/Drawing/Image.cs @@ -423,7 +423,7 @@ public SizeF PhysicalDimension /// /// Gets the width of this . /// - [DefaultValue(false)] + [DefaultValue(0)] [Browsable(false)] [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] public int Width @@ -440,7 +440,7 @@ public int Width /// /// Gets the height of this . /// - [DefaultValue(false)] + [DefaultValue(0)] [Browsable(false)] [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] public int Height diff --git a/src/System.Drawing.Common/tests/System/Drawing/ImageTests.cs b/src/System.Drawing.Common/tests/System/Drawing/ImageTests.cs index 16e0bd70193..c385d723eb8 100644 --- a/src/System.Drawing.Common/tests/System/Drawing/ImageTests.cs +++ b/src/System.Drawing.Common/tests/System/Drawing/ImageTests.cs @@ -1,6 +1,7 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. +using System.ComponentModel; using System.Drawing.Imaging; using System.Runtime.InteropServices; using System.Text; @@ -19,6 +20,19 @@ public class ImageTests private const int PropertyTagTypeASCII = 2; private const int PropertyTagTypeShort = 3; + [Theory] + [InlineData(nameof(Image.Width))] + [InlineData(nameof(Image.Height))] + public void ImageDimensionProperty_DefaultValueIsZero(string propertyName) + { + PropertyDescriptor? property = TypeDescriptor.GetProperties(typeof(Image))[propertyName]; + Assert.NotNull(property); + + DefaultValueAttribute defaultValue = Assert.IsType( + property.Attributes[typeof(DefaultValueAttribute)]); + Assert.Equal(0, defaultValue.Value); + } + [Fact] public void PropertyIdList_GetBitmapJpg_Success() {