﻿<?xml version="1.0" encoding="utf-8"?><rss version="2.0"><channel><title>Ayende @ Rahien</title><link>http://ayende.com</link><description>Ayende @ Rahien</description><copyright>Copyright (C) Ayende Rahien  2004 - 2021 (c) 2026</copyright><ttl>60</ttl><item><title>Mark Whitfeld commented on Can you hack this out?</title><description>Hmmm.... If this is possible, then I'm hoping that there are some pretty ground breaking improvements to Rhino Mocks in the near future :)
</description><link>http://ayende.com/4299/can-you-hack-this-out#comment77</link><guid>http://ayende.com/4299/can-you-hack-this-out#comment77</guid><pubDate>Fri, 27 Nov 2009 07:39:06 GMT</pubDate></item><item><title>Arielr commented on Can you hack this out?</title><description>Oren,
  
  
Yeah, I know.
  
Fun, ain't it? :)
</description><link>http://ayende.com/4299/can-you-hack-this-out#comment76</link><guid>http://ayende.com/4299/can-you-hack-this-out#comment76</guid><pubDate>Thu, 26 Nov 2009 19:06:05 GMT</pubDate></item><item><title>dexon commented on Can you hack this out?</title><description>Maybe something like this:
  
  
var irunner = typeof(AssemblyRunner).GetInterface("IRunner");
  
....
  
TypeBuilder myType = myModule.DefineType("MyRunner", 
  
				TypeAttributes.Public | TypeAttributes.Class, null, new Type[]{ irunner });
  
MethodBuilder exMethod = 
  
				myType.DefineMethod("Execute", MethodAttributes.Public, typeof(void), new Type[]{});
  
ILGenerator ilgen = exMethod.GetILGenerator();
  
ilgen.EmitWriteLine("before executing");
  
// call to AssemblyRunner.Execute
  
ilgen.EmitWriteLine("after executing");
  
  
Type finished = myType.CreateType();
  
  
Type[] typeArgs = {finished};
  
Type constructed = typeof(CompositeRunner&lt;&gt;).MakeGenericType(typeArgs);
  
MethodInfo mi = constructed.GetMethod("Execute");
  
  
mi.Invoke(Activator.CreateInstance(constructed, null, null), null);
  
  
It's allready passing through  
  
typeof(IRunner).IsAssignableFrom(typeof(T))
  
but failing on 
  
var runner = (IRunner)new T();
</description><link>http://ayende.com/4299/can-you-hack-this-out#comment75</link><guid>http://ayende.com/4299/can-you-hack-this-out#comment75</guid><pubDate>Wed, 25 Nov 2009 20:15:40 GMT</pubDate></item><item><title>Ayende Rahien commented on Can you hack this out?</title><description>Arielr,
  
That is pretty much cheating.
  
</description><link>http://ayende.com/4299/can-you-hack-this-out#comment74</link><guid>http://ayende.com/4299/can-you-hack-this-out#comment74</guid><pubDate>Tue, 24 Nov 2009 11:26:41 GMT</pubDate></item><item><title>Arielr commented on Can you hack this out?</title><description>Change the System.Console.WriteLine() function in mscorlib, and do with it what you want.
  
