I was wondering if it would be possible to use a custom attribute in C# on a property that has some items.
For instance, I have a List with a default initialization of some items of type T and I want to check through an attribute if List has only unique items. I know that a List can have multiple similar objects in it, therefore you should use a HashSet to make sure only unique items exist. However, I can still declare some duplicate items in this HashSet at compile time and I would not receive any errors... (I want to receive errors before I run the program) So I was wondering if I could use something like:
[HasUniqueItemsAttribute]
public IList<string> MyCollection { get; set; } = new List<string>()
{
"example 1",
"example 2",
"example 1"
};
Then I would receive an error on MyCollection that indicates that this default initialized collection does not contain unqiue items... Does anyone know how to do this?
List<T>, tryHashSet<T>instead.