这是一个非常奇怪的问题,真的让我很紧张。我有一个简单的C#ServicesManager类,我正在做。但是我得到这个问题的原因除了微软之外绝对没有任何明显的原因(我作为一个程序员的年代已经让我非常认同他们无尽的愚蠢)。无论如何,这里是有问题的功能:功能内部找不到功能参数
/// <summary>
/// This function checks if the ServicesManager contains a service of the specified type or not.
/// </summary>
/// <param name="serviceType">The type of service to check for.</param>
/// <returns>True if a service of the specified type is found, or false otherwise.</returns>
public bool Contains(Type serviceType)
{
bool result = false;
Type t = serviceType;
foreach (ISE_Service s in m_ServicesList)
{
if (s is serviceType)
{
result = true;
break;
}
}
return result;
}
ISE_Service只是一个接口,表示一个服务类。上面的函数只是检查服务管理器中是否已经存在指定类型的服务。
错误列表显示以下错误,始终突出“的serviceType”中的if语句有一个红色的波浪线:
错误3类型或命名空间名称“的serviceType”找不到(是)C:\ MegafontProductions \ SpiritEngine \ SpiritEngine \ Source \ ApplicationLayer \ ServicesManager.cs 55
这个错误没有任何意义。这是这个功能的一个参数。据我可以告诉这个问题是由is关键字或类型Type造成的。正如你所看到的,参数serviceType在循环之上被访问得很好。那么它是如何突然在if语句中找不到的呢?
这究竟是微软的错? – Arran
不记录ServiceLocator吗? http://msdn.microsoft.com/en-us/library/ff921142%28v=pandp.20%29.aspx – C4stor