Code Snippet
- using System;
- using System.Collections.Generic;
- namespace GuiLib.TeraRegion
- {
- public class TeraRegionModel
- {
- /// <summary>
- /// Dynamic enum of RegionTypes.
- /// <remarks>* This is a [Flags] and normal mixed enum!
- /// * 0 is reserved! it's not used!
- /// * 1 is reserved! it's void.
- /// Find it's max and assigne it's next value like this:
- /// var next_enum_val = RegionTypes.Values.Max<ulong>();
- /// RegionTypes.Add("new_item", next_enum_val*2);
- /// </remarks>
- /// </summary>
- public static Dictionary<string, ulong> RegionTypes = new Dictionary<string, ulong>()
- {
- {"void", 1}
- };
- #region RegionType
- /// <summary>
- /// Occurs when RegionType changes.
- /// </summary>
- public event EventHandler RegionTypeChanged;
- /// <summary>
- /// Raises the <see cref="E:RegionTypeChanged"/> event.
- /// </summary>
- /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
- protected virtual void OnRegionTypeChanged(EventArgs e)
- {
- if (RegionTypeChanged != null)
- RegionTypeChanged(this, e);
- }
- private ulong _RegionType = 1;
- /// <summary>
- /// Gets or sets the type of the region.
- /// </summary>
- /// <value>
- /// The type of the region.
- /// </value>
- public ulong RegionType
- {
- get
- {
- return _RegionType;
- }
- set
- {
- if (_RegionType != value)
- {
- _RegionType = value;
- OnRegionTypeChanged(new EventArgs());
- }
- }
- }
- #endregion
- }
- }
Original post:
ReplyDeletehttp://shloemi.blogspot.com/2011/11/tip-c-dynamic-enum-like-solution.html