Exemplo n.º 1
0
        public static T GetModuleByName <T>(string name)
        {
            var type = ModuleApiContainer.GetType(name);

            if (type != null)
            {
                object obj = Activator.CreateInstance(type, true); //根据类型创建实例
                return((T)obj);                                    //类型转换并返回
            }
            return(default(T));
        }
Exemplo n.º 2
0
        public static ApiMethod GetApiMethod(ApiCall call)
        {
            // this is only for the sitemodule.
            if (call.Context.WebSite == null)
            {
                return(null);
            }

            ApiMethod method = null;

            var type = ModuleApiContainer.GetType(call.Command.ObjectType);

            if (type != null)
            {
                var instance = CreateInstance(type, call.Context) as ISiteModuleApi;
                if (instance != null)
                {
                    method = GetMethod(instance, call.Command.Method, call);
                    if (method != null)
                    {
                        return(method);
                    }
                }
            }
            else
            {
                // try command and value.
                var commandtype = ModuleApiContainer.GetType(call.Command.Method);

                if (commandtype != null)
                {
                    var instance = CreateInstance(commandtype, call.Context) as ISiteModuleApi;
                    if (instance != null)
                    {
                        method = GetMethod(instance, call.Command.Value, call);
                        if (method != null)
                        {
                            return(method);
                        }
                    }
                }
            }

            return(null);
        }