Beispiel #1
0
        public override NpcMethodInfo GetNpcMethodInfo(String methodName, UInt16 parameterCount, out NpcExecutionObject executionObject)
        {
            //
            // Find method with matching name
            //
            NpcMethodOverloadable overloadableMethod;

            if (methodName.Contains("."))
            {
                if (!withObjectMethodDictionary.TryGetValue(methodName, out overloadableMethod))
                {
                    throw new NpcErrorException(NpcErrorCode.UnknownMethodName,
                                                String.Format("Method '{0}' was not found", methodName));
                }
            }
            else
            {
                List <NpcMethodOverloadable> overloadableMethodsWithSameName;
                if (!noObjectDictionary.TryGetValue(methodName, out overloadableMethodsWithSameName))
                {
                    throw new NpcErrorException(NpcErrorCode.UnknownMethodName,
                                                String.Format("Method '{0}' was not found", methodName));
                }

                if (overloadableMethodsWithSameName.Count == 1)
                {
                    overloadableMethod = overloadableMethodsWithSameName[0];
                }
                else
                {
                    throw new NpcErrorException(NpcErrorCode.AmbiguousMethodName, String.Format(
                                                    "Method '{0}' exists but there are multiple objects that have a method matching that name, use <object-name>.{0} to indicate which object you would like to call the method on", methodName));
                }
            }

            //
            // Find method with matching name that has the correct number of parameters
            //
            NpcMethodInfo npcMethodInfo = overloadableMethod.GetMethod(parameterCount);

            if (npcMethodInfo == null)
            {
                throw new InvalidOperationException(String.Format("Method '{0}' was found but it does not have {1} parameters", methodName, parameterCount));
            }
            executionObject = overloadableMethod.executionObject;
            return(npcMethodInfo);
        }
 public NpcMethodOverloadable(NpcExecutionObject executionObject, NpcMethodInfo npcMethodInfo)
 {
     this.executionObject = executionObject;
     this.npcMethodInfo   = npcMethodInfo;
     this.overloads       = null;
 }