Returns an array of System.Type objects that represent the type arguments of a generic type or the type parameters of a generic type definition. - CSharp System.Reflection

CSharp examples for System.Reflection:Type

Description

Returns an array of System.Type objects that represent the type arguments of a generic type or the type parameters of a generic type definition.

Demo Code

// See LICENSE.txt for details or visit http://www.opensource.org/licenses/ms-pl.html
using System.Reflection;
using System.Linq;
using System;/*w w w  .j  a  va 2 s . c  om*/

public class Main{
        /// <summary>
      /// Returns an array of System.Type objects that represent the type arguments of a generic type or the type parameters of a generic type definition.
      /// </summary>
      /// <param name="type">The type.</param>
      /// <returns>An array of System.Type objects that represent the type arguments of a generic type. Returns an empty array if the current type is not a generic type.</returns>
      public static Type[] GetGenericArguments( this Type type )
      {
         return type.GetTypeInfo().GenericTypeArguments;
      }
}

Related Tutorials