从外部访问内部成员
在SolutionA(命名空间名称)中,我从另一个类(Engine)调用内部类(ClassA)的成员(functionA()),并通过接口(IClassA)调用该类。
IClassA 声明了这个函数 引擎 调用此函数并使用另一个方法(在本例中为 smame 方法名称)。
因此,如果我想在另一个解决方案中调用这个内部成员。
所以在解决方案B中
我可以这样做:
using SolutionA;
IClassA iA;
iA = new Engine();
iA.fuctionA();
我想当我在 iA 之后执行 [.] 时它应该给出 functionA ,但是智能感知没有给出..这里出了什么问题?
为什么我在 SolutionB 中没有得到 functionA?
有关我的架构的更多信息:
//IClassA.cs
namespace namespaceA
{
internal class ClassA
{
public string FunctionA(){}
}
}
//Engine.cs
namespace namespaceA
{
public class Engine() : IClassA()
{
public IClassA.FunctionA(){}
}
}
// IClassA.cs
namespace namespaceA
{
public interface IClassA()
{
string FunctionA(string data);
}
}
//ClassB.cs
namespace namespaceB
{
using namespaceA;
internal class Classb
{
IClassA engine = new namespaceA.Engine();
engine.FunctionA(); //here i am unable to get fuuction
}
}
In SolutionA (Namespace name), I am calling a a memeber (functionA()) of internal class (ClassA )from another class (Engine)and this class through interface (IClassA).
IClassA declares this function
Engine Calls this function and using another method (smame method name in this case).
So if i want to call this internal member in another solution.
So in Solution B
I can do this :
using SolutionA;
IClassA iA;
iA = new Engine();
iA.fuctionA();
I guess it should give functionA when i do a [.] after iA , but intellisense is not giving ..whats wrong here?
Why i am not getting the functionA in SolutionB?
More info about my architechure:
//IClassA.cs
namespace namespaceA
{
internal class ClassA
{
public string FunctionA(){}
}
}
//Engine.cs
namespace namespaceA
{
public class Engine() : IClassA()
{
public IClassA.FunctionA(){}
}
}
// IClassA.cs
namespace namespaceA
{
public interface IClassA()
{
string FunctionA(string data);
}
}
//ClassB.cs
namespace namespaceB
{
using namespaceA;
internal class Classb
{
IClassA engine = new namespaceA.Engine();
engine.FunctionA(); //here i am unable to get fuuction
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
IClassA
接口是否声明了该函数?我的猜测是事实并非如此。鉴于iA
的编译时类是IClassA
,编译器(和 Intellisense)将只允许您使用IClassA
的成员。Does the
IClassA
interface declare the function? My guess is that it doesn't. Given that the compile-time class ofiA
isIClassA
, the compiler (and Intellisense) will only let you use members ofIClassA
.这不太可能是您的问题,但我会提到它,因为这是另一个可能导致您的症状的问题。如果
functionA
具有[ EditorBrowsable(EditorBrowsableState.Never)]
属性,当您位于不同的程序集中时,它不会显示在 Intellisense 中。但在这种情况下,忽略 Intellisense 并使用 functionA 仍然允许程序编译。It is highly unlikely that this is your problem, but I'll mention it because it is another problem that could cause your symptoms. If
functionA
has the[EditorBrowsable(EditorBrowsableState.Never)]
attribute, it will not show up in Intellisense when you are in a different assembly. Though in that situation, ignoring Intellisense and usingfunctionA
would still allow the program to compile.