示例#1
0
        private ILookupProvider GetProvider()
        {
            ILookupProvider retVal = null;
            App             app    = Configuration.GetInstance().App;

            string assemblyName = app.LookupProviderAssembly;
            string className    = app.LookupProviderClass;
            string config       = app.LookupProviderConfig;


            if (!String.IsNullOrEmpty(assemblyName) && !String.IsNullOrEmpty(className))
            {
                try
                {
                    Assembly providerAssembly = Assembly.Load(assemblyName);
                    if (providerAssembly != null)
                    {
                        Type type = providerAssembly.GetType(className, true, true);

                        if (type != null)
                        {
                            ConstructorInfo constructor = type.GetConstructor(Type.EmptyTypes);
                            retVal = constructor.Invoke(null) as ILookupProvider;

                            retVal.Initialize(config);
                        }
                    }
                }
                catch
                {
                    //silent error
                }
            }

            if (retVal == null)
            {
                throw new Exception(String.Format("No valid lookup provider was found"));
            }

            return(retVal);
        }