Created
March 8, 2016 21:52
-
-
Save pema99/c2e65efc65a90c1f7af8 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 ImplicitTest | |
{ | |
public double Val { get; set; } | |
public ImplicitTest(double Val) | |
{ | |
this.Val = Val; | |
} | |
public static implicit operator int(ImplicitTest d) | |
{ | |
return (int)d.Val; | |
} | |
} | |
public class TestClass | |
{ | |
public int Val { get; set; } | |
public TestClass(int Val) | |
{ | |
this.Val = Val; | |
} | |
} | |
public class MainClass | |
{ | |
public static void Main() | |
{ | |
//Valid | |
new TestClass(5); | |
//Valid | |
new TestClass(new ImplicitTest(5.1)); | |
//Valid | |
Activator.CreateInstance(Type.GetType("ThisNamespace.TestClass"), 5); | |
//Invalid, throws System.MissingMethodException, this is my problem | |
Activator.CreateInstance(Type.GetType("ThisNamespace.TestClass"), new ImplicitTest(5.1)); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment