Add USE_REAL_RESOURCES to easily test if `[Display]` usability has improved
- `[Display]` works only with `public` resources (classes and properties) - also change `TestResources` to make `Resources` the single source of truth
This commit is contained in:
parent
7dd3afe3d1
commit
ec6f1907c5
|
|
@ -156,8 +156,13 @@ namespace Microsoft.AspNet.Mvc.ModelBinding.Metadata
|
||||||
|
|
||||||
var display = new DisplayAttribute()
|
var display = new DisplayAttribute()
|
||||||
{
|
{
|
||||||
Name = "DisplayAttribute_Name",
|
#if USE_REAL_RESOURCES
|
||||||
|
Name = nameof(Test.Resources.DisplayAttribute_Name),
|
||||||
|
ResourceType = typeof(Test.Resources),
|
||||||
|
#else
|
||||||
|
Name = nameof(Test.Resources.DisplayAttribute_Name),
|
||||||
ResourceType = typeof(Test.TestResources),
|
ResourceType = typeof(Test.TestResources),
|
||||||
|
#endif
|
||||||
};
|
};
|
||||||
|
|
||||||
var attributes = new Attribute[] { display };
|
var attributes = new Attribute[] { display };
|
||||||
|
|
@ -180,8 +185,13 @@ namespace Microsoft.AspNet.Mvc.ModelBinding.Metadata
|
||||||
|
|
||||||
var display = new DisplayAttribute()
|
var display = new DisplayAttribute()
|
||||||
{
|
{
|
||||||
Description = "DisplayAttribute_Description",
|
#if USE_REAL_RESOURCES
|
||||||
|
Description = nameof(Test.Resources.DisplayAttribute_Description),
|
||||||
|
ResourceType = typeof(Test.Resources),
|
||||||
|
#else
|
||||||
|
Description = nameof(Test.Resources.DisplayAttribute_Description),
|
||||||
ResourceType = typeof(Test.TestResources),
|
ResourceType = typeof(Test.TestResources),
|
||||||
|
#endif
|
||||||
};
|
};
|
||||||
|
|
||||||
var attributes = new Attribute[] { display };
|
var attributes = new Attribute[] { display };
|
||||||
|
|
@ -568,7 +578,11 @@ namespace Microsoft.AspNet.Mvc.ModelBinding.Metadata
|
||||||
[Display(Name = "menos uno")]
|
[Display(Name = "menos uno")]
|
||||||
MinusOne = -1,
|
MinusOne = -1,
|
||||||
|
|
||||||
|
#if USE_REAL_RESOURCES
|
||||||
|
[Display(Name = nameof(Test.Resources.DisplayAttribute_Name), ResourceType = typeof(Test.Resources))]
|
||||||
|
#else
|
||||||
[Display(Name = nameof(Test.TestResources.DisplayAttribute_Name), ResourceType = typeof(Test.TestResources))]
|
[Display(Name = nameof(Test.TestResources.DisplayAttribute_Name), ResourceType = typeof(Test.TestResources))]
|
||||||
|
#endif
|
||||||
MinusTwo = -2,
|
MinusTwo = -2,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -3,12 +3,12 @@
|
||||||
|
|
||||||
namespace Microsoft.AspNet.Mvc.ModelBinding.Test
|
namespace Microsoft.AspNet.Mvc.ModelBinding.Test
|
||||||
{
|
{
|
||||||
// This class is a 'fake' resources for testing DisplayAttribute. We can't use actual resources
|
// Wrap resources to make them available as public properties for [Display]. That attribute does not support
|
||||||
// because our generator makes it an internal class, which doesn't work with DisplayAttribute.
|
// internal properties.
|
||||||
public static class TestResources
|
public static class TestResources
|
||||||
{
|
{
|
||||||
public static string DisplayAttribute_Description { get; } = "description from resources";
|
public static string DisplayAttribute_Description { get; } = Resources.DisplayAttribute_Description;
|
||||||
|
|
||||||
public static string DisplayAttribute_Name { get; } = "name from resources";
|
public static string DisplayAttribute_Name { get; } = Resources.DisplayAttribute_Name;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Loading…
Reference in New Issue