Esempio n. 1
0
        public void NoInstance()
        {
            var classType = typeof(TestService.TestClass);
            var handler   = new ClassMethodHandler(classType, classType.GetMethod("FloatToString"), false);

            Assert.Throws <TargetException> (() => handler.Invoke(new object[] { null, 3.14159f }));
        }
Esempio n. 2
0
        /// <summary>
        /// Add a class method to the given class in the given service for the given class type annotated with the KRPCClass attribute.
        /// </summary>
        public void AddClassMethod(string cls, Type classType, MethodInfo method)
        {
            TypeUtils.ValidateIdentifier(cls);
            TypeUtils.ValidateKRPCMethod(classType, method);
            if (!Classes.ContainsKey(cls))
            {
                throw new ArgumentException("Class " + cls + " does not exist");
            }
            var name           = method.Name;
            var id             = NextProcedureId;
            var classGameScene = TypeUtils.GetClassGameScene(classType, gameScene);

            if (!method.IsStatic)
            {
                var handler = new ClassMethodHandler(classType, method, TypeUtils.GetNullable(method));
                AddProcedure(new ProcedureSignature(
                                 Name, cls + '_' + name, id, method.GetDocumentation(), handler,
                                 TypeUtils.GetMethodGameScene(classType, method, classGameScene)));
            }
            else
            {
                var handler = new ClassStaticMethodHandler(method, TypeUtils.GetNullable(method));
                AddProcedure(new ProcedureSignature(
                                 Name, cls + "_static_" + name, id, method.GetDocumentation(), handler,
                                 TypeUtils.GetMethodGameScene(classType, method, classGameScene)));
            }
        }
Esempio n. 3
0
        void AddClassPropertyMethod(String cls, MemberInfo property, MethodInfo method, String attribute)
        {
            var handler             = new ClassMethodHandler(method);
            var parameter_attribute = "ParameterType(0).Class(" + Name + "." + cls + ")";

            AddProcedure(new ProcedureSignature(Name, cls + '_' + method.Name, property.GetDocumentation(), handler, GameScene, attribute, parameter_attribute));
        }
Esempio n. 4
0
        public void SimpleUsage()
        {
            var instance  = new TestService.TestClass("foo");
            var classType = typeof(TestService.TestClass);
            var handler   = new ClassMethodHandler(classType, classType.GetMethod("FloatToString"), false);

            Assert.AreEqual("foo3.14159", handler.Invoke(new object[] { instance, 3.14159f }));
        }
Esempio n. 5
0
        public void DefaultArguments()
        {
            var instance  = new TestService.TestClass("foo");
            var object_id = ObjectStore.Instance.AddInstance(instance);
            var handler   = new ClassMethodHandler(typeof(TestService.TestClass).GetMethod("IntToString"));

            Assert.AreEqual("foo42", handler.Invoke(new object[] { object_id, Type.Missing }));
        }
Esempio n. 6
0
        public void SimpleUsage()
        {
            var instance  = new TestService.TestClass("foo");
            var object_id = ObjectStore.Instance.AddInstance(instance);
            var handler   = new ClassMethodHandler(typeof(TestService.TestClass).GetMethod("FloatToString"));

            Assert.AreEqual("foo3.14159", handler.Invoke(new object[] { object_id, 3.14159f }));
        }
Esempio n. 7
0
        public void DefaultArguments()
        {
            var instance  = new TestService.TestClass("foo");
            var classType = typeof(TestService.TestClass);
            var handler   = new ClassMethodHandler(classType, classType.GetMethod("IntToString"), false);

            Assert.AreEqual("foo42", handler.Invoke(new object[] { instance, Type.Missing }));
        }
