C#: Use a namespace for a specific block of code

cnamespaces

I just have a point of curiosity. I'm working with SSRS and calling its SOAP methods. I've got stubs generated / Web references created and that's all working fine and I can make web service calls OK.

The problem: the two classes generated from the WSDLs, ReportService2005 and ReportExecution, have some overlapping class definitions, such as ParameterValue, DataSourceCredentials, ReportParameter.

In C#, is there a way of saying, "For this block of code in the method, use this namespace?"

Pseudo / mostly build-error code:

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

I understand that I can just write out of the full name, ReportService2005.ParameterValue[] values = null. Or I can alias the two classes at the top before my class/controller declaration. It's just something I'm curious about.

Best Answer

As others have written, I don't think this is possible. But what you can do, is to alias the full namespaces instead of each single class you want to use, e.g:

using rs = ReportService2005;
using re = ReportExecution;

// ...

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