• 随便写了点反射用例


    public static T[] ObjectsFieldNameChange<T>(T[] records)
    {
    if (records == null)
    return records;
    if (records.Count() <= 0)
    return records;

    var type = records.FirstOrDefault().GetType();
    var listType = records.GetType();
    var propertys = type.GetProperties();

    if (propertys.Count() <= 0)
    return records;

    Dictionary<string, string> userDefineList = ClientCache.CacheCode.Where(q => q.fListName == UserDefineHeader).ToDictionary(q => q.fCodeName, q => q.fCodeValue);

    if (userDefineList.Count() <= 0)
    return records;

    foreach (PropertyInfo property in propertys)
    {
    var userDefine = userDefineList.Where(q => q.Key.Contains(property.Name));
    if (userDefine.Count() > 0)
    {
    var attributes = property.GetCustomAttributes(false);
    for (int i = 0; i < attributes.Count(); i++)
    {
    if (attributes[i] is DisplayNameAttribute)
    {
    attributes[i] = new DisplayNameAttribute(userDefine.FirstOrDefault().Value);
    }
    }
    }
    }
    return records;
    }

  • 相关阅读:
    USACO 2021 US Open
    【UR #20】跳蚤电话
    省选前的做题记录
    PE444
    杂题
    CF1190E
    gym100299E
    杂题
    2021 5 10 团队博客
    2021 5 9 团队博客
  • 原文地址:https://www.cnblogs.com/zhuzhenpeng/p/3951996.html
Copyright © 2020-2023  润新知