[www.blackhat.com/.../...agedCodeRootkits-PAPER.pdf](http://www.blackhat.com/presentations/bh-usa-09/METULA/BHUSA09-Metula-ManagedCodeRootkits-PAPER.pdf)  
  
</description><link>http://ayende.com/4299/can-you-hack-this-out#comment73</link><guid>http://ayende.com/4299/can-you-hack-this-out#comment73</guid><pubDate>Tue, 24 Nov 2009 08:05:47 GMT</pubDate></item><item><title>liviu commented on Can you hack this out?</title><description>I said resharper, i ment reflector...
  
I think the challange is related either to EF or to L2S profiling...
</description><link>http://ayende.com/4299/can-you-hack-this-out#comment72</link><guid>http://ayende.com/4299/can-you-hack-this-out#comment72</guid><pubDate>Mon, 23 Nov 2009 11:28:17 GMT</pubDate></item><item><title>hpower11 commented on Can you hack this out?</title><description>Ayende:
  
You said "The real problem was a bit harder" And by far no one has manage to solve the "easier one" 
  
  
Can you please enlighten us with at list some hints. Also I am very curious about the real challenge you had.
  
</description><link>http://ayende.com/4299/can-you-hack-this-out#comment71</link><guid>http://ayende.com/4299/can-you-hack-this-out#comment71</guid><pubDate>Mon, 23 Nov 2009 11:05:18 GMT</pubDate></item><item><title>Van commented on Can you hack this out?</title><description>Anthony Dewhirst:
  
I think the cast can be handled with explicit operator.
  
  
I still cannot figure out how to trick the typeof(T) to return the Type that I wanted.
</description><link>http://ayende.com/4299/can-you-hack-this-out#comment70</link><guid>http://ayende.com/4299/can-you-hack-this-out#comment70</guid><pubDate>Mon, 23 Nov 2009 07:45:25 GMT</pubDate></item><item><title>Anthony Dewhirst commented on Can you hack this out?</title><description>David: 
  
if you do override IsAssignableFrom you still have to get past the cast on the next line.
  
  
Ayende:
  
Do you need to some how push the IRunner interface that you get using reflection into the RuntimeTypeCache for the new object or am I heading in the wrong direction?
</description><link>http://ayende.com/4299/can-you-hack-this-out#comment69</link><guid>http://ayende.com/4299/can-you-hack-this-out#comment69</guid><pubDate>Mon, 23 Nov 2009 06:56:56 GMT</pubDate></item><item><title>Alex Simkin commented on Can you hack this out?</title><description>@liviu
  
"resharper on L2S Profiler :--))"
  
  
Did that, understand how he solved the task at hand, still cannot solve this one.
  
</description><link>http://ayende.com/4299/can-you-hack-this-out#comment68</link><guid>http://ayende.com/4299/can-you-hack-this-out#comment68</guid><pubDate>Mon, 23 Nov 2009 01:39:11 GMT</pubDate></item><item><title>David commented on Can you hack this out?</title><description>I agree with Anthony, can we have some more hints, at work we are having fun in our lunch break on this one ;)
  
  
@ Whut, how does you code look right now?
  
  
  
I think to get round the IsAssignableFrom, you have to Inherit off the Type Class, override this function to return true and then use the System.Reflection.Emit to force the code to use your Type class. thing is I have yet to figure out how to do that
  
  
@ Ayende, the class type you pass into the CompositeRunner does not inherit of IRunner? its just a class that has an execute function, and you make it always return true on the IsAssignableFrom?
  
</description><link>http://ayende.com/4299/can-you-hack-this-out#comment67</link><guid>http://ayende.com/4299/can-you-hack-this-out#comment67</guid><pubDate>Sun, 22 Nov 2009 23:53:06 GMT</pubDate></item><item><title>liviu commented on Can you hack this out?</title><description>I think the solution can be found by using resharper on L2S Profiler :--))
  
</description><link>http://ayende.com/4299/can-you-hack-this-out#comment66</link><guid>http://ayende.com/4299/can-you-hack-this-out#comment66</guid><pubDate>Sun, 22 Nov 2009 23:14:42 GMT</pubDate></item><item><title>Anthony Dewhirst commented on Can you hack this out?</title><description>Please Don't give the answer, maybe some hints so we can try to figure it out. (I might be the only fool asking for this though)
</description><link>http://ayende.com/4299/can-you-hack-this-out#comment65</link><guid>http://ayende.com/4299/can-you-hack-this-out#comment65</guid><pubDate>Sun, 22 Nov 2009 22:27:17 GMT</pubDate></item><item><title>Alex Simkin commented on Can you hack this out?</title><description>@olcay şeker
  
  
Apparently we didn't ask kindly enough.
</description><link>http://ayende.com/4299/can-you-hack-this-out#comment64</link><guid>http://ayende.com/4299/can-you-hack-this-out#comment64</guid><pubDate>Sun, 22 Nov 2009 22:15:14 GMT</pubDate></item><item><title>olcay şeker commented on Can you hack this out?</title><description>@ayende
  
will you unveil the answer???
</description><link>http://ayende.com/4299/can-you-hack-this-out#comment63</link><guid>http://ayende.com/4299/can-you-hack-this-out#comment63</guid><pubDate>Sun, 22 Nov 2009 13:44:11 GMT</pubDate></item><item><title>Whut commented on Can you hack this out?</title><description>Using remoting, message sinks and some reflection hacks I'm able to run those lines:
  
  
var runner = (IRunner)new T();
  
runner.Execute();
  
  
Still I can't crack  this
  
  
if(!typeof(IRunner).IsAssignableFrom(typeof(T)))
  
  
But I will find it;)
</description><link>http://ayende.com/4299/can-you-hack-this-out#comment62</link><guid>http://ayende.com/4299/can-you-hack-this-out#comment62</guid><pubDate>Sat, 21 Nov 2009 12:54:36 GMT</pubDate></item><item><title>Gian Maria commented on Can you hack this out?</title><description>I spent this morning 30 minutes thinking to a solution, it is really a thought question :).
  
