C#:对特定代码块使用命名空间?

标签 c# namespaces

我只是有点好奇。我正在使用 SSRS 并调用它的 SOAP 方法。我已经生成了 stub /创建了 Web 引用,一切正常,我可以正常调用 Web 服务。

问题:从 WSDL 生成的两个类 ReportService2005 和 ReportExecution 有一些重叠的类定义,例如 ParameterValue、DataSourceCredentials、ReportParameter。

在 C# 中,有没有一种说法,“对于方法中的这个代码块,使用这个命名空间?”

伪/主要是构建错误代码:

use-this-namespace (ReportService2005)
{
    ParameterValue[] values = null;
    DataSourceCredentials[] credentials = null;
    ReportParameter[] parameters;
}

我知道我可以只写出全名,ReportService2005.ParameterValue[] values = null。或者我可以在类/ Controller 声明之前为顶部的两个类添加别名。这只是我很好奇的事情。

最佳答案

正如其他人所写,我认为这是不可能的。但是您可以做的是为完整的命名空间添加别名,而不是为您要使用的每个类添加别名,例如:

using rs = ReportService2005;
using re = ReportExecution;

// ...

rs.ParameterValue[] values = null;
rs.DataSourceCredentials[] credentials = null;
rs.ReportParameter[] parameters;
re.ParameterValue v2 = ...;

关于C#:对特定代码块使用命名空间?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3144124/

相关文章:

c# - Reactive Extension-新版本中旧版本的问题使用方法

c# - WPF ListBox 将 ItemsSource 与 MVVM-light 绑定(bind)

javascript - Socket.IO 命名空间,调用未定义的函数 .of()

XMLStarlet 命名空间定义

c++ - 将成员函数从基类移动到派生类会无缘无故地破坏程序

wpf - 如何在 WPF XAML 中声明命名空间?

c# - 从组合框中删除边框

C#文件关联的正确方法

c# - 标签助手未在 ASP.NET Core 2 中处理

c++ - 向许多文件添加 namespace 声明?