开发者

Is it possible to know if a System.Object was actually specified as dynamic (C#)?

I have a couple of scenarios that cover this, but I'll write specifically about the one that's easier to demonstrate

I have a factory interface:

interface IFactory
{
  Create<T>();
}

And a piece of code that uses it thus:

public static void func(IFactory f)
{
  var o = f.Creat开发者_如何学运维e<dynamic>();
}

Now, in an implementation of Create<T>() - is is there any way, via reflection over T, to determine if the caller is intending dynamic dispatch on their object as opposed to a straightforward object? I have a class where being able to make that distinction would be quite useful...

I've had a look to see if I can find attributes on the type or something like that, but no joy.


dynamic is in the eye of the caller only, so no; that isn't possible AFAIK. As far as Create is concerned it is just object.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