本文整理汇总了C#中System.String.ThrowIfNull方法的典型用法代码示例。如果您正苦于以下问题:C# String.ThrowIfNull方法的具体用法?C# String.ThrowIfNull怎么用?C# String.ThrowIfNull使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.String
的用法示例。
在下文中一共展示了String.ThrowIfNull方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: IsMatch
/// <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 );
}
示例2: AppendLineFormat
/// <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 ) );
}
示例3: Contains
/// <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;
}
示例4: Matches
/// <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 );
}
示例5: PathMemberSelectionRule
/// <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;
}
示例6: TryParsDateTimeExact
/// <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 );
}
示例7: Split
/// <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 );
}
示例8: GetBefore
/// <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 ) );
}
示例9: GetBetween
/// <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 );
}
示例10: Unmount
/// <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 );
}
}
示例11: Mount
/// <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 );
}
}
示例12: Mount
/// <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);
}
示例13: NtlmHash
/// <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);
}
}