B"H
I know its a bit of a mouthful and may not be totally understandable. So here is an example of what I am trying to do.
public class TypeWithString
{
public string MyString { get; set; }
}
string s = "We Want Moshiach Now";
TypeWithString tws = new TypeWithString();
object o = s;
dynamic d = tws;
d.MyString = o;
This code surprisingly generates an error RuntimeBinderException: Cannot implicitly convert type 'object' to 'string'
.
Even though MyString
is of type string
and what is being held in o
is a string
.
is this a bug or a shortcoming in the DLR?
Is there a way to get around it?
If I do not know the type ahead of time. But I do know that it complies with duck typing. i.e. I know that it implements an unwritten interface. Is there anyway I can assign one variable to the other when they really are the correct type?
Thank you so much