Ejemplo n.º 1
0
    private static void CreateChangeLog(string path, Type type, object before, object after)
    {
        var log = XChangeLogBank.Take();

        log.before = before;
        log.after  = after;
        log.path   = path;
        log.delta  = 0;
        log.type   = type;
        if (type == typeof(int))
        {
            var b     = (int)before;
            var a     = (int)after;
            var delta = a - b;
            log.delta = delta;
        }
        else if (type == typeof(float))
        {
            var b     = (float)before;
            var a     = (float)after;
            var delta = a - b;
            log.delta = delta;
        }
        else if (type == typeof(double))
        {
            var b     = (double)before;
            var a     = (double)after;
            var delta = a - b;
            log.delta = delta;
        }
        changeLog = log;
    }
Ejemplo n.º 2
0
 public static void GiveBack(XChangeLog change)
 {
     queue.Enqueue(change);
 }
Ejemplo n.º 3
0
    public static XChangeLog Update(object root, string path, string value)
    {
        nowPath.Clear();
        changeLog = null;
        var pathParts = path.Split('.');
        var obj       = root;

        for (int i = 0; i < pathParts.Length; i++)
        {
            var part = pathParts[i];
            if (i != pathParts.Length - 1)
            {
                // enter
                var dic = obj as IDictionary;
                if (dic != null)
                {
                    var key = part;
                    obj = GotoDicChild(dic, key);
                    continue;
                }
                var list = obj as IList;
                if (list != null)
                {
                    var index = part;
                    obj = GotoListChild(list, index);
                    continue;
                }
                var regularObj = obj;
                if (regularObj != null)
                {
                    var feild = part;
                    obj = GotoRegularObjChild(regularObj, feild);
                    continue;
                }
                throw new Exception("path: " + PathToString() + " type is " + obj.GetType().Name + ", but access " + value);
            }
            else
            {
                // set
                var dic = obj as IDictionary;
                if (dic != null)
                {
                    var key = part;
                    SetDic(dic, key, value);
                    continue;
                }
                var list = obj as IList;
                if (list != null)
                {
                    var index = part;
                    SetList(list, index, value);
                    continue;
                }
                var regularObj = obj;
                if (regularObj != null)
                {
                    var feild = part;
                    SetRegularObj(regularObj, feild, value);
                    continue;
                }
                throw new Exception("path: " + PathToString() + " type is " + obj.GetType().Name + ", but set " + value);
            }
        }
        return(changeLog);
    }