コード例 #1
0
 /// <summary>
 /// 自动绑定读表
 /// </summary>
 /// <param name="bindObject">执行对象</param>
 public static void Bind(object bindObject)
 {
     lock (lockObject)
     {
         DetectionAttribute(bindObject);
         Type type = bindObject.GetType();
         foreach (string fieldName in pool[bindObject].Keys)
         {
             TablePropertyTag tag = pool[bindObject][fieldName];
             if (!string.IsNullOrEmpty(tag.tableName) && !string.IsNullOrEmpty(tag.primaryKey) && !string.IsNullOrEmpty(tag.key))
             {
                 string    value = MyTable.GetInstance().GetValue(tag.tableName, tag.primaryKey, tag.key);
                 FieldInfo info  = type.GetField(fieldName);
                 info.SetValue(bindObject, TypeDescriptor.GetConverter(info.FieldType).ConvertFrom(value));
             }
         }
     }
 }