private static void SetByDll() { var assemblies = new DirectoryInfo(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "bin", "Apis")).GetFiles("*api.dll").Select(r => Assembly.LoadFrom(r.FullName)); var postAttr = typeof(SePostAttribute); var getAttr = typeof(SeGetAttribute); foreach (var assembly in assemblies) { var types = assembly.GetTypes(); foreach (var type in types) { var interfaces = type.GetInterfaces(); if (interfaces.Any(@interface => @interface == typeof(IApi))) { var typeStr = type.ToString(); var array = typeStr.Split('.'); var methodname = array[0] + "." + array[array.Length - 1]; var attrs = type.GetCustomAttributes(true); var httpType = "post";//默认post //var postAttr = typeof(SePostAttribute); //var postAttr = typeof(SePostAttribute); foreach (var item in attrs) { var p = item.GetType(); if (p == postAttr) { httpType = "post"; } if (p == getAttr) { httpType = "get"; } //其他类型请求 // } string method = Constants.PREFIX + methodname.ToLower().Replace("api", ""); var apimethod = new ApiMethod() { Name = method, InvokeType = InvokeType.dll, Type = type, HttpType = httpType }; apiMethods.TryAdd(method, apimethod); } } } }
private static ApiProvider GetProvider(ApiMethod apimethod, bool isPost) { if (apimethod.InvokeType == InvokeType.dll) { return(new PluginProvider(apimethod) { }); } if (apimethod.InvokeType == InvokeType.@class || apimethod.InvokeType == InvokeType.method) { return(new WebProvider(apimethod, isPost) { }); } return(null); }
public ApiProvider(ApiMethod apimethod) { this.apimethod = apimethod; }
public WebProvider(ApiMethod apimethod, bool isPost) : base(apimethod) { this.IsPost = isPost; }
public PluginProvider(ApiMethod apimethod) : base(apimethod) { }