Enumerating pre-install packages

broken image

String derivedEnumTypeName = typeof(DerivedEnum).Name Public static BaseEnum ToBaseEnum( this DerivedEnum derivedEnum)

broken image

The project contains BaseEnum enumeration:Ĭopy Code public static class DeriveEnumExtensions It contains a non-generated code large parts of which we later show can be generated. Take a look at EnumDerivationSample project. I am using the Visual Studio 2017 and the resulting VSIX file should only work in Visual Studio 2017. Here I attempt to resolve this problem using Roslyn based VS extension for generating single files, similar to the approach to simulating multiple inheritance in Implementing Adapter Pattern and Imitating Multiple Inheritance in C# using Roslyn based VS Extension Wrapper Generator and the subsequent articles. NET and Language Limitations (see section 2.5 Mocking Programming by Extension). The most usual case is when I need to use an enumeration from a dll library that I cannot modify in my code while at the same time, I also need to use some extra enumeration values that the library does not contain.Ī similar idea is presented by Sergey Kryukov in Enumeration Types do not Enumerate! Working around.

broken image

In my C# programming experience, I came across many cases where extending a plain simple Enumeration would be of benefit.

broken image

I would really appreciate if you leave me comments stating how you think this article can be improved.