【发布时间】:2020-05-03 21:34:39
【问题描述】:
我无法实际访问此无证类中的成员:BingMapsRESTToolkit.Response
各个地方的代码(例如)Bing Maps REST Services Toolkit - Access Value Outside of Delegate 似乎从 MSDN 复制了非工作示例。
例如,此方法无法访问 Response 对象中包含的 Snapped 坐标数组。将 rez 分配给响应转换的行给了我们一个空值。
private List<Coordinate> MapSnaps(List<Coordinate> coordinates)
{
// Build our request object
var req = new SnapToRoadRequest();
req.BingMapsKey = _sessionKey;
req.UserRegion = "US";
req.SpeedUnit = SpeedUnitType.MPH;
req.TravelMode = TravelModeType.Driving;
req.Points = coordinates;
var response = req.Execute().GetAwaiter().GetResult();
if(response != null &&
response.ResourceSets != null &&
response.ResourceSets.Length > 0 &&
response.ResourceSets[0].Resources != null &&
response.ResourceSets[0].Resources.Length > 0)
{
// rez gets nothing, results in null because the two objects are nothing alike
var rez = response.ResourceSets[0].Resources[0] as BingMapsRESTToolkit.Location;
// Snaps has 69 SnappedPoint items, but the member as shown in the debug window
// SnappedPoints under snaps cant be accessed in code - just in debugger
var snaps = response.ResourceSets[0].Resources[0]; //
Console.WriteLine("-.-"); // <-- breakpoint here
}
// TODO: Once we get this response snafu sorted, convert and return
// matching list of road-snapped coordinates to caller...
return ConvertToCoords(response);
}
当我使用 Visual Studio 2019 进行调试时,它清楚地显示有 69 个“SnappedPoint”值等待在 response.ResourceSet[0].Resources[0] 中使用——但我无法找到它们。以下是调试器显示的内容:
快照 BingMapsRESTToolkit.SnappedPoint[69]
SnappedPoints BingMapsRESTToolkit.SnappedPoint[69]
BoundingBox null
Type null
Each member of the SnappedPoints array contains:
Coordinate {Lat:double, Lon:double}
Index int
Name String for name of road
SpeedLimit double?
TruckSpeedLimit double?
尝试: snaps.SnappedPoints[x] 不起作用,因为该成员不存在。 BoundingBox 和 Type 都可以访问并设置为 null,但我无法访问 SnappedPoints 的内容。没有智能感知,手动输入成员名称只会导致错误。
我在这里做错了吗?
【问题讨论】: