internal static string GetValue(this GraphNodeId id, GraphNodeIdName idPartName) { if (idPartName == CodeGraphNodeIdName.Assembly || idPartName == CodeGraphNodeIdName.File) { try { Uri value = id.GetNestedValueByName <Uri>(idPartName); // for idPartName == CodeGraphNodeIdName.File it can be null, avoid unnecessary exception if (value == null) { return(null); } // Assembly and File are represented by a Uri, extract LocalPath string from Uri return((value.IsAbsoluteUri ? value.LocalPath : value.ToString()).Trim('/')); } catch { // for some node ids Uri might throw format exception, thus try to get string at least return(id.GetNestedValueByName <string>(idPartName)); } } else { return(id.GetNestedValueByName <string>(idPartName)); } }
private string GetPartialValueFromGraphNodeId(GraphNodeId id, GraphNodeIdName idPartName) { if (idPartName == CodeGraphNodeIdName.Assembly || idPartName == CodeGraphNodeIdName.File) { try { var value = id.GetNestedValueByName <Uri>(idPartName); // Assembly and File are represented by a Uri, extract LocalPath string from Uri return((value.IsAbsoluteUri ? value.LocalPath : value.ToString()).Trim('/')); } catch { // for some node ids Uri might throw format exception, thus try to get string at least return(id.GetNestedValueByName <string>(idPartName)); } } else { return(id.GetNestedValueByName <string>(idPartName)); } }
internal static string GetFileName(this GraphNodeId nodeId) { Uri fileName = nodeId.GetNestedValueByName <Uri>(CodeGraphNodeIdName.File); if (fileName != null) { return(fileName.LocalPath); } var start = nodeId.LiteralValue.IndexOf("File=file:///") + 13; if (start < 0) { return(null); } var end = nodeId.LiteralValue.IndexOf(')', start); if (end < 0) { return(null); } return(nodeId.LiteralValue.Substring(start, end - start)); }
internal static string GetFileName(this GraphNodeId nodeId) { Uri fileName = nodeId.GetNestedValueByName <Uri>(CodeGraphNodeIdName.File); return((fileName != null) ? fileName.LocalPath : null); }