Ai
1 Star 0 Fork 0

hardstylewyl/GRPC_Samples

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
SwaggerTools.cs 1001 Bytes
一键复制 编辑 原始数据 按行查看 历史
hardstylewyl 提交于 2025-01-07 18:00 +08:00 . update:优化GRPC使用方式
using System.Reflection;
using System.Runtime.Serialization;
namespace _9GrpcServer;
public static class SwaggerTools
{
public static IEnumerable<Type> GetDataContractKnownTypes(Type type)
{
foreach (var attribute in type.GetCustomAttributes<KnownTypeAttribute>())
{
foreach (var knownType in ResolveKnownTypes(type, attribute))
{
yield return knownType;
}
}
}
private static IEnumerable<Type> ResolveKnownTypes(Type type, KnownTypeAttribute attribute)
{
if (attribute.Type != null)
{
return new[] { attribute.Type };
}
if (attribute.MethodName == null)
{
return Array.Empty<Type>();
}
var types = (IEnumerable<Type>)type
.GetMethod(attribute.MethodName, BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic)!
.Invoke(null, Array.Empty<object>())!;
return types;
}
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/hardstylewyl/grpc_samples.git
git@gitee.com:hardstylewyl/grpc_samples.git
hardstylewyl
grpc_samples
GRPC_Samples
master

搜索帮助