Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to auto-generate early bound Enum properties for Entity attributes that are normally Option Sets?

Generating early bound entity classes for CRM Entities is fairly simple. Generating the Enums for the OptionSets is fairly simple as well. Generating the OptionSet Enum properties for entities that are typed to the correct Enum is not so simple, and not currently supported by the CrmSrvUtil.exe. If you want to be able to use the enums for populating the option set values, you have to continually write code that looks like this:

contact.Address1_AddressTypeCode = new OptionSetValue((int)contact_address1_addresstypecode.Home);

How do I generate Enum specific properties for OptionSetValues, so I can write code like this:

contact.Address1_AddressTypeCode = contact_address1_addresstypecode.Home;

and so Address1_AddressTypeCode's type is contact_address1_addresstypecode?

like image 914
Daryl Avatar asked Apr 18 '13 19:04

Daryl


1 Answers

I've created an Entity OptionSet Enum Mapper Utility to auto-generate Enum specific typed properties for early-bound entities. You can download both the source and executables here:

Programmatically Generating Properties for OptionSet Enums

It basically runs as part of a pre-build event during the build of your standard option set / enum dll, generating a .cs file that contains partial classes for any class that needs to have Enum properties generated for it.

like image 191
Daryl Avatar answered Oct 20 '22 15:10

Daryl