Ejemplo n.º 1
0
        public string Decompose(string compositionName, string value)
        {
            var composition = this.compositionProvider.GetComposition(compositionName);
            var textParts = new TextParts(composition);
            var stringParts = this.GetStringParts(textParts, new[] { String.Empty });
            var collection = textParts.Parts.Select((part, idx) => new {
                Part = part,
                Parameters = stringParts[idx],
                Index = idx
            }).ToArray();

            var index = 0;
            foreach (var set in collection)
            {
                if (set.Part.Parts.Any(str => str.Equals("$")))
                    break;

                index++;
                var subPart = set.Parameters.Where(value.StartsWith).Aggregate(String.Empty,
                    (current, part) => part.Length > current.Length ? part : current);

                value = value.Substring(subPart.Length);
            }

            foreach (var set in collection.Skip(index).Reverse())
            {
                var subPart = set.Parameters.Where(value.EndsWith).Aggregate(String.Empty,
                    (current, part) => part.Length > current.Length ? part : current);

                value = value.Substring(0, value.Length - subPart.Length);
            }

            return value;
        }
Ejemplo n.º 2
0
 private string[][] GetStringParts(TextParts textParts, IEnumerable<string> looseParameters)
 {
     return textParts.Parts.Select(
         textPart => textPart.IsParameter
             ? this.GetParametersWithPart(textPart, looseParameters).ToArray()
             : textPart.Parts).ToArray();
 }
Ejemplo n.º 3
0
        private IEnumerable<string> GetCompositionStrings(string composition, IEnumerable<string> looseParameters)
        {
            var textParts = new TextParts(composition);
            var stringParts = this.GetStringParts(textParts, looseParameters);

            // ReSharper disable once CoVariantArrayConversion
            return Compose(stringParts);
        }