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


C# MethodReference.ContainsGenericParameters方法代码示例

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


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

示例1: Create

        public static string Create(MethodReference mRef, Resolver resolver, ICode ast) {
            if (mRef.ContainsGenericParameters()) {
                throw new ArgumentException("Cannot create JS for method with open generic parameters");
            }
            var mDef = mRef.Resolve();
            if (mDef.IsAbstract) {
                throw new ArgumentException("Should never need to transcode an abstract method");
            }
            var tRef = mRef.DeclaringType;
            var tDef = tRef.Resolve();

            var v = new JsMethod(resolver);
            v.Visit(ast);
            var js = v.js.ToString();

            var sb = new StringBuilder();
            // Method declaration
            var methodName = resolver.MethodNames[mRef];
            //var parameterNames = mRef.Parameters.Select(x => v.parameters.ValueOrDefault(x).NullThru(y => resolver.LocalVarNames[y])).ToArray();
            // Match parameters, but have to do by position, as method built may be a custom method replacing a BCL method,
            // so parameters are not the same.
            var parameterNames = mRef.Parameters.Select(x => v.parameters.FirstOrDefault(y => y.Key.Sequence == x.Sequence).Value.NullThru(y => resolver.LocalVarNames[y])).ToArray();
            if (!mDef.IsStatic) {
                var thisName = v.vars.FirstOrDefault(x => x.ExprType == Expr.NodeType.VarThis).NullThru(x => resolver.LocalVarNames[x]);
                parameterNames = parameterNames.Prepend(thisName).ToArray();
            }
            var unusedParameterNameGen = new NameGenerator();
            parameterNames = parameterNames.Select(x => x ?? ("_" + unusedParameterNameGen.GetNewName())).ToArray();
            sb.AppendFormat("// {0}", mRef.FullName);
            sb.AppendLine();
            sb.AppendFormat("var {0} = function({1}) {{", methodName, string.Join(", ", parameterNames));
            // Variable declarations
            var declVars = v.vars
                .Select(x => new { name = resolver.LocalVarNames[x], type = x.Type })
                .Where(x => !parameterNames.Contains(x.name))
                .Select(x => {
                    var name = x.name;
                    if (x.type.IsValueType) {
                        name += " = " + DefaultValuer.Get(x.type, resolver.FieldNames);
                    }
                    return name;
                })
                .Distinct() // Bit of a hack, but works for now
                .ToArray();
            if (declVars.Any()) {
                sb.AppendLine();
                sb.Append(' ', tabSize);
                sb.AppendFormat("var {0};", string.Join(", ", declVars));
            }
            // Method body
            sb.AppendLine(js);
            // Method ending
            sb.AppendLine("};");

            var sbStr = sb.ToString();
            return sbStr;
        }
开发者ID:chrisdunelm,项目名称:DotNetWebToolkit,代码行数:57,代码来源:JsMethod.cs


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