Beispiel #1
0
        public void RegressionTest()
        {
            ClassWithTestMethods testClass       = new ClassWithTestMethods();
            NpcExecutionObject   executionObject = new NpcExecutionObject(testClass);


            NpcMethodInfo[] methodArray = new NpcMethodInfo[4];

            methodArray[0] = new NpcMethodInfo(executionObject.type.GetMethod("NoArgument"));
            NpcMethodOverloadable methods = new NpcMethodOverloadable(executionObject, methodArray[0]);

            methodArray[1] = new NpcMethodInfo(executionObject.type.GetMethod("OneArgument"));
            methods.AddOverload(methodArray[1]);

            methodArray[2] = new NpcMethodInfo(executionObject.type.GetMethod("TwoArguments"));
            methods.AddOverload(methodArray[2]);

            methodArray[3] = new NpcMethodInfo(executionObject.type.GetMethod("ThreeArguments"));
            methods.AddOverload(methodArray[3]);

            Int32 index = 0;

            foreach (NpcMethodInfo method in methods)
            {
                Assert.AreSame(methodArray[index], method, String.Format("Index {0} method={1}, methodArray={2}", index, method.methodInfo, methodArray[index]));
                index++;
            }
        }
Beispiel #2
0
        public void TestOverloadsWithSameParameterCount()
        {
            ClassWithTwoMethodsSameParameterCount testClass = new ClassWithTwoMethodsSameParameterCount();
            NpcExecutionObject executionObject = new NpcExecutionObject(testClass);

            NpcMethodOverloadable methods = new NpcMethodOverloadable(executionObject,
                                                                      new NpcMethodInfo(executionObject.type.GetMethod("Method", new Type[] { typeof(Boolean) })));

            try
            {
                methods.AddOverload(new NpcMethodInfo(executionObject.type.GetMethod("Method", new Type[] { typeof(Char) })));
                Assert.Fail("Expected NotSupportedException");
            }
            catch (NotSupportedException e)
            {
                Console.WriteLine("Caught expected exception {0}", e.Message);
            }
        }
Beispiel #3
0
        public NpcReflector(params Object [] executionObjects)
        {
            if (executionObjects == null)
            {
                throw new ArgumentNullException("executionObjects");
            }
            if (executionObjects.Length <= 0)
            {
                throw new ArgumentException("exeuctionObjects must have at least one object", "executionObjects");
            }

            this.npcExecutionObjects = new NpcExecutionObject[executionObjects.Length];

            this.interfaceSet = new NpcInterfaceInfo.Set(new Dictionary <Type, NpcInterfaceInfo>());
            this.methodList   = new List <NpcMethodOverloadable>();
            this.withObjectMethodDictionary   = new Dictionary <String, NpcMethodOverloadable>(StringComparer.OrdinalIgnoreCase);
            this.noObjectDictionary           = new Dictionary <String, List <NpcMethodOverloadable> >(StringComparer.OrdinalIgnoreCase);
            this.enumAndObjectTypesDictionary = new Dictionary <String, Type>();
            this.enumAndObjectTypesWithUniqueShortNamesDictionary = new Dictionary <String, OneOrMoreTypes>();

            //
            // Find all methods that are apart of an [NpcInterface]
            //
            SosTypeSerializationVerifier verifier = new SosTypeSerializationVerifier();

            for (int objectIndex = 0; objectIndex < executionObjects.Length; objectIndex++)
            {
                Object             executionObject    = executionObjects[objectIndex];
                NpcExecutionObject npcExecutionObject = executionObject as NpcExecutionObject;
                if (npcExecutionObject == null)
                {
                    npcExecutionObject = new NpcExecutionObject(executionObject);
                }
                npcExecutionObject.InitializeInterfaces(this.interfaceSet);
                npcExecutionObjects[objectIndex] = npcExecutionObject;

                foreach (NpcInterfaceInfo interfaceInfo in npcExecutionObject.ancestorNpcInterfaces)
                {
                    //
                    // Add all the methods
                    //
                    NpcMethodInfo[] npcMethodInfos = interfaceInfo.npcMethods;
                    for (int methodIndex = 0; methodIndex < npcMethodInfos.Length; methodIndex++)
                    {
                        NpcMethodInfo npcMethodInfo = npcMethodInfos[methodIndex];
                        //Console.WriteLine("   [NpcDebug] Registering types for method '{0}'", npcMethodInfo.methodName);

                        //
                        // Check that all parameter types can be parsed
                        //
                        for (UInt16 k = 0; k < npcMethodInfo.parametersLength; k++)
                        {
                            RegisterType(verifier, npcMethodInfo.parameters[k].ParameterType);
                        }

                        //
                        // Find the appropriate ToString method for the return type
                        //
                        RegisterType(verifier, npcMethodInfo.methodInfo.ReturnType);

                        //
                        // Add method info to dictionary
                        //
                        String objectMethodName = npcExecutionObject.objectName + "." + npcMethodInfo.methodName;
                        NpcMethodOverloadable overloadableMethod;
                        if (withObjectMethodDictionary.TryGetValue(objectMethodName, out overloadableMethod))
                        {
                            overloadableMethod.AddOverload(npcMethodInfo);
                        }
                        else
                        {
                            overloadableMethod = new NpcMethodOverloadable(npcExecutionObject, npcMethodInfo);
                            methodList.Add(overloadableMethod);
                            withObjectMethodDictionary.Add(objectMethodName, overloadableMethod);
                        }

                        List <NpcMethodOverloadable> methodsWithSameShortName;
                        if (!noObjectDictionary.TryGetValue(npcMethodInfo.methodName, out methodsWithSameShortName))
                        {
                            methodsWithSameShortName = new List <NpcMethodOverloadable>();
                            noObjectDictionary.Add(npcMethodInfo.methodName, methodsWithSameShortName);
                        }
                        methodsWithSameShortName.Add(overloadableMethod);
                    }
                }
            }
        }