/// <summary> /// Declare a new enum type in the current scope based on an actual enum. /// </summary> /// <remarks> /// Used to declare predefined enum types representing existing enums in metamodel. /// </remarks> /// <param name="type">The enum type.</param> private void Process_ModelEnum(System.Type type) { if (NameContext.Current.Scope.Model.Instances.OfType<Type>().Count(t => t.UnderlyingType == type) == 0) { EnumType enumType = new EnumType(); // Namespace enumType.Namespace = (Namespace)NameContext.Current.Scope; // Name enumType.Name = AttributeHelpers.GetTypeName(type); // Underlying type enumType.UnderlyingType = type; // Hidden enumType.AddMetaInfo(new HiddenInfo()); // Enter scope using (new NameContextScope(enumType)) { // Values foreach (FieldInfo field in type.GetFields(BindingFlags.Static | BindingFlags.Public)) { EnumValue enumValue = new EnumValue(); enumValue.Name = AttributeHelpers.GetMemberName(field); enumValue.Enum = enumType; // Hidden enumValue.AddMetaInfo(new HiddenInfo()); } } } }
/// <summary> /// Processes enum node. /// </summary> /// <param name="node">The node.</param> private void Process_EnumType(dynamic node) { EnumType enumType = new EnumType(); // Map source location and node to object enumType.AddMetaInfo(new SourceLocationInfo(node, context)); context.AddObject(node, enumType); // Namespace (from parent) try { NameContext.Current.CheckName(node.Name, typeof(EnumType), typeof(StructType), typeof(ExceptionType), typeof(ClaimsetType)); enumType.Namespace = (Namespace)NameContext.Current.Scope; } catch (NameCollisionException exception) { Error_NameExists(enumType, exception); } // Name (obligatory) enumType.Name = node.Name; // Values are not processed yet }