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


C# Module.ResolveString方法代码示例

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


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

示例1: ConstructInstructions


//.........这里部分代码省略.........
                        metadataToken = ReadInt32(il, ref position);
                        try
                        {
                            instruction.Operand = module.ResolveType(metadataToken);
                        }
                        catch
                        {

                        }
                        // SSS : see what to do here
                        break;
                     case OperandType.InlineType:
                        metadataToken = ReadInt32(il, ref position);
                        // now we call the ResolveType always using the generic attributes type in order
                        // to support decompilation of generic methods and classes

                        // thanks to the guys from code project who commented on this missing feature
                        try
                        {
                            instruction.Operand = module.ResolveType(metadataToken);
                        }
                        catch (Exception)
                        {
                            instruction.Operand = module.ResolveType(metadataToken, this.mi.DeclaringType.GetGenericArguments(), this.mi.GetGenericArguments());
                        }
                        break;
                    case OperandType.InlineI:
                        {
                            instruction.Operand = ReadInt32(il, ref position);
                            break;
                        }
                    case OperandType.InlineI8:
                        {
                            instruction.Operand = ReadInt64(il, ref position);
                            break;
                        }
                    case OperandType.InlineNone:
                        {
                            instruction.Operand = null;
                            break;
                        }
                    case OperandType.InlineR:
                        {
                            instruction.Operand = ReadDouble(il, ref position);
                            break;
                        }
                    case OperandType.InlineString:
                        {
                            metadataToken = ReadInt32(il, ref position);
                            instruction.Operand = module.ResolveString(metadataToken);
                            break;
                        }
                    case OperandType.InlineSwitch:
                        {
                            int count = ReadInt32(il, ref position);
                            int[] casesAddresses = new int[count];
                            for (int i = 0; i < count; i++)
                            {
                                casesAddresses[i] = ReadInt32(il, ref position);
                            }
                            int[] cases = new int[count];
                            for (int i = 0; i < count; i++)
                            {
                                cases[i] = position + casesAddresses[i];
                            }
                            break;
                        }
                    case OperandType.InlineVar:
                        {
                            instruction.Operand = ReadUInt16(il, ref position);
                            break;
                        }
                    case OperandType.ShortInlineBrTarget:
                        {
                            instruction.Operand = ReadSByte(il, ref position) + position;
                            break;
                        }
                    case OperandType.ShortInlineI:
                        {
                            instruction.Operand = ReadSByte(il, ref position);
                            break;
                        }
                    case OperandType.ShortInlineR:
                        {
                            instruction.Operand = ReadSingle(il, ref position);
                            break;
                        }
                    case OperandType.ShortInlineVar:
                        {
                            instruction.Operand = ReadByte(il, ref position);
                            break;
                        }
                    default:
                        {
                            throw new Exception("Unknown operand type.");
                        }
                }
                instructions.Add(instruction);
            }
        }
开发者ID:himanshugoel2797,项目名称:MSIL2CPP,代码行数:101,代码来源:MethodBodyReader.cs

示例2: ConstructInstructions


