예제 #1
0
        public int Eval(string args)
        {
            string propertyName;

            args = Tokenizer.Next(args, out propertyName);

            SomeNode propertyNode;

            if (!ReplGlobals.Current.TryGetChild(propertyName, out propertyNode))
            {
                throw new Exception($"Couldn't find property of name {propertyNode}.");
            }

            var propertyDto = propertyNode.PropertyDto;

            if (!propertyDto.HasGetter)
            {
                throw new Exception($"Property {propertyName} does not have a getter.");
            }

            var parameters = new object[0];

            Console.WriteLine($"Invoking {propertyName} getter with params ({parameters.Join(", ")}.");

            var mobDto = propertyNode.Parent.MobDto;
            var result = ReplGlobals.ManagementObjectService.InvokeManagedOperationAsync(mobDto.FullName, propertyName, parameters).Result;

            Console.WriteLine("Result: ");
            ReplUtils.PrettyPrint(result);
            return(0);
        }
예제 #2
0
        public int Eval(string args)
        {
            string methodName;

            args = Tokenizer.Next(args, out methodName);

            SomeNode methodNode;

            if (!ReplGlobals.Current.TryGetChild(methodName, out methodNode))
            {
                throw new Exception($"Couldn't find method of name {methodNode}.");
            }

            var methodDto = methodNode.MethodDto;

            object[] parameters = methodDto.Parameters.Map(
                p => {
                string arg;
                args = Tokenizer.Next(args, out arg);
                return(Convert.ChangeType(arg, p.Type));
            });

            Console.WriteLine($"Invoking {methodName} with params ({parameters.Join(", ")}).");

            var mobDto = methodNode.Parent.MobDto;
            var result = ReplGlobals.ManagementObjectService.InvokeManagedOperationAsync(mobDto.FullName, methodName, parameters).Result;

            Console.WriteLine("Result: ");
            ReplUtils.PrettyPrint(result);
            return(0);
        }