Ayende, it is somewhat related to creating a dynamic class with reflection.Emit and changing manually the TypeToken, setting with reflection the m_tdType field of the TypeBuilder? when the compositeRunner checks if T implements IRunner uses typeof(T) that in MSIL generates a call to GetTypeFromHandle using the TypeToken of T...
  
  
Alk
</description><link>http://ayende.com/4299/can-you-hack-this-out#comment61</link><guid>http://ayende.com/4299/can-you-hack-this-out#comment61</guid><pubDate>Sat, 21 Nov 2009 07:57:30 GMT</pubDate></item><item><title>Vadi commented on Can you hack this out?</title><description>I think, the story comes from here ..
  
[gyrate.wordpress.com/.../context-bound-object-p...](http://gyrate.wordpress.com/2008/09/09/context-bound-object-part-ii/)</description><link>http://ayende.com/4299/can-you-hack-this-out#comment60</link><guid>http://ayende.com/4299/can-you-hack-this-out#comment60</guid><pubDate>Sat, 21 Nov 2009 07:35:05 GMT</pubDate></item><item><title>Mags commented on Can you hack this out?</title><description>Care to post the solution?
</description><link>http://ayende.com/4299/can-you-hack-this-out#comment59</link><guid>http://ayende.com/4299/can-you-hack-this-out#comment59</guid><pubDate>Sat, 21 Nov 2009 07:21:40 GMT</pubDate></item><item><title>anon commented on Can you hack this out?</title><description>[msdn.microsoft.com/en-us/magazine/cc164165.aspx](http://msdn.microsoft.com/en-us/magazine/cc164165.aspx)  
Again, sorry for pollution, but I can't edit the comment previous.
</description><link>http://ayende.com/4299/can-you-hack-this-out#comment58</link><guid>http://ayende.com/4299/can-you-hack-this-out#comment58</guid><pubDate>Sat, 21 Nov 2009 06:34:53 GMT</pubDate></item><item><title>anon commented on Can you hack this out?</title><description>Found 2 links about something like this. Sorry for polluting your comments section :)
  
  
[stackoverflow.com/.../how-do-i-intercept-a-meth...](http://stackoverflow.com/questions/25803/how-do-i-intercept-a-method-call-in-c)  
  
[www.developerfusion.com/.../3/](http://www.developerfusion.com/article/5307/aspect-oriented-programming-using-net/3/)</description><link>http://ayende.com/4299/can-you-hack-this-out#comment57</link><guid>http://ayende.com/4299/can-you-hack-this-out#comment57</guid><pubDate>Sat, 21 Nov 2009 06:32:45 GMT</pubDate></item><item><title>anon commented on Can you hack this out?</title><description>No clue how :)
  
But, can this somehow be used to provide a undo/redo facility that is transparent to the objects? Somehow catching the get/set of a property and also enhancing any property in a object with Undo() and Redo() methods?
</description><link>http://ayende.com/4299/can-you-hack-this-out#comment56</link><guid>http://ayende.com/4299/can-you-hack-this-out#comment56</guid><pubDate>Sat, 21 Nov 2009 06:27:43 GMT</pubDate></item><item><title>Martinho Fernandes commented on Can you hack this out?</title><description>So,  you're not gonna tell us?
</description><link>http://ayende.com/4299/can-you-hack-this-out#comment55</link><guid>http://ayende.com/4299/can-you-hack-this-out#comment55</guid><pubDate>Sat, 21 Nov 2009 01:42:33 GMT</pubDate></item><item><title>Alex Simkin commented on Can you hack this out?</title><description>@Whut  Transparent proxy is an object not a type. If you want its type, use GetType(), but I do not see what it gives you.
</description><link>http://ayende.com/4299/can-you-hack-this-out#comment54</link><guid>http://ayende.com/4299/can-you-hack-this-out#comment54</guid><pubDate>Fri, 20 Nov 2009 15:43:26 GMT</pubDate></item><item><title>Whut commented on Can you hack this out?</title><description>I haven't done any remoting or COM, so I'm just fooling around.
  
  
I'm trying to use proxy of Type class and using it as generic argument to CompositeRunner, but I can't just cast transparent proxy to Type;)
</description><link>http://ayende.com/4299/can-you-hack-this-out#comment53</link><guid>http://ayende.com/4299/can-you-hack-this-out#comment53</guid><pubDate>Fri, 20 Nov 2009 15:32:51 GMT</pubDate></item><item><title>Alkampfer commented on Can you hack this out?</title><description>If you do not use another appDomain, probably a possibility is to inherit from Type, override the ISAssignableFrom(Type) method and return true, this fools the Runner and makes the following test pass
  
  
if(!typeof(IRunner).IsAssignableFrom(typeof(T)))
  
            throw new InvalidOperationException("invalid type");
  
  
 then maybe it is possible with reflection.emit, to create a new class, and use your custom Type as type, so when the runner call typeof(T) it gets your MyType that return true when it ask for IsAssignableFrom, and it gets fooled.
  
  
But actually you still have another problem, because the IRunner is internal interface, and even with reflection Emit you cannot create a class that implements it, so you can make this class inherits from ContextBoundObject and use the standard IMessage AOP technique to intercept calls and redirect to a real AsseemblyRunner object, and now you can inject code before and after the call :)
  
  
I wish to have some time to check this path and verify where it leads :)
  
  
Alk.
  