//.........这里部分代码省略.........
                        //catch
                        //{
                        //    int i = 1;

                        //}
                        break;

                    // patched from comments on CP -hwd
                    case OperandType.InlineType:
                        metadataToken = ReadInt32(il, ref position);
                        if (this.mi is MethodInfo)
                        {
                            instruction.Operand = module.ResolveType(metadataToken,
                            this.mi.DeclaringType.GetGenericArguments(), this.mi.GetGenericArguments());
                        }
                        else if (mi is ConstructorInfo)
                        {
                            instruction.Operand = module.ResolveType(metadataToken,
                               this.mi.DeclaringType.GetGenericArguments(), null);
                        }
                        else
                        {
                            instruction.Operand = module.ResolveType(metadataToken);
                        }
                        break;

                    case OperandType.InlineI:
                        {
                            instruction.Operand = ReadInt32(il, ref position);
                            break;
                        }
                    case OperandType.InlineI8:
                        {
                            instruction.Operand = ReadInt64(il, ref position);
                            break;
                        }
                    case OperandType.InlineNone:
                        {
                            instruction.Operand = null;
                            break;
                        }
                    case OperandType.InlineR:
                        {
                            instruction.Operand = ReadDouble(il, ref position);
                            break;
                        }
                    case OperandType.InlineString:
                        {
                            metadataToken = ReadInt32(il, ref position);
                            instruction.Operand = module.ResolveString(metadataToken);
                            break;
                        }
                    case OperandType.InlineSwitch:
                        {
                            int count = ReadInt32(il, ref position);
                            int[] casesAddresses = new int[count];
                            for (int i = 0; i < count; i++)
                            {
                                casesAddresses[i] = ReadInt32(il, ref position);
                            }
                            int[] cases = new int[count];
                            for (int i = 0; i < count; i++)
                            {
                                cases[i] = position + casesAddresses[i];
                            }
                            break;
                        }
                    case OperandType.InlineVar:
                        {
                            instruction.Operand = ReadUInt16(il, ref position);
                            break;
                        }
                    case OperandType.ShortInlineBrTarget:
                        {
                            instruction.Operand = ReadSByte(il, ref position) + position;
                            break;
                        }
                    case OperandType.ShortInlineI:
                        {
                            instruction.Operand = ReadSByte(il, ref position);
                            break;
                        }
                    case OperandType.ShortInlineR:
                        {
                            instruction.Operand = ReadSingle(il, ref position);
                            break;
                        }
                    case OperandType.ShortInlineVar:
                        {
                            instruction.Operand = ReadByte(il, ref position);
                            break;
                        }
                    default:
                        {
                            throw new Exception("Unknown operand type.");
                        }
                }
                instructions.Add(instruction);
            }
        }
开发者ID:mayatforest,项目名称:Refractor,代码行数:101,代码来源:MethodBodyReader.cs

