Skip to content

Commit 06a6ea7

Browse files
authored
Fix LocalizableString to work with internal ResourceType (#111130)
* Fix LocalizableString to work with internal ResourceType Removed check for Resource Type to be public. Added test for DisplayAttribute to ensure it works with with internal Resource Type. * remove the line numbers from the DisplayAttributeTests.cs file
1 parent ec281ad commit 06a6ea7

File tree

2 files changed

+17
-3
lines changed

2 files changed

+17
-3
lines changed

src/libraries/System.ComponentModel.Annotations/src/System/ComponentModel/DataAnnotations/LocalizableString.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -128,9 +128,8 @@ private void ClearCache()
128128
// We need to detect bad configurations so that we can throw exceptions accordingly
129129
var badlyConfigured = false;
130130

131-
// Make sure we found the property and it's the correct type, and that the type itself is public
132-
if (!_resourceType.IsVisible || property == null ||
133-
property.PropertyType != typeof(string))
131+
// Make sure we found the property and it's the correct type
132+
if (property == null || property.PropertyType != typeof(string))
134133
{
135134
badlyConfigured = true;
136135
}

src/libraries/System.ComponentModel.Annotations/tests/System/ComponentModel/DataAnnotations/DisplayAttributeTests.cs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,5 +191,20 @@ public void Order_Get_Set(int value)
191191
Assert.Equal(value, attribute.Order);
192192
Assert.Equal(value, attribute.GetOrder());
193193
}
194+
195+
[Fact]
196+
public void LocalizableString_WorksWithInternalResourceType()
197+
{
198+
DisplayAttribute attribute = new DisplayAttribute();
199+
attribute.ResourceType = typeof(InternalResourceType);
200+
attribute.Name = nameof(InternalResourceType.PublicProperty);
201+
202+
Assert.Equal(InternalResourceType.PublicProperty, attribute.GetName());
203+
}
204+
205+
internal class InternalResourceType
206+
{
207+
public static string PublicProperty => "Internal Resource with Public Property";
208+
}
194209
}
195210
}

0 commit comments

Comments
 (0)