-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
49 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,6 +24,7 @@ | |
"AppVeyor", | ||
"AzurePipelines", | ||
"Bamboo", | ||
"Bitbucket", | ||
"Bitrise", | ||
"GitHubActions", | ||
"GitLab", | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 45 additions & 0 deletions
45
src/Resharper.ConfigurationSense/Extensions/JPropertyExtensions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
using System.Collections.Generic; | ||
|
||
using Newtonsoft.Json.Linq; | ||
|
||
namespace Resharper.ConfigurationSense.Extensions | ||
{ | ||
public static class JPropertyExtensions | ||
{ | ||
public static string GetSettingsPath(this JProperty property) | ||
{ | ||
if (property.Parent == null) | ||
{ | ||
return string.Empty; | ||
} | ||
|
||
var positions = new List<string>(); | ||
JToken previous = null; | ||
for (JToken current = property; current != null; current = current.Parent) | ||
{ | ||
switch (current.Type) | ||
{ | ||
case JTokenType.Property: | ||
var prop = (JProperty)current; | ||
positions.Add(prop.Name); | ||
break; | ||
case JTokenType.Array: | ||
case JTokenType.Constructor: | ||
if (previous != null) | ||
{ | ||
int index = ((IList<JToken>)current).IndexOf(previous); | ||
|
||
positions.Add(index.ToString()); | ||
} | ||
break; | ||
} | ||
|
||
previous = current; | ||
} | ||
|
||
positions.Reverse(); | ||
|
||
return string.Join(":", positions); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters