在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
using Kufen.Common.Definitions; using Mono.Cecil; using System; using System.Collections.Generic; using System.Linq; using System.Text.RegularExpressions; using System.Web; namespace Kufen.WebApi.SwaggerHelp { public class SwaggerModelHelp { public static List<SwaggerEncryptModelInfo> GetDecryptRequestMetaInfoList() { var decryptRequestMetaInfoList = new List<SwaggerEncryptModelInfo>(); var path = typeof(SwaggerModelHelp).Assembly.Location; var assembly = AssemblyDefinition.ReadAssembly(path); var toInspect = assembly.MainModule .GetTypes() .SelectMany(t => t.Methods.Select(m => new { t, m })) .Where(x => x.m.HasBody); toInspect = toInspect.Where( x => x.t.Name.EndsWith("Controller") && x.m.IsPublic == true && x.m.Parameters.Any(m => m.ParameterType.Name == nameof(DecryptRequest)) ); foreach (var method in toInspect) { var containsEncryptRequestMethodBody = method.m.Body.Instructions.ToList().Where(m => m.ToString().Contains("EncryptRequestHandler")).FirstOrDefault(); if (containsEncryptRequestMethodBody != null) { var ilStr = containsEncryptRequestMethodBody.ToString(); var regMatchResult = Regex.Match(ilStr, "EncryptRequestHandler<(?<EncryptRequestModel>[^,]+),(?<EncryptResponseModel>[^>]+)>"); var encryptRequestModel = regMatchResult.Groups["EncryptRequestModel"].Value; var encryptResponseModel = regMatchResult.Groups["EncryptResponseModel"].Value; decryptRequestMetaInfoList.Add(new SwaggerEncryptModelInfo { Controller = method.t.FullName, Action = method.m.Name, ReqModelType = encryptRequestModel, ResModelType = encryptResponseModel }); } } return decryptRequestMetaInfoList; } } }
|
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论