Friday, October 15, 2010

Useful Things to Know, #426

You can add an extension  method to an enumerated type.

You can.  The code looks like that of any other extension method:

  public enum SalesCallObjective
    {
        NewCustomer = 1,
        RetainCustomer = 2,
        KeepInTouch = 3
    }
    public static class SalesCallObjectiveExtensions
    {
        public static ProductCategory ToProductCategory(this SalesCallObjective value)
        {
            switch (value)
            {
                case SalesCallObjective.NewCustomer:
                    return ProductCategory.CompetitiveProduct;
                case SalesCallObjective.RetainCustomer:
                    return ProductCategory.UpgradeProduct;
                case SalesCallObjective.KeepInTouch:
                    return ProductCategory.PromotionalProduct;
                default:
                    return ProductCategory.Unknown;
            }
        }
    }


The above is just an example of what you can do, not a real-life attempt to solve a business problem.  But it does show one potential use:  mapping an enum from one domain (sales call objective) to another. 

0 Comments:

Post a Comment

<< Home