예제 #1
0
        public bool Input(ICell cell)
        {
            string cellStringValue = cell.ToString();

            if (cell.ColumnIndex == 0)
            {
                if (cellStringValue.StartsWith("//", System.StringComparison.InvariantCulture))
                {
                    // comments. Ignore
                    return(false);
                }
                else if (cellStringValue.StartsWith("class ", System.StringComparison.InvariantCulture))
                {
                    if (mainClass == null)
                    {
                        mainClass = cellStringValue;
                    }
                    else
                    {
                        // class definition
                        currentClass = new ClassDefine()
                        {
                            className  = cellStringValue,
                            defineCell = cell
                        };
                        classDefines.Add(currentClass);
                    }
                }
                else if (!string.IsNullOrEmpty(cellStringValue.Trim()) && !cellStringValue.StartsWith("//", StringComparison.InvariantCulture))
                {
                    // Find the same field
                    FieldDefine fd = fields.Find((x) => x.GetFieldString() == cellStringValue);
                    if (!cellStringValue.Contains(" "))
                    {
                        // Use previos field
                        fd = lastField;
                    }
                    if (fd == null)
                    {
                        fd = new FieldDefine(cellStringValue);
                        fields.Add(fd);
                        lastField = fd;
                    }
                    if (fd != null)
                    {
                        fd.cellList.Add(cell);
                    }
                }
            }
            else
            {
                if (currentClass != null)
                {
                    currentClass.Input(cell);
                }
            }
            return(true);
        }
예제 #2
0
            }             // func VisitLambda

            public void InitMethods(Type typeFinished)
            {
                foreach (var c in fields)
                {
                    FieldDefine fd = c.Value;

                    //Debug.Print("Init: {0} : {1} = {2}", fd.Field.Name, fd.Field.FieldType.Name, fd.InitValue);
                    typeFinished.GetField(fd.Field.Name, BindingFlags.NonPublic | BindingFlags.Static).SetValue(null, fd.InitValue);
                }
            }     // proc CompileInitMethod
예제 #3
0
 private Expression CreateField(object value, Type fieldType, Func <object> initValue)
 {
     if (fields.TryGetValue(value, out var fd))
     {
         return(Lua.EnsureType(Expression.Field(null, fd.Field), fieldType));
     }
     else
     {
         fields[value] = fd = new FieldDefine
         {
             Field     = type.DefineField("$constant" + fields.Count.ToString(), fieldType, FieldAttributes.Private | FieldAttributes.Static),
             InitValue = initValue == null ? value : initValue()
         };
         return(Expression.Field(null, fd.Field));
     }
 }             // func CreateField
예제 #4
0
        public void Import(ScriptableObject sObj, Type textType, ScriptDefine scriptDefine)
        {
            FieldInfo fi = textType.GetField(fieldName);

            // Is a List<...> filed
            if (fi != null && fi.FieldType.IsGenericType && fi.FieldType.GetGenericTypeDefinition() == typeof(List <>))
            {
                // new List<'Data'>()
                var container = Activator.CreateInstance(fi.FieldType);
                fi.SetValue(sObj, container);

                Type entityType = fi.FieldType.GetGenericArguments()[0];

                // Find List.Add(...)
                MethodInfo mi = fi.FieldType.GetMethod("Add", new Type[] { entityType });
                if (mi != null)
                {
                    foreach (ICell cell in cellList)
                    {
                        IRow row = cell.Row;

                        // find this 'Data' class define
                        ClassDefine cd = scriptDefine.classDefines.Find((x) => x.className.Replace("class ", string.Empty) == elementTypeName);
                        if (cd != null && row != null)
                        {
                            // new a 'Data' class
                            var element = Activator.CreateInstance(entityType);

                            // for each fileds in this class
                            for (int i = 0; i < cd.fields.Count; i++)
                            {
                                FieldDefine assetField = cd.fields[i];
                                assetField.Import(element, entityType, i, row, cd);
                            }

                            // List.Add(element)
                            mi.Invoke(container, new object[] { element });
                        }
                    }
                }
            }
            else
            {
            }
        }
예제 #5
0
        //load Schema To Reader.
        void LoadSchema()
        {
            m_Schema           = new Schema();
            m_Schema.ClassName = m_FileName;
            HSSFSheet sheet = (HSSFSheet)m_Hssfworkbook.GetSheetAt(0);
            HSSFRow   row0  = (HSSFRow)sheet.GetRow(0);
            // HSSFRow row1 = (HSSFRow)sheet.GetRow(1);
            HSSFRow row2 = (HSSFRow)sheet.GetRow(2);


            for (int i = 0; i < row0.LastCellNum; ++i)
            {
                FieldDefine tempDefine = new FieldDefine();

                tempDefine.FieldName = row0.GetCell(i).ToString();
                tempDefine.Index     = i;
                string tempTypeStr = row2.GetCell(i).ToString();
                if (tempTypeStr == "INT" || tempTypeStr == "int" || tempTypeStr == "Int")
                {
                    tempDefine.FieldType = FIELD_TYPE.T_INT;
                }
                else if (tempTypeStr == "FLOAT" || tempTypeStr == "float" || tempTypeStr == "Float")
                {
                    tempDefine.FieldType = FIELD_TYPE.T_FLOAT;
                }
                else if (tempTypeStr == "STRING" || tempTypeStr == "string" || tempTypeStr == "String")
                {
                    tempDefine.FieldType = FIELD_TYPE.T_STRING;
                }
                else
                {
                    tempDefine.FieldType = FIELD_TYPE.T_INVALID;
                }

                m_Schema.AddDefine(tempDefine);
            }
        }
예제 #6
0
        public string GenerateClass()
        {
            string result = "\t[System.Serializable]\n";

            result += "\tpublic " + className + '\n';
            result += "\t{\n";
            FieldDefine prevField = null;

            foreach (FieldDefine field in fields)
            {
                if (field.IsComment)
                {
                    continue;
                }

                if (prevField == null || field.fieldName != prevField.fieldName)
                {
                    result += "\t\tpublic " + field.GetFieldString() + ";\n";
                }
                prevField = field;
            }
            result += "\t}\n";
            return(result);
        }
예제 #7
0
        void LoadData()
        {
            if (m_Schema == null)
            {
                return;
            }
            HSSFSheet sheet = (HSSFSheet)m_Hssfworkbook.GetSheetAt(0);

            int CurrentRowIndex = 0;

            System.Collections.IEnumerator rows = sheet.GetRowEnumerator();
            while (rows.MoveNext())
            {
                HSSFRow row = (HSSFRow)rows.Current;
                if (CurrentRowIndex < StartRow)
                {
                    CurrentRowIndex++;
                    continue;
                }
                Row tempRow = new Row(m_Schema);

                for (int i = 0; i < row.LastCellNum; i++)
                {
                    HSSFCell    cell       = (HSSFCell)row.GetCell(i);
                    FieldDefine tempDefine = m_Schema.GetDefine(i);
                    Field       tempField  = null;
                    if (cell != null)
                    {
                        switch (tempDefine.FieldType)
                        {
                        case FIELD_TYPE.T_INT:
                            int tempInt = (int)cell.NumericCellValue;
                            tempField = new Field(tempInt);
                            break;

                        case FIELD_TYPE.T_FLOAT:
                            float tempFloat = (float)cell.NumericCellValue;
                            tempField = new Field(tempFloat);
                            break;

                        case FIELD_TYPE.T_STRING:
                            string tempString = cell.StringCellValue;
                            tempField = new Field(tempString);
                            break;
                        }
                    }
                    else
                    {
                        switch (tempDefine.FieldType)
                        {
                        case FIELD_TYPE.T_INT:
                            int tempInt = 0;
                            tempField = new Field(tempInt);
                            break;

                        case FIELD_TYPE.T_FLOAT:
                            float tempFloat = 0;
                            tempField = new Field(tempFloat);
                            break;

                        case FIELD_TYPE.T_STRING:
                            string tempString = "";
                            tempField = new Field(tempString);
                            break;
                        }
                    }
                    tempRow.m_Fields.Add(tempField);
                }
                mRowList.Add(tempRow);
                CurrentRowIndex++;
            }
        }
예제 #8
0
        //load Schema To Reader.
        void LoadSchema()
        {
            m_Schema = new Schema();
            m_Schema.ClassName = m_FileName;
            HSSFSheet sheet = (HSSFSheet)m_Hssfworkbook.GetSheetAt(0);
            HSSFRow row0 = (HSSFRow)sheet.GetRow(0);
               // HSSFRow row1 = (HSSFRow)sheet.GetRow(1);
            HSSFRow row2 = (HSSFRow)sheet.GetRow(2);

            for (int i = 0; i < row0.LastCellNum; ++i)
            {
                FieldDefine tempDefine = new FieldDefine();

                tempDefine.FieldName = row0.GetCell(i).ToString();
                tempDefine.Index = i;
                string tempTypeStr = row2.GetCell(i).ToString();
                if (tempTypeStr == "INT" || tempTypeStr == "int" || tempTypeStr == "Int")
                {
                    tempDefine.FieldType = FIELD_TYPE.T_INT;
                }
                else if (tempTypeStr == "FLOAT" || tempTypeStr == "float" || tempTypeStr == "Float")
                {
                    tempDefine.FieldType = FIELD_TYPE.T_FLOAT;
                }
                else if (tempTypeStr == "STRING" || tempTypeStr == "string" || tempTypeStr == "String")
                {
                    tempDefine.FieldType = FIELD_TYPE.T_STRING;
                }
                else
                {
                    tempDefine.FieldType = FIELD_TYPE.T_INVALID;
                }

                m_Schema.AddDefine(tempDefine);
            }
        }