Exemple #1
0
 /// <summary>
 /// Convert this SourceList to DataTable instance.
 /// DataTable.Columns are the name of the properties in each list item.
 /// </summary>
 public static System.Data.DataTable ToDataTable(this System.Collections.IList SourceList, string TableName)
 {
     System.Data.DataTable table = new System.Data.DataTable(TableName);
     if (SourceList.Count > 0)
     {
         foreach (var item in MemberInfox.GetMemberInfox(SourceList[0]))
         {
             table.Columns.Add(item.Name, item.MemberType);
         }
         table.Populate(SourceList);
     }
     return(table);
 }
 public static MemberInfox GetPropertyInfox(object obj, string PropertyPath, bool SearchForPriviteFieldInCasePublicFieldIsReadOnly = true)
 {
     MemberInfox info = null;
     foreach (var partName in (PropertyPath + "").Split('.'))//For nested properties like a.Name
     {
         info = new MemberInfox(obj, partName, SearchForPriviteFieldInCasePublicFieldIsReadOnly);
         if (!info.MemberExists) return info;
         obj = info.GetValue();
     }
     return info;
 }
 public static int GetSizeConst(MemberInfox property)
 {
     var att = property.GetCustomAttributes(typeof(MarshalAsAttribute)) as MarshalAsAttribute;
     if (att == null) return -1;
     return att.SizeConst;
 }
 private bool IsEqualDefaut(MemberInfox property)
 {
     try
     {
         if (!Utility.IsSimpleType(property.ValueType))
             return false;
         var val = property.GetValue();
         object att = property.GetCustomAttributes(typeof(DefaultValueAttribute));
         if (att != null)
             return object.Equals(val, (att as DefaultValueAttribute).Value);
         return object.Equals(val, Utility.GetDefault(property.MemberType));
     }
     catch {  }
     return true;
 }