チェンジセット 1612 (default)


以下の違いを無視:
日時:
2023/09/15 19:08:00 (13ヵ月前)
更新者:
hizuya@…
ログメッセージ:
  • TypeFinder.FindGenericCollectionMemberType の UnitTest を追加。
ファイル:
1個の更新

凡例:

未変更
追加
削除
  • framework/trunk/CoreTest/Sources/Reflection/TypeFinderTest.cs

    r1155 r1612  
    2424{ 
    2525    using System; 
     26    using System.Collections.Generic; 
    2627    using System.Reflection; 
    2728    using NUnit.Framework; 
     
    106107            Assert.That(type.Namespace, Is.EqualTo("System"), "Type.Namespace"); 
    107108        } 
     109 
     110        /// <summary> 
     111        /// <see cref="TypeFinder.FindGenericCollectionMemberType(Type,bool)"/> 
     112        /// をテストします。 
     113        /// </summary> 
     114        /// <param name="type"> 
     115        /// <see cref="ICollection{T}"/> を一つ実装した型。 
     116        /// </param> 
     117        /// <returns> 
     118        /// <see cref="TypeFinder.FindGenericCollectionMemberType(Type,bool)"/> 
     119        /// の戻り値。 
     120        /// </returns> 
     121        [Test] 
     122        [TestCase(typeof(ICollection<Element>), ExpectedResult = typeof(Element))] 
     123        [TestCase(typeof(IList<Element>), ExpectedResult = typeof(Element))] 
     124        [TestCase(typeof(List<Element>), ExpectedResult = typeof(Element))] 
     125        [TestCase(typeof(ElementCollection), ExpectedResult = typeof(Element))] 
     126        [TestCase(typeof(ExtendedElementCollection), ExpectedResult = typeof(Element))] 
     127        [TestCase(typeof(GenericCollection<Element>), ExpectedResult = typeof(Element))] 
     128        [TestCase(typeof(GenericElementCollection), ExpectedResult = typeof(Element))] 
     129        [TestCase(typeof(ExtendedGenericElementCollection), ExpectedResult = typeof(Element))] 
     130        public Type TestFindGenericCollectionMemberType(Type type) 
     131        { 
     132            return TypeFinder.FindGenericCollectionMemberType(type, false); 
     133        } 
     134 
     135 
     136        /// <summary> 
     137        /// 要素です。 
     138        /// </summary> 
     139        private sealed class Element 
     140        { 
     141            /// <summary> 
     142            /// インスタンスを作成します。 
     143            /// </summary> 
     144            internal Element() 
     145            { 
     146                // AVOID 
     147            } 
     148        } 
     149 
     150        /// <summary> 
     151        /// 要素のコレクションです。 
     152        /// </summary> 
     153        private class ElementCollection : 
     154            System.Collections.ObjectModel.Collection<Element> 
     155        { 
     156            /// <summary> 
     157            /// インスタンスを作成します。 
     158            /// </summary> 
     159            internal ElementCollection() 
     160            { 
     161                // AVOID 
     162            } 
     163        } 
     164 
     165        /// <summary> 
     166        /// 拡張した要素のコレクションです。 
     167        /// </summary> 
     168        private sealed class ExtendedElementCollection : 
     169            ElementCollection 
     170        { 
     171            /// <summary> 
     172            /// インスタンスを作成します。 
     173            /// </summary> 
     174            internal ExtendedElementCollection() 
     175            { 
     176                // AVOID 
     177            } 
     178        } 
     179 
     180        /// <summary> 
     181        /// ジェネリックコレクションです。 
     182        /// </summary> 
     183        /// <typeparam name="T">要素の型。</typeparam> 
     184        private class GenericCollection<T> : 
     185            System.Collections.ObjectModel.Collection<T> 
     186        { 
     187            /// <summary> 
     188            /// インスタンスを作成します。 
     189            /// </summary> 
     190            internal GenericCollection() 
     191            { 
     192                // AVOID 
     193            } 
     194        } 
     195 
     196        /// <summary> 
     197        /// 要素のジェネリックコレクションです。 
     198        /// </summary> 
     199        private class GenericElementCollection : 
     200            GenericCollection<Element> 
     201        { 
     202            /// <summary> 
     203            /// インスタンスを作成します。 
     204            /// </summary> 
     205            internal GenericElementCollection() 
     206            { 
     207                // AVOID 
     208            } 
     209        } 
     210 
     211        /// <summary> 
     212        /// 拡張した要素のジェネリックコレクションです。 
     213        /// </summary> 
     214        private sealed class ExtendedGenericElementCollection : 
     215            GenericElementCollection 
     216        { 
     217            /// <summary> 
     218            /// インスタンスを作成します。 
     219            /// </summary> 
     220            internal ExtendedGenericElementCollection() 
     221            { 
     222                // AVOID 
     223            } 
     224        } 
    108225    } 
    109226} 
詳しい使い方は TracChangeset を参照してください。