Пример #1
0
        public void InitializeInterfaces(NpcInterfaceInfo.Set interfaceSet)
        {
            if (parentNpcInterfaces == null)
            {
                this.parentNpcInterfaces   = new List <NpcInterfaceInfo>();
                this.ancestorNpcInterfaces = new List <NpcInterfaceInfo>();
                interfaceSet.GetParentInterfaces(type, parentNpcInterfaces, ancestorNpcInterfaces);

                if (parentNpcInterfaces.Count <= 0)
                {
                    throw new InvalidOperationException(String.Format(
                                                            "Class {0} did not implement any NpcInterfaces (An NpcInterface is an interface with the [NpcInterface] attribute)", type.Name));
                }
            }
            else
            {
                foreach (var @interface in parentNpcInterfaces)
                {
                    interfaceSet.TryAdd(@interface.interfaceType, @interface);
                }
                foreach (var @interface in ancestorNpcInterfaces)
                {
                    interfaceSet.TryAdd(@interface.interfaceType, @interface);
                }
            }
        }
Пример #2
0
        public void InitializeInterfaces(NpcInterfaceInfo.Set interfaceSet)
        {
            if (parentNpcInterfaces != null)
            {
                throw new InvalidOperationException("Interfaces already initialized");
            }

            this.parentNpcInterfaces   = new List <NpcInterfaceInfo>();
            this.ancestorNpcInterfaces = new List <NpcInterfaceInfo>();
            interfaceSet.GetParentInterfaces(interfaceType, parentNpcInterfaces, ancestorNpcInterfaces);
        }
Пример #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);
                    }
                }
            }
        }