Here are my classes definitions:
public abstract class AbstractEntity : ...
public partial class AbstractContactEntity : AbstractEntity, ...
public sealed class EntityCollectionProxy<T> : IList<T>, System.Collections.IList
where T : AbstractEntity
Now I get an object from a delegate and I want to cast it, and it doesn't work as I expect it to.
var obj = resolver.DynamicInvoke (this.entity);
var col = obj as EntityCollectionProxy<AbstractEntity>;
obj
is of type EntityCollectionProxy<AbstractContactEntity>
.
But col
is null.
If I try the regular casting (var col = (Entity...) obj
) I get an exception.
I would expect that it work since the types are coherent.
What do I miss?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…