Example #1
0
        private void CompileNextFieldDefinition(LexList theLexList, Type varType)
        {
            string varId = theLexList.GetIdentifier("Expected the name of the field here.");

            MostRecentNameAdded = varId;
            theLexList.CheckStr(";", "Expected a ; here");
            if (MadeFieldsDict.ContainsKey(varId))
            {
                theLexList.ThrowException("This field already defined.");
            }
            if (CompileMethodsDict.ContainsKey(varId))
            {
                theLexList.ThrowException("This field name already used as a method name.");
            }
            MadeFieldsDict.Add(varId, new MadeField()
            {
                VarName = varId, VarType = varType, Index = MadeFieldsDict.Count
            });
            FieldInfo fi = ClassType.GetField("Fields", BindingFlags.Public | BindingFlags.Instance);

            if (fi == null)
            {
                theLexList.ThrowException("Can only add fields to a class that has a 'List<Object> Fields' field.");
            }
            if (fi.FieldType != typeof(List <object>))
            {
                theLexList.ThrowException("Can only add fields to a class where its Fields field is of type List<object>.");
            }
            theLexList.Next();
        }