CustomEnum.vb 1.0.3

There is a newer version of this package available.
See the version list below for details.
dotnet add package CustomEnum.vb --version 1.0.3                
NuGet\Install-Package CustomEnum.vb -Version 1.0.3                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="CustomEnum.vb" Version="1.0.3" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add CustomEnum.vb --version 1.0.3                
#r "nuget: CustomEnum.vb, 1.0.3"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install CustomEnum.vb as a Cake Addin
#addin nuget:?package=CustomEnum.vb&version=1.0.3

// Install CustomEnum.vb as a Cake Tool
#tool nuget:?package=CustomEnum.vb&version=1.0.3                

Did you ever got frustrated about the limitations of Enums? Ever needed an Enum that supports Strings? Or your custom type?

Did you ever wonder why you can't add any instance methods and properties to an Enum?

Do you like to be able to enumerate over all members, ask their names, values and index? Or just call one of your custom method on the instances (strongly typed and real instance methods, not extenstion methods)?

Did you ever wonder why you need to specify a value when the enum itself would satisfy your needs? Got annoyed to always have to include that "None"-member?

If you answer some of this questions with yes, CustomEnum.vb is definitely something for you, except, of course, if you are a religious C# believer then you need to wait a little bit for the C# version. I have the intension to provide it somewhen soon but I have the feeling it is not done by simply pushing it through the converter.

Although this is version 1.0, CustomEnum.vb is a carefully written, highly optimized, with a high code coverage tested and well documented source file written in VB.NET that provides 2 base classes called "CustomEnum" and "ValueEnum" with generic type parameters that allow you to build your own Enums according your individual needs.

The first generic type parameter is always the type of your Enum (the subclass), the optional last one the type of the combination (Enum.Combi), and the second one (ValueEnum only) is the type of the value.

Here an example:

Public Class ShirtSize
   Inherits CustomEnum(Of ShirtSize)

   'Constructors

   Private Sub New()
       MyBase.New()
   End Sub

   'Public Fields

   Public Shared ReadOnly S As New ShirtSize()
   Public Shared ReadOnly M As New ShirtSize()
   Public Shared ReadOnly L As New ShirtSize()
   Public Shared ReadOnly XL As New ShirtSize()

End Class

The usage is the same as with standard Enums:

Dim myShirt As Object = GetShirt(ShirtSize.XL)

   Private Function GetShirt(size As ShirtSize) As Object
       '...
   End Function

Note that Enums are now reference types and may be null. Although this forces you to always check for null you never have to include that "None" member in your Enum anymore...

If you like to work with "Select Case" that's still possible, you just have to append the ".Index" to the member, eg. ShirtSize.XL.Index.

But CustomEnum also provides equals/inequals operators, you can use them like this "If (size = ShirtSize.XL) Then ..."

Did I already mention that CustomEnum fully supports member combinations like with the FlagsAttribute? They are implemented as an inner class called "Combi" and there are functions and operators to construct them:

SetHighSeasons(Season.Spring Or Season.Summer Or Season.Autumn)

And the method looks like this:

   Private Sub SetHighSeasons(seasons As Season.Combi)
       For Each mySeason As Season In seasons
           'do something
       Next
   End Sub

There is many more to it:

- CustomEnum is thread-safe.
- CustomEnum checks and enforces correct implementation.
- CustomEnum has lots of attributes applied to simplify editing, debugging and code-analysis.
- CustomEnum allows to have subclasses for common functionality (although you cannot inherit members).
- CustomEnum runs in partially trusted code as well as in full trust
- CustomEnum does not make use of LINQ nor extension methods and is pure .NET 2.0.
- CustomEnum has no dependencies to other packages.
- CustomEnum only references mscorlib.dll and System.dll.
- CustomEnum ships as one single source file (and an additional tutorial folder that can easily be deleted).
- CustomEnum is free of charge.

Thank you for your interest in this package, feed-back is welcome, our email naming convention is
<given name>.<surname>@<company>.ch

Best regards
Chris

There are no supported framework assets in this package.

Learn more about Target Frameworks and .NET Standard.

  • .NETFramework 2.0

    • No dependencies.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.0.4 6,992 9/16/2013
1.0.3 6,198 6/19/2013
1.0.2 6,157 6/19/2013
1.0.0 6,408 4/30/2013

Changes in 1.0.3:
Check for private constructors relaxed to allow "Protected" and "Protected-and-Friend" (does not exist in VB) constructors as well if the class is declared abstract. Function AddFields/AddGetters adjusted to allow subclasses of TEnum. Example added to folder "04 Inheritance" to show new functionality.