src/Mimp.SeeSharper.Reflection/TypeExtensions.Default.cs
/// <summary>
/// Return a compiled delegate to get the default of <paramref name="type"/>.
/// </summary>
/// <param name="type"></param>
/// <param name="delegateType"></param>
/// <returns></returns>
/// <exception cref="ArgumentNullException"></exception>
/// <exception cref="InvalidOperationException">If type isn't castable to return type of delegate.</exception>
Return a compiled delegate to get the default of .
Return a compiled delegate to get the default of .
public static Delegate GetDefaultDelegate(this Type type, Type delegateType)
        {
            if (type is null)
                throw new ArgumentNullException(nameof(type));
            if (delegateType is null)
                throw new ArgumentNullException(nameof(delegateType));
            return Expression.Lambda(delegateType, Expression.Convert(
                Expression.Default(type), delegateType.GetDelegateReturnType()
            )).Compile();
        }
public static Delegate GetDefaultDelegate ( this Type type , Type delegateType ) { if ( type is null ) throw new ArgumentNullException ( nameof ( type ) ) ; if ( delegateType is null ) throw new ArgumentNullException ( nameof ( delegateType ) ) ; return Expression . Lambda ( delegateType , Expression . Convert ( Expression . Default ( type ) , delegateType . GetDelegateReturnType ( ) ) ) . Compile ( ) ; }
Return a compiled delegate to get the default of .
Return a compiled delegate to get the default of .
None
None
If type isn't castable to return type of delegate.
If type isn ' t castable to return type of delegate .
Type
this
delegateType
Type
None
type
None