A constraint that forces a generic parameter from a string

In this topic, you can find a solution for creating a universal class that provides parsing from string to typical parameter type. However, it may happen that the type specified by this parameter does not provide such a conversion. Is there any way to make this a guarantee?

UPDATE: Thanks for the answer. However, I know that I can generally make restrictions. The problem is whether there is any interface that implements all types that Convert.ChangeType will not work for. Or, which is implemented by all types using the Parse (string) method.

+3
source share
2 answers

, , , , , . , , (int, char, string ..), , IConvertible . .

+3

Type Constraints, , . , , .

+2

Source: https://habr.com/ru/post/1788824/


All Articles