Exemplo n.º 1
0
        private static ResourceValue GetValue(string resourceName, string resourceValue)
        {
            var value = new ResourceValue {
                Name = resourceName, Value = resourceValue
            };

            value.HasFormat = FormatExpression.IsMatch(resourceValue);

            // Parse parameter names
            if (value.HasFormat)
            {
                value.Format.AddRange(FormatExpression
                                      .Matches(resourceValue)
                                      .OfType <Match> ()
                                      .Select(match => match.Groups["name"].Value)
                                      .Distinct());
            }

            int index;

            // Find if there are any index values
            value.IsIndexed = value.Format.Any(format => int.TryParse(format, out index));

            // If there are mixed names and indexes, treat it as unformatted.
            if (value.IsIndexed && value.Format.Any(format => !int.TryParse(format, out index)))
            {
                value.HasFormat = false;
            }

            return(value);
        }
Exemplo n.º 2
0
		private static ResourceValue GetValue (string resourceName, string resourceValue)
		{
			var value = new ResourceValue { Name = resourceName, Value = resourceValue };

			value.HasFormat = FormatExpression.IsMatch (resourceValue);

			// Parse parameter names
			if (value.HasFormat) {
				value.Format.AddRange (FormatExpression
					.Matches (resourceValue)
					.OfType<Match> ()
					.Select (match => match.Groups["name"].Value)
					.Distinct ());
			}

			int index;
			// Find if there are any index values
			value.IsIndexed = value.Format.Any (format => int.TryParse (format, out index));

			// If there are mixed names and indexes, treat it as unformatted.
			if (value.IsIndexed && value.Format.Any (format => !int.TryParse (format, out index)))
				value.HasFormat = false;

			return value;
		}