Beispiel #1
0
        /// <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());
                    }
                }
            }
        }
Beispiel #2
0
        /// <summary>
        /// Processes enum value node.
        /// </summary>
        /// <param name="node">The node.</param>
        private void Process_EnumValue(dynamic node)
        {
            EnumValue enumValue = new EnumValue();

            // Map source location and node to object
            enumValue.AddMetaInfo(new SourceLocationInfo(node, context));
            context.AddObject(node, enumValue);

            // Enum
            try
            {
                NameContext.Current.CheckName(node.Name, typeof(EnumValue));
                enumValue.Enum = (EnumType)NameContext.Current.Scope;
            }
            catch (NameCollisionException exception)
            {
                Error_NameExists(enumValue, exception);
            }

            // Name
            enumValue.Name = node.Name;
        }