Skip to content

Instantly share code, notes, and snippets.

@pema99
Created March 8, 2016 21:52
Show Gist options
  • Save pema99/c2e65efc65a90c1f7af8 to your computer and use it in GitHub Desktop.
Save pema99/c2e65efc65a90c1f7af8 to your computer and use it in GitHub Desktop.
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