1
This commit is contained in:
parent
8769e2231f
commit
75d01d40d5
@ -6,6 +6,7 @@ using System.Text;
|
|||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using System.Collections;
|
using System.Collections;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using Newtonsoft;
|
||||||
|
|
||||||
namespace F6
|
namespace F6
|
||||||
{
|
{
|
||||||
@ -54,19 +55,19 @@ namespace F6
|
|||||||
|
|
||||||
public class BaseTable
|
public class BaseTable
|
||||||
{
|
{
|
||||||
private BaseMeta _meta;
|
public BaseMeta _meta;
|
||||||
private BitArray _flags;
|
public BitArray _flags = new BitArray(100);
|
||||||
public bool HasValue(string fieldName)
|
virtual public bool HasValue(string fieldName)
|
||||||
{
|
{
|
||||||
return this.HasValue(this.GetFieldIdx(fieldName));
|
return this.HasValue(this.GetFieldIdx(fieldName));
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool HasValue(int fieldIdx)
|
virtual public bool HasValue(int fieldIdx)
|
||||||
{
|
{
|
||||||
return this._flags.Get(fieldIdx);
|
return this._flags.Get(fieldIdx);
|
||||||
}
|
}
|
||||||
|
|
||||||
public int GetFieldIdx(string fieldName)
|
virtual public int GetFieldIdx(string fieldName)
|
||||||
{
|
{
|
||||||
int idx = 0;
|
int idx = 0;
|
||||||
this._meta.nameIdxHash.TryGetValue(fieldName, out idx);
|
this._meta.nameIdxHash.TryGetValue(fieldName, out idx);
|
||||||
@ -75,7 +76,7 @@ namespace F6
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public class RawMetaTable<T> : IMetaTable
|
public class RawMetaTable<T> : IMetaTable where T : BaseTable, new()
|
||||||
{
|
{
|
||||||
protected string fileName;
|
protected string fileName;
|
||||||
protected string primKey;
|
protected string primKey;
|
||||||
@ -114,7 +115,66 @@ namespace F6
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
string fileContent = File.ReadAllText(this.fileName);
|
string fileContent = File.ReadAllText(this.fileName);
|
||||||
int i = 0;
|
var dataSet = Newtonsoft.Json.JsonConvert.DeserializeObject<List<Dictionary<string, string>>>(fileContent);
|
||||||
|
foreach(var row in dataSet)
|
||||||
|
{
|
||||||
|
T t = new T();
|
||||||
|
Type tType = typeof(T);
|
||||||
|
Type tBaseType = tType.BaseType;
|
||||||
|
int fieldIdx = 0;
|
||||||
|
foreach(var f in tBaseType.GetFields())
|
||||||
|
{
|
||||||
|
string fieldName = f.Name;
|
||||||
|
var tAttrs = f.GetCustomAttributes(typeof(MetaTableFieldAttribute), false);
|
||||||
|
if (tAttrs.Length > 0)
|
||||||
|
{
|
||||||
|
var tAttr = (MetaTableFieldAttribute)tAttrs.First();
|
||||||
|
if (tAttr != null)
|
||||||
|
{
|
||||||
|
fieldName = tAttr.fieldName;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
var typeName = f.FieldType.ToString();
|
||||||
|
string val;
|
||||||
|
if (row.TryGetValue(fieldName, out val)) {
|
||||||
|
switch (typeName)
|
||||||
|
{
|
||||||
|
case "System.Int32":
|
||||||
|
{
|
||||||
|
f.SetValue(t, int.Parse(val));
|
||||||
|
t._flags.Set(fieldIdx, true);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case "System.Int64":
|
||||||
|
{
|
||||||
|
f.SetValue(t, long.Parse(val));
|
||||||
|
t._flags.Set(fieldIdx, true);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case "System.Single":
|
||||||
|
{
|
||||||
|
f.SetValue(t, float.Parse(val));
|
||||||
|
t._flags.Set(fieldIdx, true);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case "System.Double":
|
||||||
|
{
|
||||||
|
f.SetValue(t, double.Parse(val));
|
||||||
|
t._flags.Set(fieldIdx, true);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case "System.String":
|
||||||
|
{
|
||||||
|
f.SetValue(t, val);
|
||||||
|
t._flags.Set(fieldIdx, true);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}//endif
|
||||||
|
++fieldIdx;
|
||||||
|
}
|
||||||
|
this.rawList.Add(t);
|
||||||
|
}
|
||||||
}catch(Exception e)
|
}catch(Exception e)
|
||||||
{
|
{
|
||||||
int i = 0;
|
int i = 0;
|
||||||
@ -127,7 +187,7 @@ namespace F6
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public class IdMetaTable<T>: RawMetaTable<T>
|
public class IdMetaTable<T>: RawMetaTable<T> where T : BaseTable, new()
|
||||||
{
|
{
|
||||||
protected Dictionary<Int64, T> idHash = new Dictionary<Int64, T> ();
|
protected Dictionary<Int64, T> idHash = new Dictionary<Int64, T> ();
|
||||||
|
|
||||||
@ -150,7 +210,7 @@ namespace F6
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public class NameMetaTable<T>: RawMetaTable<T>
|
public class NameMetaTable<T>: RawMetaTable<T> where T : BaseTable, new()
|
||||||
{
|
{
|
||||||
protected Dictionary<string, T> nameHash = new Dictionary<string, T>();
|
protected Dictionary<string, T> nameHash = new Dictionary<string, T>();
|
||||||
|
|
||||||
|
@ -9,6 +9,10 @@ namespace Mtb
|
|||||||
class Equip : F6.BaseTable
|
class Equip : F6.BaseTable
|
||||||
{
|
{
|
||||||
[F6.MetaTableField(fieldName = "id")]
|
[F6.MetaTableField(fieldName = "id")]
|
||||||
public int id { get; }
|
public readonly int id;
|
||||||
|
public readonly float f1;
|
||||||
|
public readonly double f2;
|
||||||
|
public readonly string f3;
|
||||||
|
public readonly long f4;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user