</description><link>http://ayende.com/4299/can-you-hack-this-out#comment52</link><guid>http://ayende.com/4299/can-you-hack-this-out#comment52</guid><pubDate>Fri, 20 Nov 2009 11:08:39 GMT</pubDate></item><item><title>SeeR commented on Can you hack this out?</title><description>Hmm. I'm guessing that now, you know also the way to mock static methoda with Rhino Mocks :-)
</description><link>http://ayende.com/4299/can-you-hack-this-out#comment51</link><guid>http://ayende.com/4299/can-you-hack-this-out#comment51</guid><pubDate>Fri, 20 Nov 2009 10:05:31 GMT</pubDate></item><item><title>SeeR commented on Can you hack this out?</title><description>I remember your tweets about AppDomain.AssemblyResolve and hacking LINQ2SQL IProvider.
  
The best was "how to override System.RuntimeType at runtime using Reflection.Emit "
  
  
I guess this is it :-)
</description><link>http://ayende.com/4299/can-you-hack-this-out#comment50</link><guid>http://ayende.com/4299/can-you-hack-this-out#comment50</guid><pubDate>Fri, 20 Nov 2009 08:39:05 GMT</pubDate></item><item><title>Dennis commented on Can you hack this out?</title><description>[http://netasm.codeplex.com/](http://netasm.codeplex.com/)  
Atleast similar
</description><link>http://ayende.com/4299/can-you-hack-this-out#comment49</link><guid>http://ayende.com/4299/can-you-hack-this-out#comment49</guid><pubDate>Fri, 20 Nov 2009 07:30:41 GMT</pubDate></item><item><title>Dennis commented on Can you hack this out?</title><description>I saw an article the other day about hooking into the JIT and hijacking the jump table. But I cannot find the reference again :(
</description><link>http://ayende.com/4299/can-you-hack-this-out#comment48</link><guid>http://ayende.com/4299/can-you-hack-this-out#comment48</guid><pubDate>Fri, 20 Nov 2009 07:18:52 GMT</pubDate></item></channel></rss>