public static bool DuckIs <T>(this object instance) { if (instance is null) { DuckTypeTargetObjectInstanceIsNull.Throw(); } return(DuckType.CanCreate <T>(instance)); }
public static bool DuckIs(this object instance, Type targetType) { if (instance is null) { DuckTypeTargetObjectInstanceIsNull.Throw(); } if (targetType != null) { return(DuckType.CanCreate(targetType, instance)); } return(false); }
public static bool DuckIs <T>(this object instance) { if (instance is null) { DuckTypeTargetObjectInstanceIsNull.Throw(); } if (DuckType.CreateCache <T> .IsVisible) { return(DuckType.CanCreate <T>(instance)); } return(false); }
public static object DuckAs(this object instance, Type targetType) { if (instance is null) { DuckTypeTargetObjectInstanceIsNull.Throw(); } if (targetType != null) { DuckType.CreateTypeResult proxyResult = DuckType.GetOrCreateProxyType(targetType, instance.GetType()); if (proxyResult.Success) { return(proxyResult.CreateInstance(instance)); } } return(null); }
public static bool TryDuckCast(this object instance, Type targetType, out object value) { if (instance is null) { DuckTypeTargetObjectInstanceIsNull.Throw(); } if (targetType != null) { DuckType.CreateTypeResult proxyResult = DuckType.GetOrCreateProxyType(targetType, instance.GetType()); if (proxyResult.Success) { value = proxyResult.CreateInstance(instance); return(true); } } value = default; return(false); }
public static bool TryDuckImplement(this object?instance, Type?typeToDeriveFrom, [NotNullWhen(true)] out object?value) { if (instance is null) { DuckTypeTargetObjectInstanceIsNull.Throw(); } if (typeToDeriveFrom != null) { DuckType.CreateTypeResult proxyResult = DuckType.GetOrCreateReverseProxyType(typeToDeriveFrom, instance.GetType()); if (proxyResult.Success) { value = proxyResult.CreateInstance(instance); return(true); } } value = default; return(false); }
/// <summary> /// Gets the duck type instance for the object implementing a base class or interface T /// </summary> /// <param name="instance">Object instance</param> /// <param name="targetType">Target type</param> /// <returns>DuckType instance</returns> public static object As(this object instance, Type targetType) => DuckType.Create(targetType, instance);
/// <summary> /// Gets the duck type instance for the object implementing a base class or interface T /// </summary> /// <param name="instance">Object instance</param> /// <typeparam name="T">Target type</typeparam> /// <returns>DuckType instance</returns> public static T As <T>(this object instance) => DuckType.Create <T>(instance);
public static object DuckImplement(this object instance, Type typeToDeriveFrom) => DuckType.CreateReverse(typeToDeriveFrom, instance);
public static T?DuckCast <T>(this object?instance) => DuckType.Create <T>(instance);