gpt4 book ai didi

c# - 转换来自不同 namespace 的相同对象?

转载 作者:行者123 更新时间:2023-11-30 17:08:10 25 4
gpt4 key购买 nike

这些是错误:

Error   1   Cannot implicitly convert type 'Plantool.xRoute.Point' to 'Plantool.xMap.Point' 
Error 2 Cannot implicitly convert type 'Plantool.xRoute.Point' to 'Plantool.xMap.Point'
Error 3 Cannot implicitly convert type 'Plantool.xRoute.LineString' to 'Plantool.xMap.LineString'

我有这个带有命名空间的代码。

using Plantool; //Contains xMap, xServer, xLocate

这就是有问题的功能。

    /* createMap()
* Input: WaypointDesc[], Route
* Output: string mapURL
* Edited 21/12/12 - Davide Nguyen
*/
private static string createMap(xRoute.WaypointDesc[] waypointDesc, xRoute.Route route)
{
#region boundingBox
// Set boundingBox fand use corners from the calculated route
xMap.BoundingBox boundingBox = new xMap.BoundingBox();
boundingBox.leftTop = route.totalRectangle.rightTop;
boundingBox.rightBottom = route.totalRectangle.leftBottom;
#endregion

#region mapParams
// Build mapParams
xMap.MapParams mapParams = new xMap.MapParams();
mapParams.showScale = true;
mapParams.useMiles = false;
#endregion

#region imageInfo
// Create imageInfo and set the frame size and image format. NOTE: 1052; 863
xMap.ImageInfo imageInfo = new xMap.ImageInfo();
imageInfo.format = xMap.ImageFileFormat.PNG;
imageInfo.height = 1052;
imageInfo.width = 863;
imageInfo.imageParameter = "";
#endregion

#region layers
// Create a line from the calculated route
xMap.LineString[] lineStrings = new xMap.LineString[] { route.polygon };
xMap.Lines[] lines = new xMap.Lines[1];
xMap.LineOptions options = new xMap.LineOptions();
xMap.LinePartOptions partoptions = new xMap.LinePartOptions();
partoptions.color = new xMap.Color();
partoptions.visible = true;
partoptions.width = -10;
options.mainLine = partoptions;

lines[0] = new xMap.Lines();
lines[0].wrappedLines = lineStrings;
lines[0].options = options;

// Define customLayer that contains the object lines and set layers.
xMap.CustomLayer customLayer = new xMap.CustomLayer();
customLayer.visible = true;
customLayer.drawPriority = 100;
customLayer.wrappedLines = lines;
customLayer.objectInfos = xMap.ObjectInfoType.NONE;
customLayer.centerObjects = true;
xMap.Layer[] layers = new xMap.Layer[] { customLayer };
#endregion

#region includeImageInResponse
// Set argument includeImageInResponse to false (default).
Boolean includeImageInResponse = false;
#endregion

// Return object map using the following method.
xMap.Map map = xMapClient.renderMapBoundingBox(boundingBox, mapParams, imageInfo, layers, includeImageInResponse, null);

// Retrieve the image
string result = "http://" + map.image.url;

// Return the drawn map
return result;
}

问题在于 boundingBox 对象和 lineString 对象。 route.totalRectangle 包含来自 xRoute 命名空间的 Point 对象,它与 xMap 的相同。无论如何复制或转换它?

这个问题在 java 示例中似乎不会发生,但在 C# 中会发生。我相信,如果我能解决这个错误,其他错误也会得到解决。我已经在 API 上搜索了我的屁股,但它可能对你有帮助:

仍在挖掘自己。

最佳答案

在 C# 中,您不能从一种类型转换为另一种类型,即使它们在所有目的上都是相同的,除非复制所有属性等,除非 implicit。转换存在。

因此您可以编写一个隐式转换运算符,如上面的链接所示,或者您可以使用像 AutoMapper 这样的工具在两个对象之间复制

关于c# - 转换来自不同 namespace 的相同对象?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13987205/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com