Beispiel #1
0
        public static ClassModel FromDeclaration(PiInterpreter interpreter, ClassDeclaration declaration)
        {
            var fields = new List <ModelField>();

            foreach (var field in declaration.Fields)
            {
                object value = null;

                if (field.DefaultValue != null)
                {
                    value = interpreter.EvaluateExpression(field.DefaultValue);
                }

                PiType fieldType = interpreter.Context.GetPiType(field.Type);

                if (fieldType == null)
                {
                    throw new InterpreterException($"Type \"{field.Type}\" not found", field.Location);
                }

                fields.Add(new ModelField(field.Name, value, fieldType));
            }

            return(new ClassModel(declaration.Name, fields.ToArray()));
        }
Beispiel #2
0
 public ModelField(string name, object defaultValue, PiType type)
 {
     this.Name         = name;
     this.DefaultValue = defaultValue;
     this.Type         = type;
 }