当前位置: 首页>>代码示例>>C#>>正文


C# Script.FindType方法代码示例

本文整理汇总了C#中System.Script.FindType方法的典型用法代码示例。如果您正苦于以下问题:C# Script.FindType方法的具体用法?C# Script.FindType怎么用?C# Script.FindType使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Script的用法示例。


在下文中一共展示了Script.FindType方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Execute

        public override object Execute(Script script, Scope scope, Token previousToken, object unknown)
        {
            if (unknown != null)
            {
                // TODO: Write a better message for this...
                throw new Exception("An object cannot be passed to a 'new' object!");
            }

            return Invoke(script, scope, null, script.FindType(_name), null, _arguments, _generics);
        }
开发者ID:iammitch,项目名称:Slimterpreter,代码行数:10,代码来源:NewTypeToken.cs

示例2: Invoke

        /// <summary>
        /// Invokes a method on type.
        /// </summary>
        /// <param name="script"></param>
        /// <param name="scope"></param>
        /// <param name="obj">The object that the method before returned, this can be null for static methods.</param>
        /// <param name="objectType">The type of object.</param>
        /// <param name="methodName">The method we want to call, if null, we are assuming that we want to call the constructor for this type.</param>
        /// <param name="arguments">The arguments for the method.</param>
        /// <param name="generics">If generic, the types we are passing to it.</param>
        /// <param name="locals">Local variables.</param>
        /// <returns>The result of the method, or Slimterpreter.Void if no return type.</returns>
        protected object Invoke(Script script, Scope scope, object obj, Type objectType, string methodName, List<List<Token>> arguments, List<string> generics)
        {
            if (generics.Count != 0)
            {
                var genericTypes = new Type[generics.Count];
                for (int i = 0; i < generics.Count; i++)
                {
                    Type type = script.FindType(generics[i]);
                    if (type == null)
                    {
                        throw new InvalidCastException("Cannot cast to type " + generics[i]);
                    }
                    genericTypes[i] = type;
                }
                objectType = objectType.MakeGenericType(genericTypes);
            }

            // Solve the parameters.
            var argumentTypes = new Type[arguments.Count];
            var argumentValues = new object[arguments.Count];
            for (int i = 0; i < arguments.Count; i++)
            {
                object res = null;
                // We need to get to the end of the list of Calls...
                for (int j = 0; j < arguments[i].Count; j++)
                {
                    if (j + 1 < arguments[i].Count)
                    {
                        res = arguments[i][j].Execute(script, null, null, res);
                    }
                    else if (j + 1 == arguments[i].Count)
                    {
                        argumentValues[i] = arguments[i][j].Execute(script, scope, null, res);
                        if (argumentValues[i] == null)
                        {
                            argumentTypes[i] = typeof (object);
                        }
                        else
                        {
                            argumentTypes[i] = argumentValues[i].GetType();
                        }
                    }
                }
            }

            if (methodName == null)
            {
                return ConstructorInvoke(objectType, argumentTypes, argumentValues);
            }
            else
            {
                return MethodInvoke(obj, methodName, objectType, argumentTypes, argumentValues);
            }
        }
开发者ID:iammitch,项目名称:Slimterpreter,代码行数:66,代码来源:ReflectionToken.cs

示例3: Execute

 public override object Execute(Script script, Scope scope, Token previousToken, object unknown)
 {
     return script.FindType(_id);
 }
开发者ID:iammitch,项目名称:Slimterpreter,代码行数:4,代码来源:TypeToken.cs


注:本文中的System.Script.FindType方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。