Ejemplo n.º 1
0
        private object CreateExpression(string name, string returnType, List <string> param, bool async, bool canFail)
        {
            if (param.Count > 6)
            {
                throw new NotImplementedException();
            }

            var isAction = NeovimUtil.ConvTypeNeovimToCs(returnType) == typeof(void);

            if (isAction && param.Count == 0)
            {
                return(CreateAction(name, returnType, param, async, canFail));
            }
            else
            {
                if (!isAction)
                {
                    param.Add(returnType);
                }
                var creatorName = (isAction) ? "CreateAction" : "CreateFunc";
                var methods     = typeof(NeovimClient <T>).GetMethods(BindingFlags.NonPublic | BindingFlags.Instance);
                var baseMethod  = methods.First(m => m.Name == creatorName && m.GetGenericArguments().Count() == param.Count);
                var method      = baseMethod.MakeGenericMethod(param.Select(i => NeovimUtil.ConvTypeNeovimToCs(i)).ToArray());
                return(method.Invoke(this, new object[] { name, returnType, param, async, canFail }));
            }
        }
Ejemplo n.º 2
0
        public NeovimFuncInfo(string name, string dscr, List <string> paramType, string returnType, object func, bool isAsync, bool canFail)
        {
            Name             = name;
            Description      = dscr;
            ReturnTypeNeovim = returnType;
            ReturnTypeCs     = NeovimUtil.ConvTypeNeovimToCs(returnType);
            IsAsync          = isAsync;
            CanFail          = canFail;
            Func             = func;

            foreach (var p in paramType)
            {
                paramTypeNeovim.Add(p);
                paramTypeCs.Add(NeovimUtil.ConvTypeNeovimToCs(p));
            }
        }
Ejemplo n.º 3
0
        private void CreateApi()
        {
            api.Clear();
            var funcs       = GetApiInfo().AsList()[1].AsDictionary()["functions"].AsList();
            var funcsStatic = GetApiStatic();

            foreach (var f in funcs.Concat(funcsStatic))
            {
                var func = f.AsDictionary();

                var parameters = func["parameters"].AsList();
                var async      = (func.ContainsKey("async")) ? func["async"].AsBoolean() : false;
                var canFail    = (func.ContainsKey("can_fail")) ? func["can_fail"].AsBoolean() : false;
                var returnType = func["return_type"].AsString();
                var name       = func["name"].AsString();

                var param = new List <string>();

                var dscr0 = (NeovimUtil.ConvTypeNeovimToCs(returnType) == typeof(void)) ? "void Action<" : NeovimUtil.ConvTypeNeovimToCs(returnType).Name + " Func<";
                var dscr1 = "( String name, ";
                foreach (var p in parameters)
                {
                    var pType = p.AsList()[0].AsString();
                    var pName = p.AsList()[1].AsString();
                    param.Add(pType);
                    dscr0 += NeovimUtil.ConvTypeNeovimToCs(pType).Name + ", ";
                    dscr1 += NeovimUtil.ConvTypeNeovimToCs(pType).Name + " " + pName + ", ";
                }
                dscr0 = dscr0.Remove(dscr0.Length - 2);
                dscr1 = dscr1.Remove(dscr1.Length - 2);
                var dscr = dscr0 + ">" + dscr1 + " )";

                var expr       = CreateExpression(name, returnType, param, async, canFail);
                var neovimFunc = new NeovimFuncInfo(name, dscr, param, returnType, expr, async, canFail);
                api.Add(name, neovimFunc);
            }
        }