12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091 |
- using System;
- using System.ComponentModel.DataAnnotations.Schema;
- using System.Linq;
- using System.Reflection;
- namespace Common
- {
- public sealed class EntityAttributeHelper
- {
-
-
-
-
- public static string GetEntityTable<T>()
- {
- Type objTye = typeof(T);
- string entityName = "";
- var tableAttribute = objTye.GetCustomAttributes(true).OfType<TableAttribute>();
- var descriptionAttributes = tableAttribute as TableAttribute[] ?? tableAttribute.ToArray();
- entityName = descriptionAttributes.Any() ? descriptionAttributes.ToList()[0].Name : objTye.Name;
- return entityName;
- }
-
-
-
-
- public static string GetEntityKey<T>()
- {
- Type objTye = typeof(T);
- string entityName = "";
- var tableAttribute = objTye.GetCustomAttributes(true).OfType<Key>();
- var descriptionAttributes = tableAttribute as Key[] ?? tableAttribute.ToArray();
- entityName = descriptionAttributes.Any() ? descriptionAttributes.ToList()[0].Name : objTye.Name;
- return entityName;
- }
-
-
-
-
- public static string GetMark<T>()
- {
- Type objTye = typeof(T);
- string entityName = "";
- var tableAttribute = objTye.GetCustomAttributes(true).OfType<MarkAttribute>();
- var descriptionAttributes = tableAttribute as MarkAttribute[] ?? tableAttribute.ToArray();
- entityName = descriptionAttributes.Any() ? descriptionAttributes.ToList()[0].Name : objTye.Name;
- return entityName;
- }
-
-
-
-
-
- public static PropertyInfo[] GetProperties(Type type)
- {
- return type.GetProperties(BindingFlags.Public | BindingFlags.Instance);
- }
-
-
-
-
- public static string GetCalssTable<T>()
- {
- Type objTye = typeof(T);
- if (objTye.Name.Contains("List"))
- {
- objTye = objTye.GenericTypeArguments[0];
- }
- string entityName = "";
- try
- {
- var tableAttribute = objTye.GetCustomAttributes(true).OfType<TableAttribute>();
- var descriptionAttributes = tableAttribute as TableAttribute[] ?? tableAttribute.ToArray();
- entityName = descriptionAttributes.Any() ? descriptionAttributes.ToList()[0].Name : objTye.Name;
- }
- catch (Exception e)
- {
- }
- return entityName+"_";
- }
-
- }
- }
|