How to access a type with same fully qualified nam

2019-07-31 22:49发布

问题:

I need to refer to both the assemblies PresentationFramework.Classic and PresentationFramework.Luna and I have a situation where I need to use the Microsoft.Windows.Themes.DataGridHeaderBorder type. But this gives error as both the assemblies have this type defined. I mean, I can do with referring to any of them (Classic or Luna) for this type, it's just a simple Datagrid, where I need to check if the DataGridHeaderBorder is clicked.

Thanks in advance.

回答1:

This is the sort of situation that external assembly aliases are intended to address. You can also specify the alias for a reference using the "Aliases" property in the reference's properties sheet in Visual Studio if command line compilation isn't your thing. See http://blogs.msdn.com/b/ansonh/archive/2006/09/27/774692.aspx for a full example.



回答2:

Try this:

using Clasic = PresentationFramework.Classic;
using Luna = PresentationFramework.Luna;



namespace Test1
{
    class Program
    {
        static void Main(string[] args)
        {
            Clasic.Microsoft.Windows.Themes.DataGridHeaderBorder bClassic;
            Luna.Microsoft.Windows.Themes.DataGridHeaderBorder bLuna;
        }
    }
}