/// <summary> /// Processes struct node. /// </summary> /// <param name="node">The node.</param> private void Process_StructType(dynamic node) { StructType structType = new StructType(); // Map source location and node to object structType.AddMetaInfo(new SourceLocationInfo(node, context)); context.AddObject(node, structType); // Namespace (from parent) try { NameContext.Current.CheckName(node.Name, typeof(EnumType), typeof(StructType), typeof(ExceptionType), typeof(ClaimsetType)); structType.Namespace = (Namespace)NameContext.Current.Scope; } catch (NameCollisionException exception) { Error_NameExists(structType, exception); } // Name (obligatory) structType.Name = node.Name; // Fields are not processed yet // SuperType is not processed yet }
/// <summary> /// Declare a new struct type in the current scope based on an actual class. /// </summary> /// <remarks> /// Used to declare predefined struct types representing existing classes in metamodel. /// </remarks> /// <param name="type">The class type.</param> private void Process_ModelStruct(System.Type type) { if (NameContext.Current.Scope.Model.Instances.OfType<Type>().Count(t => t.UnderlyingType == type) == 0) { StructType structType = new StructType(); // Namespace structType.Namespace = (Namespace)NameContext.Current.Scope; // Name structType.Name = AttributeHelpers.GetTypeName(type); // Underlying type structType.UnderlyingType = type; // Hidden structType.AddMetaInfo(new HiddenInfo()); // Enter scope using (new NameContextScope(structType)) { // Fields foreach (PropertyInfo property in type.GetProperties(BindingFlags.Instance | BindingFlags.Public)) { StructField structField = new StructField(); structField.Name = AttributeHelpers.GetMemberName(property); structField.Type = BuiltInType.GetBuiltInType(property.PropertyType); structField.Struct = structType; // Hidden structField.AddMetaInfo(new HiddenInfo()); } } } }