Exemple #1
0
        public override void Execute()
        {
            Object = (T)Activator.CreateInstance(typeof(T));
            Type objectType = typeof(T);

            for (var i = 0; i < DataRecord.FieldCount; i++)
            {
                string       columnName   = DataRecord.GetName(i);
                PropertyInfo propertyInfo = objectType.GetProperty(columnName);

                if (propertyInfo == null)
                {
                    throw new NoPropertyForColumnException(String.Format("The DataRecord contains column '{0}' that is not a property of the '{1}' class.", columnName, objectType.FullName));
                }

                object columnValue = DataRecord[columnName];
                if (columnValue.GetType() != typeof(System.DBNull))
                {
                    Type propertyType = propertyInfo.PropertyType;

                    if (propertyType.IsGenericType && propertyType.GetGenericTypeDefinition().Equals(typeof(Nullable <>)))
                    {
                        propertyType = Nullable.GetUnderlyingType(propertyInfo.PropertyType);
                    }

                    columnValue = Convert.ChangeType(columnValue, propertyType);
                    propertyInfo.SetValue(Object, columnValue, null);
                }
            }
        }
 public static int InsertResultItem(SQLiteCommand command, DataRecord record, string tableName)
 {
     command.CommandText = $"INSERT into '{tableName}'(name, date) values('{record.GetName()}','{record.GetDate().ToString()}');";
     command.ExecuteNonQuery();
     return(0);
 }