I\'m trying to create classes to encapsulate validation and logic for objects like Email , URL , phone number and so on . in the first try I found that I\'m repeating the sa
so , how can I have access to PropOne and PropTwo in this static method ?
You need to have an instance somehow, otherwise it's a meaningless operation. So the question is - how would you want to identify the instance that you're interested in? Do you really need Validate
to be static at all?
Note that instead of having abstract properties, if you expect the values to always stay the same throughout an instance of the class, you might want to make the values part of the constructor for BaseClass
instead, and just keep them in fields.
If what you're trying to achieve is that each subclass has a single separate validator, I would separate the two concerns - give each subclass a static property of a different type. You wouldn't be able to call this polymorphically, but it sounds like you don't really want to anyway.
We can't really tell what your classes are meant to represent here - if you can give us more concrete context, we can probably be more helpful.
you can try making IsValid
an extension method.