当前位置: 首页>>代码示例>>C#>>正文


C# String.ThrowIfNull方法代码示例

本文整理汇总了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 );
        }
开发者ID:MannusEtten,项目名称:Extend,代码行数:19,代码来源:String.IsMatch.cs

示例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 ) );
        }
开发者ID:MannusEtten,项目名称:Extend,代码行数:16,代码来源:StringBuilder.AppendLineFormat.cs

示例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;
        }
开发者ID:MannusEtten,项目名称:Extend,代码行数:17,代码来源:String.Contains.cs

示例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 );
        }
开发者ID:MannusEtten,项目名称:Extend,代码行数:18,代码来源:String.Matches.cs

示例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;
        }
开发者ID:MannusEtten,项目名称:Extend,代码行数:15,代码来源:PathMemberSelectionRule.cs

示例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 );
        }
开发者ID:MannusEtten,项目名称:Extend,代码行数:41,代码来源:String.TryParsDateTimeExact.cs

示例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 );
        }
开发者ID:MannusEtten,项目名称:Extend,代码行数:30,代码来源:String.Split.cs

示例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 ) );
        }
开发者ID:MannusEtten,项目名称:Extend,代码行数:29,代码来源:String.GetBefore.cs

示例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 );
        }
开发者ID:MannusEtten,项目名称:Extend,代码行数:33,代码来源:String.GetBetween.cs

示例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 );
            }
        }
开发者ID:otugi,项目名称:SmartArrow-Windows,代码行数:17,代码来源:FileSystem.cs

示例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 );
            }
        }
开发者ID:otugi,项目名称:SmartArrow-Windows,代码行数:17,代码来源:FileSystem.cs

示例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);
        }
开发者ID:vebin,项目名称:madb,代码行数:13,代码来源:FileSystem.cs

示例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);
			}
		}
开发者ID:abhibecb,项目名称:S22.Imap,代码行数:14,代码来源:Responses.cs


注:本文中的System.String.ThrowIfNull方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。