Ejemplo n.º 1
0
        /// <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);
        }
Ejemplo n.º 2
0
 /// <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);