-
-
Save SriramSakthivel/b2bb3ea2e2baf4c203f1 to your computer and use it in GitHub Desktop.
Snippet to show that new operator can return null.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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