内部类被对象掩盖 [英] Internal class masked by object

查看:74
本文介绍了内部类被对象掩盖的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设(B)类的公共功能具有返回行:

Assume that class (B)'s public function has the return line:

return (object)(new List<A>{Some elements})

其中A是内部密封类。我无法更改A或B的代码。

where A is an internal and sealed class. I cannot change the code of A or B.

在B中调用此函数后,如何找到该列表的第一个元素。 C#不允许我将该列表转换回 List< A> ,因为A是内部的。

After I call this function in B, how do I find the first element of that list. C# does not let me cast that list back into List<A> because A is internal.

推荐答案


  1. 仅仅因为您可以阅读源代码或反汇编代码,所以您不应该依赖当前的实现,而应该尝试使用公共接口。

  1. Just because you can read the source code or disassemble the code, you should not rely on the current implementation, rather try to use the public interface.

List< A> 实现非通用的 IList ,因此如果您确实遇到麻烦,可以将其退回 IEnumerable IList

List<A> implements the non-generic IList, so you can cast back to IEnumerable or IList if you really look for trouble.

这篇关于内部类被对象掩盖的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