Thanks for your explantion, I am a green hand, so maybe I need more time
the understand it.
I clearly know Mono.cecil can do everything to a C# program, because it can
read the original program and create new instructions to it.
There is another question is: can it combines two programs into one or
introduces some part of a program to another one?For example:
There is a program like:
Assembly A contains:
class program 1
{
public main(){}
}
Assembly B contains:
class program 2
{
variable a;
public fun(){ a...}
}
I wonder how to introduce the fun() in program 2 to program 1. if this can
be done, I can surely use
Mono.cecil to let main() call the fun(). Now my initial idea is to create
the variable and fun() in program 1, just
the same to program 2
but it feels a bit strange, is there a way to introduce them to program 1?
在 2016年3月3日星期四 UTC+8上午12:44:04,Jb Evain写道:
>
> Cool !
>
> I'm not exactly sure I understand what you mean.
>
> Import (ImportReference in master), creates a reference scoped to your
> module from a metadata element defined in another module. This is
> conceptually different from a C# using.
>
> Jb
>
>
> On Wed, Mar 2, 2016 at 7:23 AM, <[email protected] <javascript:>>
> wrote:
> > Thanks, it works! I wonder if the Import works like using.... in the C#
> > code, but it works in minor scale, such as the type reference but not
> > assembly reference?
> >
> > 在 2016年3月1日星期二 UTC+8下午7:20:19,[email protected]写道:
> >>
> >> I want to creat a new variable, for example, StreamWriter sw. I do like
> >> this:
> >> var stream_ref = new TypeReference("System.IO",
> >> "StreamWriter",MethodModule, null,true);
> >> var streamwriter = new VariableDefinition("writer",
> >> stream_ref);
> >> method.Body.Variables.Add(streamwriter);
> >> and I get the NullReferenceException, I feel there lacks something, but
> I
> >> don't know where...I also wonder how to initialize the varible, like:
> >> StreamWriter sw = new StreamWriter("./test.txt", true);
> >> and how to refer to it.
> >> Before, I try to create a varible like this:
> >> ins = ilProcessor.Create(OpCodes.Ldstr, @"./test.txt");
> >> ilProcessor.InsertBefore(instructions[0], ins);
> >> ins = ilProcessor.Create(OpCodes.Ldc_I4_1);
> >> ilProcessor.InsertBefore(method.Body.Instructions[1], ins);
> >> ins = ilProcessor.Create(OpCodes.Newobj,
> >> MethodModule.Import(typeof(System.IO.StreamWriter).GetConstructor( new
> >> Type[]{typeof(String), typeof(Boolean)})));
> >> ilProcessor.InsertBefore(instructions[2], ins);
> >> ins = ilProcessor.Create(OpCodes.Stloc_0);
> >> ilProcessor.InsertBefore(instructions[3], ins);
> >> it doesn't work either.
> >> I don't know why since the IL codes dumped from the one written in C#
> is
> >> like that, I know I miss something...
> >> Another question is how to use the variable?
> >>
> > --
> > --
> > --
> > mono-cecil
> > ---
> > You received this message because you are subscribed to the Google
> Groups
> > "mono-cecil" group.
> > To unsubscribe from this group and stop receiving emails from it, send
> an
> > email to [email protected] <javascript:>.
> > For more options, visit https://groups.google.com/d/optout.
>
--
--
--
mono-cecil
---
You received this message because you are subscribed to the Google Groups
"mono-cecil" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.