Esempio n. 1
0
        //Helper for getting a native custom marshaler
        private static bool HasNativeCustomMarshaler(Type type, out INativeCustomMarshaler marshaler)
        {
            marshaler = null;

            if (type == null)
            {
                return(false);
            }

            lock (s_customMarshalers)
            {
                if (!s_customMarshalers.TryGetValue(type, out marshaler))
                {
                    Object[] customAttributes = type.GetCustomAttributes(typeof(NativeCustomMarshalerAttribute), false);
                    if (customAttributes.Length != 0)
                    {
                        marshaler = (customAttributes[0] as NativeCustomMarshalerAttribute).Marshaler;
                    }

                    s_customMarshalers.Add(type, marshaler);
                }
            }

            return(marshaler != null);
        }
        /// <summary>
        /// Constructs a new instance of the <see cref="NativeCustomMarshalerAttribute"/> class.
        /// </summary>
        /// <param name="type">Type that implements <see cref="INativeCustomMarshaler"/></param>
        /// <exception cref="System.NullReferenceException">Thrown if the type is null.</exception>
        /// <exception cref="System.ArgumentException">Thrown if the type does not implement <see cref="INativeCustomMarshaler"/>.</exception>
        public NativeCustomMarshalerAttribute(Type type)
        {
            if (type == null)
                throw new NullReferenceException("type");

            if (!typeof(INativeCustomMarshaler).IsAssignableFrom(type))
                throw new ArgumentException(String.Format("{0} does not implement INativeCustomMarshaler.", type.FullName));

            m_marshaler = Activator.CreateInstance(type) as INativeCustomMarshaler;
        }
Esempio n. 3
0
        /// <summary>
        /// Constructs a new instance of the <see cref="NativeCustomMarshalerAttribute"/> class.
        /// </summary>
        /// <param name="type">Type that implements <see cref="INativeCustomMarshaler"/></param>
        /// <exception cref="System.NullReferenceException">Thrown if the type is null.</exception>
        /// <exception cref="System.ArgumentException">Thrown if the type does not implement <see cref="INativeCustomMarshaler"/>.</exception>
        public NativeCustomMarshalerAttribute(Type type)
        {
            if (type == null)
            {
                throw new NullReferenceException("type");
            }

            if (!typeof(INativeCustomMarshaler).IsAssignableFrom(type))
            {
                throw new ArgumentException(String.Format("{0} does not implement INativeCustomMarshaler.", type.FullName));
            }

            m_marshaler = Activator.CreateInstance(type) as INativeCustomMarshaler;
        }