Skip to content

Get Started

Felipe Bellini edited this page Jun 17, 2020 · 2 revisions

Download ReflectXMLDB from our nuget links.

ReflectXMLDB offers the traditional Get, Insert, Remove and Update item(s) capabilities commonly present in other database frameworks. Also, it provides a more low level interface with the database files generated, such as the ability to Export and Import the database files to .db files, which are compressed versions of the workspace.

There are a few rules that need to be understood when using ReflectXMLDB.

  1. ReflectXMLDB creates a database XML file for each database initialized and/or instantiated.
  2. Every database class must inherit from ReflectXMLDB.Interface.IDatabase and end its name with "Database". Also must provide a single ICollection (such as Arrays, Lists, ObservableCollections, etc.) of the item that it will store.
  3. Every database object must inherit from ReflectXMLDB.Interface.ICollectableObject.
  4. Database classes and objects must be in the same namespace.
  5. That is it!

Example:

    //Initializes ReflectXMLDB database handling class.
    DatabaseHandler dh = new DatabaseHandler();

    //Creates the workspace.
    string workspace = "\\DBSample";
    Type[] databaseTypes = new Type[] { typeof(SampleDatabase) };
    dh.SetWorkspace(workspace, databaseTypes);
    
    //Creates a database file.
    //SampleDatabase inherits from IDatabase.
    dh.CreateDatabase<SampleDatabase>();

    //Creates a list of objects to be inserted.
    //Sample inherits from ICollectableObject and is in the same namespace of SampleDatabase
    List<Sample> samples = new List<Sample>();
    for (int i = 0; i < 10; i++)
    {
        samples.Add(new Sample() { SomeData = string.Format("Data{0}", i) });
    }

    //Inserts the items in the database.
    dh.Insert(samples);

    //Gets all samples in the database.
    var queryAllSamples = dh.Get<Sample>();
    //Gets all samples that have Data5 as the value of the SomeData property.
    var querySomeSamples = dh.Get<Sample>("SomeData","Data5");

    //Removes some of the items in the database.
    dh.Remove<Sample>(querySomeSamples);

    //Exports the database to a .db file.
    dh.ExportDatabase("\\Place\\", "copyOfSampleDatabase1");

    //Deletes the database
    dh.DeleteDatabase<SampleDatabase>();

    //Deletes the workspace and clears the internal resources.
    dh.ClearHandler();

Where Sample is:

    public class Sample : ICollectableObject
    {
        [XmlAttribute]
        public string GUID { get; set; }
        [XmlAttribute]
        public uint EID { get; set; }
        public string SomeData { get; set; }
    }

And SampleDatabase is:

    public class SampleDatabase : IDatabase
    {
        [XmlAttribute]
        public string GUID { get; set; }
        public Sample[] Samples { get; set; }
    }
Clone this wiki locally