Condition = value;
break;
default:
- throw new InvalidProjectFileException (string.Format (
+ throw new InvalidProjectFileException (Location, null, string.Format (
"Attribute \"{0}\" is not known on node \"{1}\" [type {2}].", name, XmlName,
GetType ()));
}
internal void FillLocation (XmlReader reader)
{
-#if NET_4_5
var l = reader as IXmlLineInfo;
if (l != null && l.HasLineInfo ())
Location = new ProjectElementLocation (reader.BaseURI, l);
if (reader.MoveToAttribute ("Label") && l.HasLineInfo ())
LabelLocation = new ProjectElementLocation (reader.BaseURI, l);
reader.MoveToElement ();
-#endif
}
class ProjectElementLocation : ElementLocation
{
reader.Read ();
reader.MoveToContent ();
+ FillLocation (reader);
if (reader.LocalName != XmlName || reader.NamespaceURI != MSBuildNamespace)
throw CreateError (reader, string.Format ("Unexpected XML {0} \"{1}\" in namespace \"{2}\" appeared, while \"{3}\" in namespace \"{4}\" is expected.",
reader.NodeType, reader.LocalName, reader.NamespaceURI, XmlName, MSBuildNamespace), -1);
- FillLocation (reader);
while (reader.MoveToNextAttribute ()) {
LoadAttribute (reader.Name, reader.Value);
}
public string HelpKeyword { get; private set; }
public int LineNumber { get; private set; }
public override string Message {
- get { return ProjectFile == null ? base.Message : base.Message + " " + ProjectFile; }
+ get { return ProjectFile == null ? base.Message : base.Message + " " + GetLocation (); }
}
public string ProjectFile { get; private set; }
+
+ string GetLocation ()
+ {
+ string start = LineNumber == 0 ? string.Empty : ColumnNumber > 0 ? string.Format ("{0},{1}", LineNumber, ColumnNumber) : string.Format ("{0}", LineNumber);
+ string end = EndLineNumber == 0 ? string.Empty : EndColumnNumber > 0 ? string.Format (" - {0},{1}", EndLineNumber, EndColumnNumber) : string.Format (" - {0}", EndLineNumber);
+ return LineNumber == 0 ? ProjectFile : String.Format (" at: {0} ({1}{2})", ProjectFile, start, end);
+ }
}
}