Bitwise Enum problem in Custom Control
-
I have a web custom control with the following property:
private AvailablePages _LinksToDisplay = AvailablePages.Home; public AvailablePages LinksToDisplay { get{return this._LinksToDisplay;} set{this._LinksToDisplay = value;} }
AvailablePages is an enum with the flags attribute set:
[Flags()] public enum AvailablePages : int { Home = 1, AddNewCCRate = 2, AddNewCCRateValue = 4, AmendCCRateValue = 8, AddNewForecastRate = 16, AddNewForecastRateValue = 32, AmendForecastRateValue = 64, AddNewRate = 128, AddNewRateValue = 256, AmmendRateValue = 512 }
This works if only one enumeration is chosen through visual studio's web forms designer. Code is written to the control's tag on the .aspx page along the lines of:
LinksToDisplay="Home"
However, when multiple values are chosen, the designer writes something like:LinksToDisplay="Home,AmendCCRateValue"
and the page throws an "Object reference not set to an instance of an object" error before any code is run (EG can't get it to stop at a break point before it fails). The stack trace starts:[NullReferenceException: Object reference not set to an instance of an object.] System.Web.Compilation.CodeDomUtility.GenerateExpressionForValue(PropertyInfo propertyInfo, Object value, Type valueType)
I think this is a problem with the conversion from the comma seperated string to a bitwise enum, but have had no luck looking for a way around it. Any help will be much appreciated.