示例#1
0
文件: ClassModel.cs 项目: pipe01/pi
        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()));
        }
示例#2
0
文件: ClassModel.cs 项目: pipe01/pi
 public ModelField(string name, object defaultValue, PiType type)
 {
     this.Name         = name;
     this.DefaultValue = defaultValue;
     this.Type         = type;
 }