コード例 #1
0
        static public MethodReference Repair2(this MethodReference @this, MethodReference method)
        {
            var _types = @this.GenericParameterTypes().Select(_Type => _Type.Name.StartsWith("!!") ? @this.GenericParameters[int.Parse(_Type.Name.Substring(2))] : (_Type.Name.StartsWith("!") ? @this.DeclaringType.GenericParameters[int.Parse(_Type.Name.Substring(1))] : _Type)).ToArray();

            if (_types.Length > 0)
            {
                if (method.GenericParameters.Count > 0)
                {
                    var _method = new GenericInstanceMethod(@this.Module.Import(method.Resolve()));
                    foreach (var k in method.GenericParameters)
                    {
                        _method.GenericArguments.Add(k.Name.StartsWith("!!") ? @this.GenericParameters[int.Parse(k.Name.Substring(2))] : (k.Name.StartsWith("!") ? @this.DeclaringType.GenericParameters[int.Parse(k.Name.Substring(1))] : k));
                    }
                    _method.DeclaringType = @this.GetRealType(method.DeclaringType);
                    return(_method);
                }
                else
                {
                    var dec = @this.GetRealType(method.DeclaringType);
                    if (dec is GenericInstanceType)
                    {
                        var _method = @this.Module.Import(method.Resolve()).MakeHostInstanceGeneric((dec as GenericInstanceType).GenericArguments.ToArray());
                        //var _method = new MethodReference(method.Name, that.GetRealType(method.ReturnType), that.GetRealType(method.DeclaringType));
                        //foreach (var _parameter in method.Parameters) { _method.Parameters.Add(new ParameterDefinition(_parameter.Name, _parameter.Attributes, that.GetRealType(_parameter.ParameterType))); }
                        return(_method);
                    }
                    else
                    {
                        return(method);
                    }
                }
            }
            //var met = method.Resolve();
            //if (met.GenericParameters.Count > 0)
            //{
            //    var kk = method.Module.Import(met).MakeGenericMethod(_types.Reverse().Take(met.GenericParameters.Count).Reverse().ToArray());
            //    if (met.DeclaringType.GenericParameters.Count > 0) { kk.DeclaringType = met.DeclaringType.MakeGenericType(_types.Take(met.DeclaringType.GenericParameters.Count)); }
            //    return kk;
            //}
            //if (met.DeclaringType.GenericParameters.Count > 0)
            //{
            //    var kk = method.Module.Import(met);
            //    kk.DeclaringType = met.DeclaringType.MakeGenericType(_types.Take(met.DeclaringType.GenericParameters.Count));
            //    return kk;
            //}
            return(method);
        }