Adding DataAnnotation Check to Internal Property
Is it possible to check for an internal property that has a data annotation?
For example:
public class Customer
{
[Required, Range(1, int.MaxValue)]
internal int CustomerID { get; set; }
}
When checking use
Validator.TryValidateObject(customerInstance, new ValidationContext(customerInstance), null, true);
It doesn't check the internal field. I assume this is because the assembly " System.ComponentModel.DataAnnotations
" knows nothing about the internals of my assembly.
I tried to make the DataAnnotation assembly a "Friend" assembly with the following expression before the Customer class:
[assembly: InternalsVisibleTo("System.ComponentModel.DataAnnotations, PublicKey=0024000004.....")]
but it doesn't work.
The reason I am doing an internal customer CustomerID is because nothing outside of my assembly needs to know about it.
+3
Jack
source
to share
No one has answered this question yet
Check out similar questions:
1743
1270
982
756
34
31
five
2
2
1