我只是有好奇心.我正在使用SSRS并调用其SOAP方法.我已经生成了存根/创建了Web引用,并且一切正常,我可以使Web服务调用正常.
问题:从WSDL,ReportService2005和ReportExecution生成的两个类有一些重叠的类定义,例如ParameterValue,DataSourceCredentials,ReportParameter.
在C#中,有没有办法说,"对于方法中的这个代码块,使用这个命名空间?"
伪/主要是构建错误代码:
use-this-namespace (ReportService2005)
{
ParameterValue[] values = null;
DataSourceCredentials[] credentials = null;
ReportParameter[] parameters;
}
Run Code Online (Sandbox Code Playgroud)
我知道我可以写出全名,ReportService2005.ParameterValue [] values = null.或者我可以在我的类/控制器声明之前在顶部对两个类进行别名.这只是我很好奇的事情.
M4N*_*M4N 14
正如其他人所写,我认为这是不可能的.但是你可以做的是将完整的命名空间别名,而不是你想要使用的每个单独的类,例如:
using rs = ReportService2005;
using re = ReportExecution;
// ...
rs.ParameterValue[] values = null;
rs.DataSourceCredentials[] credentials = null;
rs.ReportParameter[] parameters;
re.ParameterValue v2 = ...;
Run Code Online (Sandbox Code Playgroud)
另一个鲜为人知的C#功能可能会让你感兴趣,并且类似于Martin的回答,它基本上是对Imports块中的类进行别名:
using ListOfDictionary = System.Collections.Generic.List<System.Collections.Generic.Dictionary<string, string>>;
Run Code Online (Sandbox Code Playgroud)
并声明为
ListOfDictionary list = new ListOfDictionary();
Run Code Online (Sandbox Code Playgroud)
注意此功能和示例在另一个问题中找到; 具体来说:C#的隐藏功能?