Beispiel #1
0
        /// <summary>
        /// Find the adapter attribute for a named adapter type.
        /// </summary>
        protected static AdapterAttribute FindAdapterAttribute(string adapterName)
        {
            if (!string.IsNullOrEmpty(adapterName))
            {
                var adapterType = TypeResolver.FindAdapterType(adapterName);
                if (adapterType != null)
                {
                    return(TypeResolver.FindAdapterAttribute(adapterType));
                }
            }

            return(null);
        }
Beispiel #2
0

        
        /// <summary>
        /// Find the type of the adapter with the specified name and create it.
        /// </summary>
        protected static IAdapter CreateAdapter(string adapterTypeName)
        {
            if (string.IsNullOrEmpty(adapterTypeName))
            {
                return(null);
            }

            var adapterType = TypeResolver.FindAdapterType(adapterTypeName);

            if (adapterType == null)
            {
                throw new NoSuchAdapterException(adapterTypeName);
            }

            if (!typeof(IAdapter).IsAssignableFrom(adapterType))
            {
                throw new InvalidAdapterException(string.Format("Type '{0}' does not implement IAdapter and cannot be used as an adapter.", adapterTypeName));
            }

            return((IAdapter)Activator.CreateInstance(adapterType));
        }