Strangenut

How to use the Namespace Alias in .net 3.5

Recently in one application I am working on, there was a ambiguous reference between two namespaces.  One was an object that was generated by our ORM tool (EntitySpaces), and one that was in the System.Web.Security namespace.  The class in both was Roles; a namespace alias was the perfect way to resolve this.  Setting a namespace alias is easy, in the using section do this:

 

using WebSec = System.Web.Security;

Then in the code where you have the ambigous reference, just use the WebSec namespace as shorthand like so:

_groupRoles = _orgManager.GetAccessGroupRoles(groupid, WebSec.Roles.IsUserInRole("SystemAdmin"));

 

.. and that's it!


Posted Feb 23 2009, 01:21 PM by dacrowlah
Powered by Community Server (Non-Commercial Edition), by Telligent Systems