Suppose I have the following:
var t = typeof(Foo).MakeByRefType();
are there any ways to convert the result back to typeof(Foo)
?
Honestly, the only way I've found is this:
var t = typeof(Foo).MakeByRefType();
string name = t.Name.Trim('&');
string asmQualified = t.AssemblyQualifiedName.Replace(t.Name, name);
var v = Type.GetType(asmQualified);
Other methods I've tried doesn't seems to work:
- Are there better ways to do this?
- If this is the only way, are there situations in which it can fail (maybe with dynamically generated assemblies)?
Aucun commentaire:
Enregistrer un commentaire