小编sli*_*les的帖子

Serilog 有 JSON 模式吗?

我们专门使用 appsettings.json (和环境特定版本)来配置 Serilog。我希望在这些文件中配置 Serilog 时具有智能感知功能。

有人知道他们是否有一个架构,或者是否有人创建了一个架构并共享它?

schema json serilog

6
推荐指数
0
解决办法
381
查看次数

MethodInfo、CreateDelegate 和通用方法

感谢 Jon Skeet 在这个问题中的回答,我进行了以下工作:

public delegate BaseItem GetItemDelegate(Guid itemID);

public static class Lists
{
  public static GetItemDelegate GetItemDelegateForType(Type derivedType)
  {
    MethodInfo method = typeof(Lists).GetMethod("GetItem");
    method = method.MakeGenericMethod(new Type[] { derivedType });
    return (GetItemDelegate)Delegate.CreateDelegate(typeof(GetItemDelegate), method);
  }

  public static T GetItem<T>(Guid itemID) where T : class { // returns an item of type T ... }
}

public class DerivedItem : BaseItem { }

// I can call it like so:
GetItemDelegate getItem = Lists.GetItemDelegateForType(typeof(DerivedItem));
DerivedItem myItem = getItem(someID); // …
Run Code Online (Sandbox Code Playgroud)

c# generics delegates methodinfo

5
推荐指数
1
解决办法
6520
查看次数

标签 统计

c# ×1

delegates ×1

generics ×1

json ×1

methodinfo ×1

schema ×1

serilog ×1