/// <summary> /// 构建一个ApiClass描述,如果<paramref name="type"/>不是ApiClass则返回null /// </summary> /// <param name="type"></param> /// <returns></returns> private static ApiClassDescriptor CreateApiClassDescriptor(Type type) { var typeInfo = type.GetTypeInfo(); if (CheckType(typeInfo, false) == false) { return(null); } var methods = typeInfo.DeclaredMethods.Where(m => m.IsDefined(typeof(ApiAttribute))); if (methods.Any() == false) { return(null); } var apis = new List <ApiDescriptor>(); var properties = new List <ApiPropertyDescriptor>(); var apiclass = new ApiClassDescriptor(type, apis, properties); apis.AddRange(methods .Select(it => CreateApiDescriptor(it, apiclass)) .Where(it => it != null)); if (apis.Count == 0) { return(null); } properties.AddRange(typeInfo.DeclaredProperties .Where(it => it.IsDefined(typeof(ApiPropertyAttribute))) .Select(it => CreateApiPropertyDescriptor(it, apiclass)) .Where(it => it != null)); return(apiclass); }
private void FindAllApis(IEnumerable <Type> types) { foreach (var t in types) { var apiclass = ApiClassDescriptor.Create(t, Container); if (apiclass == null) { continue; } _types.Add(apiclass); var ns = _namespaces.FirstOrDefault(it => it.FullName == t.Namespace); if (ns == null) { _namespaces.Add(ns = new NamespaceDescriptor(t.Namespace, Container)); } ns.AddApiCalss(apiclass); foreach (var type in _types) { _apis.AddRange(type.Apis); } } }
/// <summary> /// 创建API属性描述,如果属性不合法,则返null /// </summary> /// <param name="property"></param> /// <param name="apiclass"></param> /// <returns></returns> private static ApiPropertyDescriptor CreateApiPropertyDescriptor(PropertyInfo property, ApiClassDescriptor apiclass) => CheckProperty(property, false) ? new ApiPropertyDescriptor(property, apiclass) : null;
/// <summary> /// 创建API描述,如果方法不是API则返回null /// </summary> /// <param name="method">同于创建API的方法</param> /// <param name="apiclass">方法所在类的描述</param> /// <returns></returns> private static ApiDescriptor CreateApiDescriptor(MethodInfo method, ApiClassDescriptor apiclass) => CheckMethod(method, false) ? new ApiDescriptor(method, apiclass) : null;