/// <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()); } } } }
/// <summary> /// Processes struct field node. /// </summary> /// <param name="node">The node.</param> private void Process_StructField(dynamic node) { StructField structField = new StructField(); // Map source location and node to object structField.AddMetaInfo(new SourceLocationInfo(node, context)); context.AddObject(node, structField); // Struct try { NameContext.Current.CheckName(node.Name, typeof(StructField)); structField.Struct = (StructType)NameContext.Current.Scope; } catch (NameCollisionException exception) { Error_NameExists(structField, exception); } // Name structField.Name = node.Name; // Type try { structField.Type = this.Process_TypeReference(node.Type); } catch (NameNotFoundException exception) { Error_NameNotFound(structField, exception); } catch (NameCollisionException exception) { Error_NameCollision(structField, exception); } }