Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
108 views
in Technique[技术] by (71.8m points)

c# - Resolving an ambiguous reference

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

Question&Answers:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...