【发布时间】:2017-06-04 01:43:05
【问题描述】:
XDocument document = XDocument.Load(@"C:\Users\mysvg\Documents\my.svg");
XNamespace ns = "http://www.w3.org/2000/svg";
var list = document.Root.Descendants(ns + "rect").Select(e => new {
Style = e.Attribute("style").Value.Substring(15, 7),
Transform = e.Attribute("transform")?.Value,
Width = e.Attribute("width").Value,
Height = e.Attribute("height").Value,
X = e.Attribute("x").Value
});
在 csharp 中它工作正常。 但是在统一视觉工作室中,我遇到了错误:
e.Attribute("transform")?.Value.Substring(18, 43)
功能“空传播运算符”在 C# 4 中不可用。请使用语言版本 6 或更高版本。
在 csharp 中我不需要更改任何内容。
我统一使用的视觉工作室(与 csharp 相同)是:14.0.24531.01 Update 3 和 visual c# 2015
也许我需要更改行检查是否为其他内容?
【问题讨论】:
-
这与 VS 无关,而是与 Unity 中使用的 C# 编译器有关 - 作为错误状态,它仅支持 C# 4.0。所以你必须编写“旧式”空检查,例如:
if(e.Attribute("transform") != null) -
@UnholySheep 但是我在哪里以及如何添加这个旧的空检查?我将行更改为原来的: Transform = e.Attribute("transform").Value.Substring(18, 43) 但现在在哪里添加 if(e.Attribute("transform") != null) i can' t 只需在 e.Attribute 行上方添加一行。
-
你把它放在 if 语句中。你还在为此苦恼吗?
-
@Programmer 是的,仍然不明白 if(e.Attribute("transform") != null) 的放置位置/方式