Is TypeConverter a safe frame type?

Is it wise?

class MyTypeConverter : TypeConverter { // implementation } // elsewhere TypeDescriptor.AddAttributes(typeof(string[]), new[] { new TypeConverterAttribute(typeof(MyTypeConverter)) }); 

Note. I put this in string[] .

It seems to me that it's dirty.

+4
source share
2 answers

Safe? Yes, it is used by the Windows Forms Designer to add attributes, so it is a valid part of the functionality, although it is not used to a large extent.

Dirty? Yes a little. If there is any other way of cat skin, I would look at it like that. Attributes are for simple metadata used to provide a clean way to indicate specific characteristics of your code. Using dynamic attributes, you seem to get out of the normal use case.

+1
source

If you need to do this, you need to do this. Make sure you really don't only need the readonly property in the containing class.

However, I would suggest using typeof (IEnumerable) so that you can also collect lists, collections, etc.

0
source

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


All Articles