/// <summary>Determines whether a type can be marshaled.</summary> /// <param name="t">The type to check.</param> /// <param name="marshaler">On success, the marshaler instance.</param> /// <returns><see langword="true"/> if this type can marshaled; otherwise, <see langword="false"/>.</returns> public static bool CanMarshal(Type t, out IVanaraMarshaler marshaler) { var vattr = t.GetCustomAttributes <VanaraMarshalerAttribute>(true).FirstOrDefault(); if (vattr != null) { var cookie = vattr.Cookie; marshaler = cookie is null? Activator.CreateInstance(vattr.MarshalType) as IVanaraMarshaler: Activator.CreateInstance(vattr.MarshalType, cookie) as IVanaraMarshaler; return(marshaler != null); } if (typeof(IVanaraMarshaler).IsAssignableFrom(t)) { marshaler = Activator.CreateInstance(t) as IVanaraMarshaler; return(marshaler != null); } marshaler = null; return(false); }
/// <summary>Determines whether a type can be marshaled.</summary> /// <typeparam name="T">The type to check.</typeparam> /// <param name="marshaler">On success, the marshaler instance.</param> /// <returns><see langword="true"/> if this type can marshaled; otherwise, <see langword="false"/>.</returns> public static bool CanMarshal <T>(out IVanaraMarshaler marshaler) => CanMarshal(typeof(T), out marshaler);