thomasgalliker / ValueConverters.NET

A collection of commonly used IValueConverters for .NET applications

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Add ValueConversionAttribute

sa-he opened this issue · comments

commented

Is it possible to add the ValueConversionAttribute to the converters? AFAIK it is only available in net full framework and netcore so compiler-ifs would be required.

I could send a pull request if you agree.

https://docs.microsoft.com/en-us/dotnet/api/system.windows.data.valueconversionattribute?view=netframework-4.8

Ok. Can you maybe prepare a minimal PR so I can see how you’d add it - and how you’d use it? Is there a concrete use-case for these annotations? You cannot add it to generic classes, right?

commented

No, generic types cannot be used in attributes. This is why I suggest to add the attribute to all child classes instead of base classes.

Use-case?
A. It helps consumers of the lib to understand the input and outcome of the converter.
B. We have developed the idea of cascading converters (#12) in a less intrusive way. Meaning that existing converters do not need to have a reference to a 'PreviousConverter'. This implementation relies on the ValueConversionAttribute and is used like this:

<conv:ValueConverterGroup x:Key="Int32ToInvertedVisibility"> <!-- Add any IValueConverter that is decorated with ValueConvertionAttribute --> <conv:Int32ToBoolean /> <conv:BoolInverter /> <conv:BooleanToVisibility /> </conv:ValueConverterGroup>

I would provide a PR if you are intrested. Otherwise adding the ValueConvertionAttribute to your converters allows us to place them inside our ValueConverterGroup.