Sharing generic code between UWP projects

63 views Asked by At

I'm developing an UWP app via C#, that uses IBasicVideoEffect with IDirect3DSurface. As mentioned in documentation, I have created Windows Runtime Component (Universal Windows) project.

But settings of effects are stored in some implementation of IPropertySet (smth like Dictionary<object, object>).

To use high - level operations on this storage, I've introduced IPropertySetExtensions into runtime component, that has for example Get<T>, GetOrDefault<T> methods, which return instance of T (not object) from storage.

Than I realized, that same operations will be needed in main project, but when I changed

internal static class IPropertySetExtensions into public one, I got an error like "winmd components cant contain generic methods". That's why I duplicated extension class into main project.

How can I avoid this duplicating? Maybe move shared code into NuGet .dll or smth?

1

There are 1 answers

0
marcelwgn On

Unfortunately, when writing a WinRT Component there are quite a few limitations due to the fact that WinRT Components are usable in C++, C#, VB and JS (yes also JS). The following document covers part of what to watch out for: https://learn.microsoft.com/en-us/windows/uwp/winrt-components/creating-windows-runtime-components-in-csharp-and-visual-basic

In your case, I think creating a "Class Library (Universal Windows)" will solve that problem since you can write C# code as you like without having to watch out for WinRT Component limitations.