60 lines
1.6 KiB
C#
60 lines
1.6 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Linq.Expressions;
|
|
using System.Text;
|
|
|
|
namespace APT.Infrastructure.Utility
|
|
{
|
|
public static class CsRedisHelper<T> where T : class
|
|
{
|
|
public static RedisClass GetRedisClass()
|
|
{
|
|
var type = typeof(T);
|
|
var attribute = type.GetCustomAttributes(typeof(RedisAttribute), false).FirstOrDefault() as RedisAttribute;
|
|
if (attribute == null)
|
|
{
|
|
return null;
|
|
}
|
|
|
|
var attributelist = type.GetCustomAttributes(typeof(RedisAttribute), false).FirstOrDefault() as RedisAttribute;
|
|
if (attribute == null)
|
|
{
|
|
return null;
|
|
}
|
|
|
|
var key = attribute.Key;
|
|
var props = type.GetProperties();
|
|
var redisClass = new RedisClass();
|
|
redisClass.ClassName = type.Name;
|
|
redisClass.GroupName = attribute.GroupField;
|
|
redisClass.DicKeys = new Dictionary<string, string>();
|
|
if (key.Any())
|
|
{
|
|
foreach (var k in key)
|
|
{
|
|
var prp = props.FirstOrDefault(i => i.Name == k);
|
|
redisClass.DicKeys.Add(k, prp.PropertyType.Name);
|
|
}
|
|
|
|
}
|
|
else
|
|
{
|
|
redisClass.DicKeys.Add("ID", "GUID");
|
|
}
|
|
|
|
return redisClass;
|
|
}
|
|
|
|
}
|
|
|
|
public class RedisClass
|
|
{
|
|
public string ClassName { get; set; }
|
|
|
|
public string GroupName { get; set; }
|
|
public Dictionary<string,string> DicKeys { get; set; }
|
|
}
|
|
|
|
}
|