Resolving an ambiguous reference

C#

C# Problem Overview


I'm trying to create a manager class to use with my charting tool, the problem is the tool I use, uses the same names for both a 3d and 2d charts which is resulting in ambiguous reference when I try to add the 2d library.. any ideas how best to resolve this?

For example,

using tool.2dChartLib;
using tool.3dChartLib;

BorderStyle is a member of both of these

I've tried casting the areas where I use BorderStyle. I suppose it could work if i just reference tool but then that would mean I'd have hundreds of tool.class lines instead of class

C# Solutions


Solution 1 - C#

If the types with the same name exist in both namespaces, you have a couple of options:

  1. If the number of types is small, create an alias for that type:

    using BorderStyle3d = tool.3dChartLib.BorderStyle;

  2. If the number of types is large, you can create an alias for the namespace:

    using t3d = tool.3dChartLib;

Then in your code...

t3d.BorderStyle

Solution 2 - C#

You can use full type names, or create aliases:

using 2dBorderStyle = tool.2dChartLib.BorderStyle;

Solution 3 - C#

Use namespace alias

using twoDimensionLib = tool.2dChartLib;
using threeDimensionLib tool.3dChartLib;

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionSayseView Question on Stackoverflow
Solution 1 - C#Adam RobinsonView Answer on Stackoverflow
Solution 2 - C#Sergey BerezovskiyView Answer on Stackoverflow
Solution 3 - C#TilakView Answer on Stackoverflow