/// <summary> /// Creates an EnumDataType from a C# enumeration. /// </summary> /// <param name="enumeration">The enumeration.</param> /// <returns>The created EnumDataType</returns> public static XerusEnumType CreateFromEnum(Type enumeration) { if (!enumeration.IsEnum) { throw new ArgumentException("Given parameter is not an enum"); } var enumDataType = new XerusEnumType(enumeration.Name, enumeration.GetDocumentation()); foreach (var value in Enum.GetValues(enumeration)) { var memberInfos = enumeration.GetMember(value.ToString()).FirstOrDefault(); var customAttributes = value.GetType().GetCustomAttributes(); var definedValue = (int)value; string documentation = memberInfos.GetDocumentation(); XerusEnumMemberType xerusEnumMemberType = new XerusEnumMemberType(value.ToString()).WithDefinedValue(definedValue).WithDescription(documentation); enumDataType.Members.Add(xerusEnumMemberType); } return(enumDataType); }
/// <summary> /// Adds an member to the enumeration /// </summary> /// <param name="member"> /// The member /// </param> /// <returns> /// The enumeration /// </returns> public XerusEnumType AddMember(XerusEnumMemberType member) { this.Members.Add(member); return(this); }