phil-campbell submitted these extension methods

  • WhereIf

    When building a LINQ query, you may need to involve optional filtering criteria. Avoids if statements when building predicates & lambdas for a query. Useful when you don't know at compile time whether a filter should apply. Borrowed from Andrew Robinson.
    C# System.Collections.Generic.IEnumerable<T> Phil Campbell
  • Randomize

    OrderBy() is nice when you want a consistent & predictable ordering. This method is NOT THAT! Randomize() - Use this extension method when you want a different or random order every time! Useful when ordering a list of things for display to give each a fair chance of landing at the top or bottom on each hit. {customers, support techs, or even use as a randomizer for your lottery ;) }
    C# System.Collections.Generic.IEnumerable<T> Phil Campbell
  • IsDate

    Wraps DateTime.TryParse() and all the other kinds of code you need to determine if a given string holds a value that can be converted into a DateTime object.
    C# System.String Phil Campbell
  • EqualsAny

    Check that the given string is in a list of potential matches. Inspired by StackOverflow answer
    C# System.String Phil Campbell
  • Or

    Returns the first string with a non-empty non-null value.
    C# System.String Phil Campbell
  • Length

    Determines how many numbers compose the integer if it was represented as a string.
    C# System.Int32 Phil Campbell
  • HasMultipleInstancesOf

    Determines whether a string has multiple occurrences of a particular character. May be helpful when parsing file names, or ensuring a particular string has already contains a given character. This may be extended to use strings, rather than a char.
    C# System.String Phil Campbell