Esempio n. 8
0
        void AddClassPropertyMethod(string cls, Type classType, PropertyInfo property, MethodInfo method, bool nullable)
        {
            var handler        = new ClassMethodHandler(classType, method, nullable);
            var classGameScene = TypeUtils.GetClassGameScene(classType, gameScene);

            AddProcedure(new ProcedureSignature(
                             Name, cls + '_' + method.Name, NextProcedureId, property.GetDocumentation(), handler,
                             TypeUtils.GetClassPropertyGameScene(classType, property, classGameScene)));
        }
Esempio n. 9
0
        public void PropertiesDefaultArgument()
        {
            var handler    = new ClassMethodHandler(typeof(TestService.TestClass).GetMethod("IntToString"));
            var parameters = handler.Parameters.ToList();

            Assert.AreEqual(2, parameters.Count);
            Assert.AreEqual("this", parameters [0].Name);
            Assert.AreEqual("x", parameters [1].Name);
            Assert.AreEqual(typeof(ulong), parameters [0].Type);
            Assert.AreEqual(typeof(int), parameters [1].Type);
            Assert.IsFalse(parameters [0].HasDefaultValue);
            Assert.IsTrue(parameters [1].HasDefaultValue);
            Assert.AreEqual(typeof(string), handler.ReturnType);
        }
Esempio n. 10
0
        public void Properties()
        {
            var classType  = typeof(TestService.TestClass);
            var handler    = new ClassMethodHandler(classType, classType.GetMethod("FloatToString"), false);
            var parameters = handler.Parameters.ToList();

            Assert.AreEqual(2, parameters.Count);
            Assert.AreEqual("this", parameters [0].Name);
            Assert.AreEqual("x", parameters [1].Name);
            Assert.AreEqual(typeof(TestService.TestClass), parameters [0].Type);
            Assert.AreEqual(typeof(float), parameters [1].Type);
            Assert.IsFalse(parameters [0].HasDefaultValue);
            Assert.IsFalse(parameters [1].HasDefaultValue);
            Assert.AreEqual(typeof(string), handler.ReturnType);
        }
Esempio n. 11
0
 /// <summary>
 /// Add a class method to the given class in the given service for the given class type annotated with the KRPCClass attribute.
 /// </summary>
 public void AddClassMethod(string cls, MethodInfo method)
 {
     if (!Classes.ContainsKey(cls))
     {
         throw new ArgumentException("Class " + cls + " does not exist");
     }
     if (!method.IsStatic)
     {
         var handler = new ClassMethodHandler(method);
         AddProcedure(new ProcedureSignature(Name, cls + '_' + method.Name, method.GetDocumentation(), handler, GameScene,
                                             "Class.Method(" + Name + "." + cls + "," + method.Name + ")", "ParameterType(0).Class(" + Name + "." + cls + ")"));
     }
     else
     {
         var handler = new ClassStaticMethodHandler(method);
         AddProcedure(new ProcedureSignature(Name, cls + '_' + method.Name, method.GetDocumentation(), handler, GameScene,
                                             "Class.StaticMethod(" + Name + "." + cls + "," + method.Name + ")"));
     }
 }
Esempio n. 12
0
 /// <summary>
 /// Add a class property to the given class in the given service for the given property annotated with the KRPCProperty attribute.
 /// </summary>
 public void AddClassProperty(string cls, PropertyInfo property)
 {
     if (!Classes.ContainsKey(cls))
     {
         throw new ArgumentException("Class " + cls + " does not exist");
     }
     if (property.GetGetMethod() != null)
     {
         var method              = property.GetGetMethod();
         var handler             = new ClassMethodHandler(method);
         var attribute           = "Class.Property.Get(" + Name + "." + cls + "," + property.Name + ")";
         var parameter_attribute = "ParameterType(0).Class(" + Name + "." + cls + ")";
         AddProcedure(new ProcedureSignature(Name, cls + '_' + method.Name, property.GetDocumentation(), handler, GameScene, attribute, parameter_attribute));
     }
     if (property.GetSetMethod() != null)
     {
         var method              = property.GetSetMethod();
         var handler             = new ClassMethodHandler(method);
         var attribute           = "Class.Property.Set(" + Name + "." + cls + "," + property.Name + ")";
         var parameter_attribute = "ParameterType(0).Class(" + Name + "." + cls + ")";
         AddProcedure(new ProcedureSignature(Name, cls + '_' + method.Name, property.GetDocumentation(), handler, GameScene, attribute, parameter_attribute));
     }
 }
Esempio n. 13
0
 void AddClassPropertyMethod (String cls, MemberInfo property, MethodInfo method, String attribute)
 {
     var handler = new ClassMethodHandler (method);
     var parameter_attribute = "ParameterType(0).Class(" + Name + "." + cls + ")";
     AddProcedure (new ProcedureSignature (Name, cls + '_' + method.Name, property.GetDocumentation (), handler, GameScene, attribute, parameter_attribute));
 }
Esempio n. 14
0
        void AddClassPropertyMethod(string cls, Type classType, MemberInfo property, MethodInfo method, bool nullable)
        {
            var handler = new ClassMethodHandler(classType, method, nullable);

            AddProcedure(new ProcedureSignature(Name, cls + '_' + method.Name, property.GetDocumentation(), handler, GameScene));
        }
Esempio n. 15
0
        public void NoInstance()
        {
            var handler = new ClassMethodHandler(typeof(TestService.TestClass).GetMethod("FloatToString"));

            Assert.Throws <ArgumentException> (() => handler.Invoke(new object[] { 1000UL, 3.14159f }));
        }
Esempio n. 16
0
 /// <summary>
 /// Add a class method to the given class in the given service for the given class type annotated with the KRPCClass attribute.
 /// </summary>
 public void AddClassMethod(string cls, MethodInfo method)
 {
     if (!Classes.ContainsKey (cls))
         throw new ArgumentException ("Class " + cls + " does not exist");
     if (!method.IsStatic) {
         var handler = new ClassMethodHandler (method);
         AddProcedure (new ProcedureSignature (Name, cls + '_' + method.Name, method.GetDocumentation (), handler, GameScene,
             "Class.Method(" + Name + "." + cls + "," + method.Name + ")", "ParameterType(0).Class(" + Name + "." + cls + ")"));
     } else {
         var handler = new ClassStaticMethodHandler (method);
         AddProcedure (new ProcedureSignature (Name, cls + '_' + method.Name, method.GetDocumentation (), handler, GameScene,
             "Class.StaticMethod(" + Name + "." + cls + "," + method.Name + ")"));
     }
 }
Esempio n. 17
0
 /// <summary>
 /// Add a class property to the given class in the given service for the given property annotated with the KRPCProperty attribute.
 /// </summary>
 public void AddClassProperty(string cls, PropertyInfo property)
 {
     if (!Classes.ContainsKey (cls))
         throw new ArgumentException ("Class " + cls + " does not exist");
     if (property.GetGetMethod () != null) {
         var method = property.GetGetMethod ();
         var handler = new ClassMethodHandler (method);
         var attribute = "Class.Property.Get(" + Name + "." + cls + "," + property.Name + ")";
         var parameter_attribute = "ParameterType(0).Class(" + Name + "." + cls + ")";
         AddProcedure (new ProcedureSignature (Name, cls + '_' + method.Name, property.GetDocumentation (), handler, GameScene, attribute, parameter_attribute));
     }
     if (property.GetSetMethod () != null) {
         var method = property.GetSetMethod ();
         var handler = new ClassMethodHandler (method);
         var attribute = "Class.Property.Set(" + Name + "." + cls + "," + property.Name + ")";
         var parameter_attribute = "ParameterType(0).Class(" + Name + "." + cls + ")";
         AddProcedure (new ProcedureSignature (Name, cls + '_' + method.Name, property.GetDocumentation (), handler, GameScene, attribute, parameter_attribute));
     }
 }