Ngugi1 / sqlite-net

Automatically exported from code.google.com/p/sqlite-net
0 stars 0 forks source link

Change Insert and Update to Generics #15

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
Hi,

Please change Update and Insert to use Generics instead of just object.
That allows me to save inherited classes as their base class.

e.g. 
public class Animal{}
public class Dog : Animal {}

db.CreateTable<Animal>()

Dog myDog = new Dog(); 
If I do:
db.Insert(myDog)
it wil die telling me there is no Dog table which is correct but I want to tell 
it to save the Dog as an Animal.:
db.Insert<Animal>(myDog);

All you need to do it change the first few lines:
public int Update<T> (T obj)
{
    if (obj == null) {
        return 0;
    }
    var map = GetMapping (typeof(T));
[...]

This change it backward compatible as well.

Corneliu.

Original issue reported on code.google.com by corneliu...@gtempaccount.com on 17 Jun 2010 at 2:40

GoogleCodeExporter commented 9 years ago
Added in Rev 58

This has been implemented but instead of using generics, you can now pass a 
Type argument. The MonoTouch developers recommended the Type arg over the 
generic arg as it reduces the final code size.

Original comment by frank.al...@gmail.com on 29 Jun 2010 at 6:52