public static bool TryParse(string path, out KeyPathTemplate keyPathTemplate) { if (path == null) { throw new ArgumentNullException(nameof(path)); } bool isValid = true; uint[] preIndices = null, postIndices = null; bool isPreIndex = true; int count = 0; List <uint> indices = new List <uint>(); foreach (var p in path .Split(new[] { '/' }, StringSplitOptions.RemoveEmptyEntries) .Where(p => p != "m")) { if (p == "*") { if (isPreIndex) { isPreIndex = false; count++; preIndices = indices.ToArray(); indices.Clear(); } else { isValid = false; } } else { isValid &= TryParseCore(p, out var i); if (isValid) { indices.Add(i); } count++; } } if (count > 255) { isValid = false; } isValid &= preIndices != null; if (!isValid) { keyPathTemplate = null; return(false); } postIndices = indices.ToArray(); keyPathTemplate = new KeyPathTemplate(preIndices, postIndices); return(true); }
public KeyPathTemplates(KeyPathTemplate customKeyPathTemplate) { this.customKeyPathTemplate = customKeyPathTemplate; List <DerivationFeature> derivationFeatures = new List <DerivationFeature>(); derivationFeatures.Add(DerivationFeature.Deposit); derivationFeatures.Add(DerivationFeature.Change); derivationFeatures.Add(DerivationFeature.Direct); if (customKeyPathTemplate != null) { derivationFeatures.Add(DerivationFeature.Custom); } this.derivationFeatures = derivationFeatures.ToArray(); }