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
c # data-annotations


source to share


No one has answered this question yet

Check out similar questions:

1743
What's the best way to give a C # auto property an initial value?
1270
Why not inherit from List <T>?
982
LINQ Distinct () for a specific property
756
Failed to check for one or more objects. For more information, see "EntityValidationErrors Property".
34
Why can't my public class extend the inner class?
31
How do I make internal interfaces visible to Moq?
five
Server side validation using custom DataAnnotationsModelValidatorProvider
2
Validator.TryValidateObject does not validate attribute
2
MVC2: Using DataAnnotations to Check DataType
1
Soft Validation Using Derived Classes and Data



All Articles
Loading...
X
Show
Funny
Dev
Pics