BN089-BS开发框架MVC4版/source20131023/Zephyr.Net/Zephyr.Core/Base/ModelBase.cs
(开头部分) 2KB这里只显示每个文件的开头 60 行。登录后可以解锁完整代码。
/*************************************************************************
* 文件名称 :ModelBase.cs
* 描述说明 :定义实体基类
*
* 创建信息 : create by liuhuisheng.xm@gmail.com on 2012-11-10
* 修订信息 : modify by (person) on (date) for (reason)
*
* 版权信息 : Copyright (c) 2013 厦门纵云信息科技有限公司 www.zoewin.com
**************************************************************************/
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Dynamic;
using System.Linq;
using Zephyr.Utils;
namespace Zephyr.Core
{
public class ModelBase
{
private static readonly ConcurrentDictionary<Type, Dictionary<string, List<string>>> _cachedAtrributes = new ConcurrentDictionary<Type, Dictionary<string, List<string>>>();
public static List<string> GetAttributeFields<TModel, TAttribute>()
{
var key = typeof(TAttribute).Name;
var thisAttributes =_cachedAtrributes.GetOrAdd(typeof(TModel), BuildAtrributeDictionary);
return thisAttributes.ContainsKey(key) ? thisAttributes[typeof(TAttribute).Name] : new List<string>();
}
private static Dictionary<string, List<string>> BuildAtrributeDictionary(Type TModel)
{
var result = new Dictionary<string, List<string>>();
foreach (var property in TModel.GetProperties())
{
var attributes = property.GetCustomAttributes(typeof(Attribute), true) as Attribute[];
if (attributes != null)
foreach (var key in attributes.Select(attr => attr.GetType().Name))
{
if (!result.ContainsKey(key))
result.Add(key, new List<string>());
result[key].Add(property.Name);
}
}
return result;
}
public dynamic Extend(object obj)
{
var expando = (IDictionary<string, object>)new ExpandoObject();
EachHelper.EachObjectProperty(this, (i, name, value) => {
expando.Add(name, value);
});
EachHelper.EachObjectProperty(obj, (i, name, value) => {
expando[name] = value;
后面还有 6 行代码,解锁后查看完整代码
24 小时内免费解锁 3 个项目,之后 1 算力/个。 规则说明
AI 解读 AI
登录后可用,每次 10 算力,解读结果公开显示在下面。
还没有人解读过这个文件。