チェンジセット 1655 (default)


以下の違いを無視:
日時:
2024/08/08 1:13:45 (2ヵ月前)
更新者:
hizuya@…
ログメッセージ:
  • Stream.Close 時に例外を無視する機能を追加。
場所:
framework/trunk
ファイル:
1個の追加
3個の更新

凡例:

未変更
追加
削除
  • framework/trunk/CoreLibrary/CoreLibrary.csproj

    r1628 r1655  
    164164    <Compile Include="Sources\IO\AutoDetectEncodingStreamReader.cs" /> 
    165165    <Compile Include="Sources\IO\BufferedPipeStream.cs" /> 
     166    <Compile Include="Sources\IO\CloseExceptionIgnorableStream.cs" /> 
    166167    <Compile Include="Sources\IO\CountedStream.cs" /> 
    167168    <Compile Include="Sources\IO\DeliveryStream.cs" /> 
  • framework/trunk/CoreLibrary/Sources/IO/IOUtility.cs

    r1638 r1655  
    14201420 
    14211421        /// <summary> 
     1422        /// 指定したストリームを、破棄時に発生する例外を無視するストリームでラップします。 
     1423        /// </summary> 
     1424        /// <param name="stream">元にするストリーム。</param> 
     1425        /// <returns> 
     1426        /// ラップしたストリーム。 
     1427        /// </returns> 
     1428        /// <exception cref="ArgumentNullException"> 
     1429        /// <paramref name="stream"/> が <see langword="null"/> 参照です。 
     1430        /// </exception> 
     1431        public static Stream CreateCloseExceptionIgnorableStream(Stream stream) 
     1432        { 
     1433            return new CloseExceptionIgnorableStream(stream); 
     1434        } 
     1435 
     1436        /// <summary> 
    14221437        /// 文字がディレクトリセパレータを表すかを取得します。 
    14231438        /// </summary> 
  • framework/trunk/CoreTest/Sources/IO/IOUtilityTest.cs

    r1575 r1655  
    679679 
    680680        /// <summary> 
     681        /// <see cref="IOUtility.CreateCloseExceptionIgnorableStream"/> をテストします。 
     682        /// </summary> 
     683        [Test] 
     684        public void TestCreateCloseExceptionIgnorableStream() 
     685        { 
     686            Action<bool, Action<Stream>> action = delegate(bool useWrapper, Action<Stream> callback) 
     687            { 
     688                using (MemoryStream rootStream = new MemoryStream()) 
     689                { 
     690                    Stream targetStream = new BufferedStream(rootStream, 0x1000); 
     691                    if (useWrapper) 
     692                    { 
     693                        targetStream = IOUtility.CreateCloseExceptionIgnorableStream(targetStream); 
     694                    } 
     695 
     696                    try 
     697                    { 
     698                        targetStream.WriteByte(1); 
     699                    } 
     700                    finally 
     701                    { 
     702                        // 元のストリームを破棄 
     703                        rootStream.Close(); 
     704 
     705                        // BufferedStream.Close() では書き込まれたデータがある場合 Flush() を呼ぶので例外が発生する 
     706                        callback(targetStream); 
     707                    } 
     708                } 
     709            }; 
     710 
     711            // Close() で例外が発生することを確認 
     712            action( 
     713                false, 
     714                delegate(Stream stream) 
     715                { 
     716                    Assert.That( 
     717                        stream.Close, 
     718                        Throws.TypeOf<ObjectDisposedException>(), 
     719                        "Normal close"); 
     720                }); 
     721 
     722            // Close() で例外が発生しないことを確認 
     723            action( 
     724                true, 
     725                delegate(Stream stream) 
     726                { 
     727                    stream.Close(); 
     728                }); 
     729        } 
     730 
     731        /// <summary> 
    681732        /// 再解析ポイントを作成します。 
    682733        /// </summary> 
詳しい使い方は TracChangeset を参照してください。