string.AddDashes()

Here are the examples of the csharp api class string.AddDashes() taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.

5 Examples 7

1. Example

Project: stripe-dotnet
Source File: StringExtensions.cs
View license
public static IEnumerable<string> GetNameVariants(this string name, CultureInfo culture)
		{
			if (String.IsNullOrEmpty(name))
				yield break;

			yield return name;

			// try camel cased name
			yield return name.ToCamelCase(culture);

			// try lower cased name
			yield return name.ToLower(culture);

			// try name with underscores
			yield return name.AddUnderscores();

			// try name with underscores with lower case
			yield return name.AddUnderscores().ToLower(culture);

			// try name with dashes
			yield return name.AddDashes();

			// try name with dashes with lower case
			yield return name.AddDashes().ToLower(culture);
		}

2. Example

View license
IEnumerable<XElement> GetDescendentsByName(XElement root, XName name)
        {            
            var lowerName = XName.Get(name.LocalName.ToLower(), name.NamespaceName);
            var camelName = XName.Get(name.LocalName.ToCamelCase(), name.NamespaceName);
            var dashName = XName.Get(name.LocalName.AddDashes().ToLower(), name.NamespaceName);

            var descendants = root.Descendants(name);

            if (descendants != null && descendants.Count() < 1)
            {
                descendants = root.Descendants(lowerName);
            }

            if (descendants != null && descendants.Count() < 1)
            {
                descendants = root.Descendants(camelName);
            }

            if (descendants != null && descendants.Count() < 1)
            {
                descendants = root.Descendants(dashName);
            }                  

            return descendants;
        }

3. Example

Project: RestSharp
Source File: StringExtensions.cs
View license
public static IEnumerable<string> GetNameVariants(this string name, CultureInfo culture)
        {
            if (string.IsNullOrEmpty(name))
                yield break;

            yield return name;

            // try camel cased name
            yield return name.ToCamelCase(culture);

            // try lower cased name
            yield return name.ToLower(culture);

            // try name with underscores
            yield return name.AddUnderscores();

            // try name with underscores with lower case
            yield return name.AddUnderscores().ToLower(culture);

            // try name with dashes
            yield return name.AddDashes();

            // try name with dashes with lower case
            yield return name.AddDashes().ToLower(culture);

            // try name with underscore prefix
            yield return name.AddUnderscorePrefix();

            // try name with underscore prefix, using camel case
            yield return name.ToCamelCase(culture).AddUnderscorePrefix();

            // try name with spaces
            yield return name.AddSpaces();

            // try name with spaces with lower case
            yield return name.AddSpaces().ToLower(culture);
        }

4. Example

View license
private XAttribute GetAttributeByName(XElement root, XName name)
        {
            var lowerName = XName.Get(name.LocalName.ToLower(), name.NamespaceName);
            var camelName = XName.Get(name.LocalName.ToCamelCase(), name.NamespaceName);
            var dashName = XName.Get(name.LocalName.AddDashes().ToLower(), name.NamespaceName);

            if (root.Attribute(name) != null)
            {
                return root.Attribute(name);
            }

            if (root.Attribute(lowerName) != null)
            {
                return root.Attribute(lowerName);
            }

            if (root.Attribute(camelName) != null)
            {
                return root.Attribute(camelName);
            }

            if (root.Attribute(dashName) != null)
            {
                return root.Attribute(dashName);
            }

            // try looking for element that matches sanitized property name
            var element = root.Attributes().FirstOrDefault(d => d.Name.LocalName.RemoveUnderscoresAndDashes() == name.LocalName);
            if (element != null)
            {
                return element;
            }

            return null;
        }

5. Example

View license
private XElement GetElementByName(XElement root, XName name)
        {
            var lowerName = X/n ..... /n //View Source file for more details /n }