示例3: CopyOpcode

        void CopyOpcode(byte[] Bytes, ref int i, ILGenerator Gen, Module Origin, List<int> ExceptionTrinkets, Dictionary<int, Label[]> LabelOrigins)
        {
            OpCode Code = GetOpcode(Bytes, ref i);

            // These are emitted by exception handling copier if an exception
            // block is imminent. If not, copy them as usual.
            if(Code == OpCodes.Leave && ExceptionTrinkets.Contains(i + 5))
            {
                i += 4;
                return;
            }
            else if(Code == OpCodes.Leave_S && ExceptionTrinkets.Contains(i + 2))
            {
                // This is a rather tricky one. See the comment preceding the call to MineLabels above.
                i++;
                return;
            }
            else if(Code == OpCodes.Endfinally && ExceptionTrinkets.Contains(i+1)) return;

            switch(Code.OperandType)
            {
                // If no argument, then re-emit the opcode
                case OperandType.InlineNone:
                {
                    Gen.Emit(Code);
                    break;
                }

                // If argument is a method, re-emit the method reference
                case OperandType.InlineMethod:
                {
                    int Token = BitHelper.ReadInteger(Bytes, ref i);
                    MethodBase Base = Origin.ResolveMethod(Token);

                    if(Base is MethodInfo)
                        Gen.Emit(Code, GrabMethod(Base as MethodInfo));
                    else if(Base is ConstructorInfo)
                        Gen.Emit(Code, GrabConstructor(Base as ConstructorInfo));
                    else throw new InvalidOperationException("Inline method is neither method nor constructor.");

                    break;
                }

                // Argument is a field reference
                case OperandType.InlineField:
                {
                    int Token = BitHelper.ReadInteger(Bytes, ref i);
                    FieldInfo Field = Origin.ResolveField(Token);
                    Gen.Emit(Code, GrabField(Field));
                    break;
                }

                // Argument is a type reference
                case OperandType.InlineType:
                {
                    int Token = BitHelper.ReadInteger(Bytes, ref i);
                    Type Ref = Origin.ResolveType(Token);
                    Gen.Emit(Code, GrabType(Ref));
                    break;
                }

                // Argument is an inline string
                case OperandType.InlineString:
                {
                    int Token = BitHelper.ReadInteger(Bytes, ref i);
                    string Copy = Origin.ResolveString(Token);
                    Gen.Emit(Code, Copy);
                    break;
                }

                // Argument is a metadata token
                case OperandType.InlineTok:
                {
                    int Token = BitHelper.ReadInteger(Bytes, ref i);
                    MemberInfo Info = Origin.ResolveMember(Token);

                    if(Info.MemberType == MemberTypes.Field)
                    {
                        if(Code != OpCodes.Ldtoken || !TryReplaceBackingField(Bytes, i, Gen, Origin))
                            Gen.Emit(Code, GrabField(Info as FieldInfo));
                    }
                    else if(Info.MemberType == MemberTypes.Method)
                        Gen.Emit(Code, GrabMethod(Info as MethodInfo));
                    else if(Info.MemberType == MemberTypes.TypeInfo || Info.MemberType == MemberTypes.NestedType)
                        Gen.Emit(Code, GrabType(Info as Type));
                    else throw new InvalidOperationException("Inline token is neither field, nor method, nor type");

                    break;
                }

                // Argument is a switch map
                case OperandType.InlineSwitch:
                {
                    if(!LabelOrigins.ContainsKey(i))
                        throw new Exception("No switchmap found for RVA "+i.ToString("X"));

                    Label[] Labels = LabelOrigins[i];
                    i += 4 + Labels.Length*4;
                    Gen.Emit(Code, Labels);

//.........这里部分代码省略.........
开发者ID:RaptorOne,项目名称:IronAHK,代码行数:101,代码来源:CopyBody.cs

示例4: Write

        private void Write(BinaryWriter bw, Module module, MethodBody mb)
        {
            var locals = mb.LocalVariables;
            bw.Write(locals.Count);
            for (int i=0;i< locals.Count;i++)
            {
                bw.Write(locals[i].LocalType.FullName);
                bw.Write(locals[i].IsPinned);
            }

            var il = mb.GetILAsByteArray();
            for(int i = 0; i < il.Length;)
            {
                EArgumentType argType = EArgumentType.None;
                var opcode = (EOpCode)il[i];
                bw.Write(il[i]);
                i++;

                if(opcode == EOpCode.Extended)
                {
                    bw.Write(il[i]);
                    argType = ((EExtendedOpCode)il[i]).ArgFor();
                    i++;
                }
                else
                    argType = opcode.ArgFor();

                switch (argType)
                {
                    case EArgumentType.Field:
                        var fi = module.ResolveField(BitConverter.ToInt32(il, i));
                        i += 4;
                        bw.Write(Names.Field(fi));
                        break;
                    case EArgumentType.Float32:
                        bw.Write(BitConverter.ToSingle(il, i));
                        i += 4;
                        break;
                    case EArgumentType.Float64:
                        bw.Write(BitConverter.ToDouble(il, i));
                        i += 8;
                        break;
                    case EArgumentType.Token:
                    case EArgumentType.Int32:
                        bw.Write(BitConverter.ToInt32(il, i));
                        i += 4;
                        break;
                    case EArgumentType.Int64:
                        bw.Write(BitConverter.ToInt64(il, i));
                        i += 8;
                        break;
                    case EArgumentType.Int8:
                        bw.Write((sbyte)il[i]);
                        i++;
                        break;
                    case EArgumentType.ListOfInt:
                        uint count = BitConverter.ToUInt32(il, i);
                        bw.Write(count);
                        i += 4;
                        while(count > 0)
                        {
                            bw.Write(BitConverter.ToInt32(il, i));
                            i += 4;
                        }
                        break;
                    case EArgumentType.Method:
                        var mi = module.ResolveMethod(BitConverter.ToInt32(il, i));
                        i += 4;
                        bw.Write(Names.Method(mi));
                        break;
                    case EArgumentType.String:
                        var str = module.ResolveString(BitConverter.ToInt32(il, i));
                        i += 4;
                        bw.Write(str);
                        break;
                    case EArgumentType.Type:
                        var t = module.ResolveType(BitConverter.ToInt32(il, i));
                        i += 4;
                        bw.Write(t.FullName);
                        break;
                    case EArgumentType.Uint16:
                        bw.Write(BitConverter.ToUInt16(il, i));
                        i += 2;
                        break;
                    case EArgumentType.Uint32:
                        bw.Write(BitConverter.ToUInt32(il, i));
                        i += 4;
                        break;
                    case EArgumentType.Uint8:
                        bw.Write(il[i]);
                        i++;
                        break;
                }
            }

            bw.Write((byte)EOpCode.Terminator);
            /*

            var handlers = mb.ExceptionHandlingClauses;
            m_bw.Write(handlers.Count);
//.........这里部分代码省略.........
开发者ID:CurlyBrackets,项目名称:DynamicLibrary,代码行数:101,代码来源:ClassSerializer.cs

示例5: ConstructInstructions


//.........这里部分代码省略.........
                        // now we call the ResolveType always using the generic attributes type in order
                        // to support decompilation of generic methods and classes
                        // thanks to the guys from code project who commented on this missing feature
                        Type[] declaringTypeGenericArgs = this.mi.DeclaringType.GetGenericArguments();
                        Type[] genericArgs = null;
                        if (this.mi.IsGenericMethod)
                        {
                            genericArgs = this.mi.GetGenericArguments();
                        }

                        instruction.Operand = module.ResolveType(metadataToken, declaringTypeGenericArgs, genericArgs);
                        break;
                    case OperandType.InlineI:
                        {
                            instruction.Operand = ReadInt32(ref position);
                            break;
                        }

                    case OperandType.InlineI8:
                        {
                            instruction.Operand = ReadInt64(ref position);
                            break;
                        }

                    case OperandType.InlineNone:
                        {
                            instruction.Operand = null;
                            break;
                        }

                    case OperandType.InlineR:
                        {
                            instruction.Operand = ReadDouble(ref position);
                            break;
                        }

                    case OperandType.InlineString:
                        {
                            metadataToken = ReadInt32(ref position);
                            instruction.Operand = module.ResolveString(metadataToken);
                            break;
                        }

                    case OperandType.InlineSwitch:
                        {
                            int count = ReadInt32(ref position);
                            var casesAddresses = new int[count];
                            for (int i = 0; i < count; i++)
                            {
                                casesAddresses[i] = ReadInt32(ref position);
                            }

                            var cases = new int[count];
                            for (int i = 0; i < count; i++)
                            {
                                cases[i] = position + casesAddresses[i];
                            }

                            break;
                        }

                    case OperandType.InlineVar:
                        {
                            instruction.Operand = ReadUInt16(ref position);
                            break;
                        }

                    case OperandType.ShortInlineBrTarget:
                        {
                            instruction.Operand = ReadSByte(ref position) + position;
                            break;
                        }

                    case OperandType.ShortInlineI:
                        {
                            instruction.Operand = ReadSByte(ref position);
                            break;
                        }

                    case OperandType.ShortInlineR:
                        {
                            instruction.Operand = ReadSingle(ref position);
                            break;
                        }

                    case OperandType.ShortInlineVar:
                        {
                            instruction.Operand = ReadByte(ref position);
                            break;
                        }

                    default:
                        {
                            throw new NotSupportedException("Unknown operand type.");
                        }
                }

                this.instructions.Add(instruction);
            }
        }
开发者ID:Benrnz,项目名称:TypeVisualiser,代码行数:101,代码来源:MethodBodyReader.cs

示例6: ToString

 public string ToString( Module module )
 {
     OpCode opCode = OpCode;
     string operandStr = "";
     int operandStart = _startIndex + opCode.Size;
     switch (opCode.OperandType)
     {
         case OperandType.InlineBrTarget:
             break;
         case OperandType.InlineField:
             operandStr = module.ResolveField(_il.GetInt32(operandStart)).Name;
             break;
         case OperandType.InlineI:
             operandStr = _il.GetInt32(operandStart).ToString();
             break;
         case OperandType.InlineI8:
             operandStr = _il.GetInt64(operandStart).ToString();
             break;
         case OperandType.InlineMethod:
             operandStr = module.ResolveMethod(_il.GetInt32(operandStart)).Name;
             break;
         case OperandType.InlineNone:
             break;
         case OperandType.InlineR:
             operandStr = _il.GetDouble(operandStart).ToString();
             break;
         case OperandType.InlineSig:
             operandStr = string.Join("",
                                      module.ResolveSignature(_il.GetInt32(operandStart))
                                            .Select(b => b.ToString("X2")));
             break;
         case OperandType.InlineString:
             operandStr = "\"" + module.ResolveString(_il.GetInt32(operandStart)) + "\"";
             break;
         case OperandType.InlineSwitch:
             break;
         case OperandType.InlineTok:
             operandStr = module.ResolveType(_il.GetInt32(operandStart)).Name;
             break;
         case OperandType.InlineType:
             operandStr = module.ResolveType(_il.GetInt32(operandStart)).Name;
             break;
         case OperandType.InlineVar:
             operandStr = _il.GetInt16(operandStart).ToString();
             break;
         case OperandType.ShortInlineBrTarget:
             break;
         case OperandType.ShortInlineI:
             operandStr = ((int) _il[operandStart]).ToString();
             break;
         case OperandType.ShortInlineR:
             operandStr = _il.GetSingle(operandStart).ToString();
             break;
         case OperandType.ShortInlineVar:
             operandStr = ((int) _il[operandStart]).ToString();
             break;
     }
     return opCode.Name + " " + operandStr;
 }
开发者ID:kazuk,项目名称:SimpleILer,代码行数:59,代码来源:ILInstruction.cs

示例7: ReadOperand

        private object ReadOperand(OpCode code, Module module, ref long localVariableIndex)
        {
            object operand = null;
            
            switch (code.OperandType)
            {
                case OperandType.InlineNone:
                    break;
                case OperandType.InlineSwitch:
                    int length = stream.ReadInt32();
                    int[] branches = new int[length];
                    int[] offsets = new int[length];
                    for (int i = 0; i < length; i++)
                    {
                        offsets[i] = stream.ReadInt32();
                    }
                    for (int i = 0; i < length; i++)
                    {
                        branches[i] = (int)stream.BaseStream.Position + offsets[i];
                    }

                    operand = (object) branches; // Just forget to save readed offsets
                    break;
                case OperandType.ShortInlineBrTarget:
                    if (code.FlowControl != FlowControl.Branch && code.FlowControl != FlowControl.Cond_Branch)
                    {
                        operand = stream.ReadSByte();
                    }
                    else
                    {
                        operand = stream.ReadSByte() + stream.BaseStream.Position;
                    }
                    break;
                case OperandType.InlineBrTarget:
                    operand = stream.ReadInt32()+ stream.BaseStream.Position;;
                    break;
                case OperandType.ShortInlineI:
                    if (code == OpCodes.Ldc_I4_S)
                        operand = (sbyte)stream.ReadByte();
                    else
                        operand = stream.ReadByte();
                    break;
                case OperandType.InlineI:
                    operand = stream.ReadInt32();
                    break;
                case OperandType.ShortInlineR:
                    operand = stream.ReadSingle();
                    break;
                case OperandType.InlineR:
                    operand = stream.ReadDouble();
                    break;
                case OperandType.InlineI8:
                    operand = stream.ReadInt64();
                    break;
                case OperandType.InlineSig:
                    operand = module.ResolveSignature(stream.ReadInt32());
                    break;
                case OperandType.InlineString:
                    operand = module.ResolveString(stream.ReadInt32());
                    break;
                case OperandType.InlineTok:
                case OperandType.InlineType:
                case OperandType.InlineMethod:
                case OperandType.InlineField:
                    operand = module.ResolveMember(stream.ReadInt32(), typeArgs, methodArgs);
                    break;
                case OperandType.ShortInlineVar:
                    {
                        int index = stream.ReadByte();
                        operand = GetVariable(code, index);
                        localVariableIndex = index;
                    }
                    break;
                case OperandType.InlineVar:
                    {
                        int index = stream.ReadUInt16();
                        operand = GetVariable(code, index);
                        localVariableIndex = index;
                    }
                    break;
                default:
                    throw new NotSupportedException();
            }

            return operand;
        }
开发者ID:fluxit,项目名称:SpaceEngineers,代码行数:86,代码来源:IlReader.cs


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