C# GCollection API

Constructors

  Name Description
GCollection<T>(string xmlPath) Initializes new instance of the GCollection class based on given xmlPath string variable

GCollection Properties

  Name Description
XmlDocument _xmlDocument Get or Set the GCollection XmlDocument object
string _xmlPath Get or Set the GCollection string filepath

GCollection T Get Properties

  Name Description
T Get(string id) Gets an generic T type from the GCollection based on string id
List T GetList() Gets an generic List T with all generic T objects from the GCollection (LINQ Supported)

GCollection T Object Methods

  Name Description
Add(T gObject) Add new generic type gObject instance to GCollection
Update(T gObject) Update existing generic type gObject instance in GCollection
Delete(T gObject)
Delete generic type gObject instance from GCollection
DeleteAt(string id)
Delete generic type gObject instance from GCollection by string id
DeleteAll(query)
Delete all generic type gObject instances from GCollection by LINQ query

GCollection Database Methods

  Name Description
CreateDB() Create new db file (xml based) to the location based on the GCollection _xmlPath string property
CreateDB(string xmlPath) Create new db file (xml based) to the location based on the given xmlPath string variable
LoadDB()
Load GCollection DB file (xml based) from the location based on the GCollection _xmlPath string property
LoadDB(string xmlPath) Load GCollection DB file (xml based) from the location based on the given xmlPath string variable
FlushDB() Flush all collection entries in the GCollection DB
SaveDB() Save all changes made to the GCollection DB to a file (xml based) from the location based on the GCollection _xmlPath string property

GCollection Code Example (Create a GCollection Database.cs)


  using GCollection;
  using System.Xml.Serialization;

  namespace GCollectionExampleApp
  {
      // Define database model
      // With filename/classname of your choice
      class Person
      {

          [XmlAttribute("id")] // Note : XmlAttribute("id") is mandatory in every GCollection object
          public string ID { get; set; } 

          // 
          // Define public properties of your choice
          // 

          public string Name { get; set; }

          public int Age { get; set; }

      }

      // Define GCollection Database
      // With filename/classname of your choice
      // Inherit database model of choice
      class Database : GCollection<Person>
      {
          public Database(string xmlPath) : base(xmlPath) { }
      }
  }

  

GCollection Code Example (Add Database Entry)


  // create & initialize database path
  string databasePath = "C:\\Users\\Thoosje\\Databases\\database.xml";

  // initialize gcollection Database class
  Database database = new Database(databasePath);
  // load database
  database.LoadDB();

  // add new person to database
  database.Add(new Person() {
      ID=Guid.NewGuid().ToString(),
      Name = "Mr Snuggels",
      Age = 20
  });

  // save changes in the dabase
  database.SaveDB();
  // close database connection
  database.CloseDB();
  

GCollection Code Example (Update Database Entry)


  // create & initialize database path
  string databasePath = "C:\\Users\\Thoosje\\Databases\\database.xml";

  // initialize gcollection database object
  Database database = new Database(databasePath);
  // load database
  database.LoadDB();

  // get list of all database entries
  List<Person> allDatabaseEntries = database.GetList();

  // update each selected person(s)
  foreach (Person personToEdit item in allDatabaseEntries)
  {
      // make changes to person (by increasing he's age or something)
      personToEdit.Age++;
      // update "personToEdit" in the database
      database.Update(personToEdit);
  }

  // save changes made to database on drive
  database.SaveDB();
  // close database connection
  database.CloseDB();
  

GCollection Code Example (Remove Database Entry)


  // create & initialize database path
  string databasePath = "C:\\Users\\Thoosje\\Databases\\database.xml";

  // initialize gcollection database object
  Database database = new Database(databasePath);
  // load database
  database.LoadDB();

  // get list of all database entries
  List<Person> allDatabaseEntries = database.GetList();

  // remove first entry in the database
  database.Delete(allDatabaseEntries[0]);
  // delete all persons under 25 (with LINQ)
  database.DeleteAll(x=> x.Age < 25);

  // save changes made to database on drive
  database.SaveDB();
  // close database connection
  database.CloseDB();