/// <summary> /// Gets whether a <see cref="Regex" /> with the specified pattern finds a match in the specified input /// <see cref="String" />. /// </summary> /// <exception cref="ArgumentNullException">The input can not be null.</exception> /// <exception cref="ArgumentNullException">The pattern can not be null.</exception> /// <param name="input">The <see cref="String" /> to search for a match.</param> /// <param name="pattern">The regular expression pattern used by the <see cref="Regex" />.</param> /// <returns>A value of true if the regular expression finds a match, otherwise false.</returns> public static Boolean IsMatch( this String input, String pattern ) { input.ThrowIfNull( nameof( input ) ); pattern.ThrowIfNull( nameof( pattern ) ); return Regex.IsMatch( input, pattern ); }
/// <summary> /// Checks whether a specified substring occurs within the given string, or not. /// </summary> /// <exception cref="ArgumentException"> comparisonType is not a valid <see cref="System.StringComparison" /> value.</exception> /// <exception cref="ArgumentNullException">str can not be null.</exception> /// <exception cref="ArgumentNullException">value can not be null.</exception> /// <param name="str">The string to search in.</param> /// <param name="value">The string to seek.</param> /// <param name="stringComparison">One of the enumeration values that specifies the rules for the search.</param> /// <returns>Returns true if the value parameter occurs within the given string; otherwise, false.</returns> public static Boolean Contains( this String str, String value, StringComparison stringComparison ) { str.ThrowIfNull( nameof( str ) ); value.ThrowIfNull( nameof( value ) ); return str.IndexOf( value, stringComparison ) >= 0; }
/// <summary> /// Appends a formated line to the given string builder. /// </summary> /// <exception cref="ArgumentNullException">The string builder can not be null.</exception> /// <exception cref="ArgumentNullException">The format can not be null.</exception> /// <param name="sb">The string builder to append the line to.</param> /// <param name="format">The <see cref="String" /> containing the format items.</param> /// <param name="arg0">The first argument.</param> /// <returns>Returns the string builder.</returns> public static StringBuilder AppendLineFormat( this StringBuilder sb, String format, Object arg0 ) { sb.ThrowIfNull( nameof( sb ) ); format.ThrowIfNull( nameof( format ) ); return sb.AppendLine( format.F( arg0 ) ); }
/// <summary> /// Gets whether a <see cref="Regex" /> with the specified pattern finds a match in the specified input /// <see cref="String" />. /// </summary> /// <exception cref="ArgumentNullException">The input can not be null.</exception> /// <exception cref="ArgumentNullException">The pattern can not be null.</exception> /// <exception cref="ArgumentNullException">The timeout can not be null.</exception> /// <param name="input">The <see cref="String" /> to search for a match.</param> /// <param name="pattern">The regular expression pattern used by the <see cref="Regex" />.</param> /// <param name="options">The regular expression options used by the <see cref="Regex" />.</param> /// <param name="timeOut">The timeout for the match operation.</param> /// <returns>A value of true if the regular expression finds a match, otherwise false.</returns> public static Boolean IsMatch( this String input, String pattern, RegexOptions options, TimeSpan timeOut ) { input.ThrowIfNull( nameof( input ) ); pattern.ThrowIfNull( nameof( pattern ) ); return Regex.IsMatch( input, pattern, options, timeOut ); }
/// <summary> /// Searches the specified input string for all occurrences of a specified regular expression, using the /// specified matching options. /// </summary> /// <param name="input">The string to search for a match.</param> /// <param name="pattern">The regular expression pattern to match.</param> /// <param name="options">A bitwise combination of the enumeration values that specify options for matching.</param> /// <returns> /// A collection of the objects found by the search. If no matches are found, the method returns an empty /// collection object. /// </returns> public static MatchCollection Matches( this String input, String pattern, RegexOptions options ) { input.ThrowIfNull( nameof( input ) ); pattern.ThrowIfNull( nameof( pattern ) ); return Regex.Matches( input, pattern, options ); }
/// <summary> /// Initializes a new instance of the <see cref="PathMemberSelectionRule" /> class. /// </summary> /// <param name="memberPath">The member path used to find matching members.</param> /// <param name="selectionMode">The selection mode to apply.</param> /// <param name="name">The name of the rule.</param> /// <param name="description">The description of the rule.</param> public PathMemberSelectionRule( String memberPath, MemberSelectionMode selectionMode, String name = null, String description = null ) : base(name, description) { memberPath.ThrowIfNull( nameof( memberPath ) ); _memberPath = memberPath; _selectionMode = selectionMode; }
/// <summary> /// Appends a formated line to the given string builder. /// </summary> /// <exception cref="ArgumentNullException">The string builder can not be null.</exception> /// <exception cref="ArgumentNullException">The format can not be null.</exception> /// <exception cref="ArgumentNullException">The arguments can not be null.</exception> /// <param name="sb">The string builder to append the line to.</param> /// <param name="format">The <see cref="String" /> containing the format items.</param> /// <param name="args">The array containing all the corresponding values.</param> /// <returns>Returns the string builder.</returns> public static StringBuilder AppendLineFormat( this StringBuilder sb, String format, params Object[] args ) { sb.ThrowIfNull( nameof( sb ) ); format.ThrowIfNull( nameof( format ) ); args.ThrowIfNull( nameof( args ) ); return sb.AppendLine( format.F( args ) ); }
/// <summary> /// Converts the specified string representation of a date and time to its DateTime equivalent using the specified /// format, /// culture-specific format information, and style. /// The format of the string representatiomust match the specified format exactly. /// The method returns a value that indicates whether the conversion succeeded. /// </summary> /// <exception cref="ArgumentNullException">value can not be null.</exception> /// <exception cref="ArgumentNullException">format can not be null.</exception> /// <exception cref="ArgumentNullException">format provider can not be null.</exception> /// <param name="value">A <see cref="String" /> containing a date and time to convert.</param> /// <param name="format">The required format of s. See the Remarks section for more information.</param> /// <param name="formatProvider"> /// An object that supplies culture-specific formatting information about /// <paramref name="value" />. /// </param> /// <param name="dateTimeStyle"> /// A bitwise combination of one or more enumeration values that indicate the permitted format /// of <paramref name="value" />. /// </param> /// <param name="outValue"> /// When this method returns, contains the s<see cref="DateTime" /> value equivalent to the date and time contained in /// <paramref name="value" />, /// if the conversion succeeded, or <see cref="DateTime.MinValue" /> if the conversion failed. /// The conversion fails if either the s or format parameter is null, is an empty string, or does not contain a date /// and time that correspond to the pattern specified in format. /// This parameter is passed uninitialized. /// </param> /// <returns>Returns true if the parsing was successful, otherwise false.</returns> public static Boolean TryParsDateTimeExact( this String value, String format, IFormatProvider formatProvider, DateTimeStyles dateTimeStyle, out DateTime outValue ) { value.ThrowIfNull( nameof( value ) ); format.ThrowIfNull( nameof( format ) ); formatProvider.ThrowIfNull( nameof( formatProvider ) ); return DateTime.TryParseExact( value, format, formatProvider, dateTimeStyle, out outValue ); }
/// <summary> /// Returns a string array that contains the substrings in this string that are /// delimited by the given separator. A parameter specifies /// whether to return empty array elements. /// </summary> /// <exception cref="ArgumentNullException">The string can not be null.</exception> /// <exception cref="ArgumentNullException">The separator can not be null.</exception> /// <param name="value">The string to split.</param> /// <param name="separator">A string that delimit the substrings in this string.</param> /// <param name="stringSplitOption"> /// <see cref="System.StringSplitOptions.RemoveEmptyEntries" /> to omit empty array elements /// from the array returned; or System.StringSplitOptions.None to include empty /// array elements in the array returned. /// </param> /// <returns> /// Returns an array whose elements contain the substrings in this string that are delimited by the separator. /// </returns> public static String[] Split( this String value, String separator, StringSplitOptions stringSplitOption = StringSplitOptions.None ) { value.ThrowIfNull( nameof( value ) ); separator.ThrowIfNull( nameof( separator ) ); return value.Split( new[] { separator }, stringSplitOption ); }
/// <summary> /// Gets the part of the string before the specified value, starting at the given start index /// and ending after the specified number of characters. /// </summary> /// <exception cref="ArgumentNullException">The string can not be null.</exception> /// <exception cref="ArgumentNullException">value can not be null.</exception> /// <exception cref="ArgumentOutOfRangeException">The specified range is invalid.</exception> /// <param name="str">The input string.</param> /// <param name="value">The value to search for.</param> /// <param name="startIndex">The start index of the string.</param> /// <param name="length">The length of the string, from the start index.</param> /// <returns> /// The part of the string before the specified value, starting at the given start index. /// Or an empty string if the given string doesn't contain the given value. /// </returns> public static String GetBefore( this String str, String value, Int32 startIndex, Int32 length ) { // ReSharper disable once AccessToModifiedClosure str.ThrowIfNull( nameof( str ) ); value.ThrowIfNull( nameof( value ) ); if ( startIndex < 0 || length < 0 || startIndex + length > str.Length ) throw new ArgumentOutOfRangeException( "length", "The specified range is invalid." ); str = str.Substring( startIndex, length ); return !str.Contains( value ) ? String.Empty : str.Substring( 0, str.IndexOf( value, StringComparison.Ordinal ) ); }
/// <summary> /// Gets the part of the input string between the before and after value, starting at the given start index, /// and ending after the specified number of characters. /// </summary> /// <exception cref="ArgumentNullException">The string can not be null.</exception> /// <exception cref="ArgumentNullException">value can not be null.</exception> /// <exception cref="ArgumentOutOfRangeException">The specified range is invalid.</exception> /// <param name="str">The input string.</param> /// <param name="before">The before value.</param> /// <param name="after">The after value.</param> /// <param name="startIndex">The start index of the string.</param> /// <param name="length">The length of the string, from the start index.</param> /// <returns>The part of the string between the before and after value.</returns> public static String GetBetween( this String str, String before, String after, Int32 startIndex, Int32 length ) { // ReSharper disable once AccessToModifiedClosure str.ThrowIfNull( nameof( str ) ); before.ThrowIfNull( nameof( before ) ); after.ThrowIfNull( nameof( after ) ); if ( startIndex < 0 || startIndex + length > str.Length ) throw new ArgumentOutOfRangeException( "length", "The specified range is invalid." ); str = str.Substring( startIndex, length ); var beforeIndex = str.IndexOf( before, StringComparison.Ordinal ); if ( beforeIndex < 0 ) return String.Empty; var actualStartIndex = beforeIndex + before.Length; var afterIndex = str.IndexOf( after, actualStartIndex, StringComparison.Ordinal ); return afterIndex < 0 ? String.Empty : str.Substring( actualStartIndex, afterIndex - actualStartIndex ); }
/// <summary> /// Unmounts the specified mount point. /// </summary> /// <param name="mountPoint">The mount point.</param> /// <param name="options">The options.</param> public void Unmount( String mountPoint, String options ) { mountPoint.ThrowIfNull ( "mountPoint" ); Device.ThrowIfNull ( "Device" ); CommandErrorReceiver cer = new CommandErrorReceiver ( ); if ( Device.BusyBox.Available ) { Device.ExecuteShellCommand ( "busybox umount {1} {0}", cer, !String.IsNullOrEmpty ( options ) ? String.Format ( "-o {0}", options ) : String.Empty, mountPoint ); } else { Device.ExecuteShellCommand ( "umount {1} {0}", cer, !String.IsNullOrEmpty ( options ) ? String.Format ( "-o {0}", options ) : String.Empty, mountPoint ); } }
/// <summary> /// Imports plans from the given filename. /// </summary> /// <param name="filename">The filename.</param> /// <returns></returns> /// <exception cref="System.ArgumentNullException">filename</exception> public static IEnumerable<SerializablePlan> ImportPlansFromXML(String filename) { filename.ThrowIfNull(nameof(filename)); OutputPlans result = null; try { // Is the format compressed ? if (filename.EndsWith(".epb", StringComparison.OrdinalIgnoreCase)) { string tempFile = Util.UncompressToTempFile(filename); try { return ImportPlansFromXML(tempFile); } finally { FileHelper.DeleteFile(tempFile); } } // Reads the revision number from the file int revision = Util.GetRevisionNumber(filename); if (revision != 0) result = Util.DeserializeXmlFromFile<OutputPlans>(filename); } catch (UnauthorizedAccessException exc) { MessageBox.Show(@"Couldn't read the given file, access was denied. Maybe the directory was under synchronization."); ExceptionHandler.LogException(exc, true); } catch (InvalidDataException exc) { MessageBox.Show(@"The file seems to be corrupted, wrong gzip format."); ExceptionHandler.LogException(exc, true); } if (result != null) return result.Plans; MessageBox.Show(@"There was a problem with the format of the document."); return null; }
/// <summary> /// Attempts to mount the mount point to the associated device without knowing the device or the type. /// Some devices may not support this method. /// </summary> /// <param name="mountPoint"></param> public void Mount( String mountPoint ) { mountPoint.ThrowIfNull ( "mountPoint" ); Device.ThrowIfNull ( "Device" ); CommandErrorReceiver cer = new CommandErrorReceiver ( ); if ( Device.BusyBox.Available ) { Device.ExecuteShellCommand ( "busybox mount {0}", cer, mountPoint ); } else { Device.ExecuteShellCommand ( "mount {0}", cer, mountPoint ); } }
public static String ToTitle(this String value, CultureInfo cultureInfo = null) { value.ThrowIfNull("value"); return((cultureInfo ?? CultureInfo.CurrentCulture).TextInfo.ToTitleCase(value)); }
/// <summary> /// Creates the NTLM Hash of the specified password. /// </summary> /// <param name="password">The password to create the NTLM hash of.</param> /// <returns>The NTLM hash for the specified password.</returns> /// <exception cref="ArgumentNullException">Thrown if the password /// parameter is null.</exception> private static byte[] NtlmHash(String password) { password.ThrowIfNull("password"); byte[] data = Encoding.Unicode.GetBytes(password); using (MD4 md4 = new MD4()) { return md4.ComputeHash(data); } }
public static String[] Split(this String instance, String separator, StringSplitOptions options = StringSplitOptions.RemoveEmptyEntries) { instance.ThrowIfNull("instance"); return(instance.Split(new[] { separator }, options)); }
/// <summary> /// Attempts to mount the mount point to the associated device without knowing the device or the type. /// Some devices may not support this method. /// </summary> /// <param name="mountPoint"></param> public void Mount(String mountPoint) { mountPoint.ThrowIfNull("mountPoint"); Device.ThrowIfNull("Device"); CommandErrorReceiver cer = new CommandErrorReceiver(); Device.ExecuteShellCommand("mount {0}", cer, mountPoint); }