Skip to content

Instantly share code, notes, and snippets.

@SriramSakthivel
Last active August 29, 2015 14:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save SriramSakthivel/b2bb3ea2e2baf4c203f1 to your computer and use it in GitHub Desktop.
Save SriramSakthivel/b2bb3ea2e2baf4c203f1 to your computer and use it in GitHub Desktop.
Snippet to show that new operator can return null.
public class Program
{
static void Main(string[] args)
{
new SomeClass().DoSomething();
Console.ReadLine();
}
}
[EvilProxy]
public class SomeClass : ContextBoundObject
{
public void DoSomething()
{
//Some code
Console.WriteLine("this == null ? : {0}", this == null);
//Some more code
Console.WriteLine(this.GetType());//kaboom!!
}
}
[AttributeUsage(AttributeTargets.All, Inherited = false, AllowMultiple = true)]
public class EvilProxyAttribute : ProxyAttribute
{
public override MarshalByRefObject CreateInstance(Type serverType)
{
return null;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment