|
|
|
@ -4,16 +4,35 @@ using System.Linq;
@@ -4,16 +4,35 @@ using System.Linq;
|
|
|
|
|
using System.Reflection; |
|
|
|
|
|
|
|
|
|
namespace EGFramework{ |
|
|
|
|
public static class EGenerateVariant{ |
|
|
|
|
public static Dictionary<string,object> EGenerateDictiontaryByType(this Type self){ |
|
|
|
|
public static class EGenerateVariant |
|
|
|
|
{ |
|
|
|
|
public static Dictionary<string, object> EGenerateDictiontaryByType(this Type self) |
|
|
|
|
{ |
|
|
|
|
PropertyInfo[] propertyNames = self.GetProperties(); |
|
|
|
|
FieldInfo[] fieldNames = self.GetFields(); |
|
|
|
|
Dictionary<string, object> result = new Dictionary<string, object>(); |
|
|
|
|
foreach (PropertyInfo pName in propertyNames) |
|
|
|
|
{ |
|
|
|
|
result.Add(pName.Name, pName.Name); |
|
|
|
|
} |
|
|
|
|
foreach (FieldInfo fName in fieldNames) |
|
|
|
|
{ |
|
|
|
|
result.Add(fName.Name, fName.Name); |
|
|
|
|
} |
|
|
|
|
return result; |
|
|
|
|
} |
|
|
|
|
public static Dictionary<string, object> EGenerateEmptyDictiontaryByType(this Type self) |
|
|
|
|
{ |
|
|
|
|
PropertyInfo[] propertyNames = self.GetProperties(); |
|
|
|
|
FieldInfo[] fieldNames = self.GetFields(); |
|
|
|
|
Dictionary<string,object> result = new Dictionary<string, object>(); |
|
|
|
|
foreach(PropertyInfo pName in propertyNames){ |
|
|
|
|
result.Add(pName.Name,pName.Name); |
|
|
|
|
Dictionary<string, object> result = new Dictionary<string, object>(); |
|
|
|
|
foreach (PropertyInfo pName in propertyNames) |
|
|
|
|
{ |
|
|
|
|
result.Add(pName.Name, ""); |
|
|
|
|
} |
|
|
|
|
foreach(FieldInfo fName in fieldNames){ |
|
|
|
|
result.Add(fName.Name,fName.Name); |
|
|
|
|
foreach (FieldInfo fName in fieldNames) |
|
|
|
|
{ |
|
|
|
|
result.Add(fName.Name, ""); |
|
|
|
|
} |
|
|
|
|
return result; |
|
|
|
|
} |
|
|
|
@ -38,23 +57,40 @@ namespace EGFramework{
@@ -38,23 +57,40 @@ namespace EGFramework{
|
|
|
|
|
return result; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public static List<Dictionary<string,object>> EGenerateDictionaryByGroup<T>(this IEnumerable<T> self){ |
|
|
|
|
List<Dictionary<string,object>> result = new List<Dictionary<string, object>>(); |
|
|
|
|
public static List<Dictionary<string, object>> EGenerateDictionaryByGroup<T>(this IEnumerable<T> self) |
|
|
|
|
{ |
|
|
|
|
List<Dictionary<string, object>> result = new List<Dictionary<string, object>>(); |
|
|
|
|
PropertyInfo[] propertyNames = typeof(T).GetProperties(); |
|
|
|
|
FieldInfo[] fieldNames = typeof(T).GetFields(); |
|
|
|
|
foreach(T member in self){ |
|
|
|
|
Dictionary<string,object> mResult = new Dictionary<string, object>(); |
|
|
|
|
foreach(PropertyInfo pName in propertyNames){ |
|
|
|
|
foreach (T member in self) |
|
|
|
|
{ |
|
|
|
|
Dictionary<string, object> mResult = new Dictionary<string, object>(); |
|
|
|
|
foreach (PropertyInfo pName in propertyNames) |
|
|
|
|
{ |
|
|
|
|
object p = pName.GetValue(member); |
|
|
|
|
mResult.Add(pName.Name,p); |
|
|
|
|
mResult.Add(pName.Name, p); |
|
|
|
|
} |
|
|
|
|
foreach(FieldInfo fName in fieldNames){ |
|
|
|
|
foreach (FieldInfo fName in fieldNames) |
|
|
|
|
{ |
|
|
|
|
object p = fName.GetValue(member); |
|
|
|
|
mResult.Add(fName.Name,p); |
|
|
|
|
mResult.Add(fName.Name, p); |
|
|
|
|
} |
|
|
|
|
result.Add(mResult); |
|
|
|
|
} |
|
|
|
|
return result; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
//Default primary key is id,Id,ID. |
|
|
|
|
public static string EGetDefaultPrimaryKey(this Dictionary<string, object> self) |
|
|
|
|
{ |
|
|
|
|
foreach (KeyValuePair<string, object> param in self) |
|
|
|
|
{ |
|
|
|
|
if (param.Key == "ID" || param.Key == "Id" || param.Key == "id") |
|
|
|
|
{ |
|
|
|
|
return param.Key; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
return ""; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |