Spike Five - Establishing and setting Data type class
A downloadable project
Spike Five - Establishing and setting Data type class
Introduction
This spike will explore establishing one class to set appropriate data types from the csv. Previously across the csv conversion script and the json reader script there were two separate classes that set the data types for the data's columns and they were only set to a data type of a string.
Goals
- Establish one class to set the data's data types as oppose to duplicating this class.
- Ensure that the class can be called when needed.
- Assign appropriate data types.
- Ensure that the data types are handled appropriately to be parsed into a list.
Personnel
Primary - Zackery Camille [1095725]
Secondary - Christian
Technologies, Tools, and Resources used
Tasks Undertaken
- Remove (delete) the second data type class in the json reader script and then open the csv conversion script.
- Apply appropriate data types to each field just like below for example.
/// <summary> /// The 'ExampleDataType' class handles initialising all of the data types for the item columns pertaining to the data, /// held in the csv and TextAsset. /// </summary> [System.Serializable] public class ExampleDataType { public int exampleInt; public string exampleString; }
3. Create a new class and initialise a new instance of the data type class so that the newly created class can house getters for the data type class fields.
/// <summary> /// The 'Example' class handles creating getters for the item data types so that they can be accessed in other classes. /// This is done by creating an new instance of 'ExampleDataType' and creating a return statement in a variable for, /// each item column. /// </summary> public class Example { public ExampleDataType exampleDataType= new ExampleDataType(); public int GetExampleInt() { return exampleDataType.exampleInt; } public string GetExampleString() { return exampleDataType.exampleString; }
4. In the method where each record of the data is created and added to the list, for each field with a data type of int use,
int.TryParse(csvGrid[0, i], out newDataRecord.exampleDataStats.exampleInt);
For a more deeper understanding and context download the 'CSV_JSON_CONVERSION.cs' file.
5. Lastly in the json reader script add the following class as follows,
/// <summary> /// The 'ExampleCollection' class handles returning the data types Getters from the 'Example' class located in step three. /// A new instance of the 'Example' class is created to allow each fields data type, /// to be referenced and returned appropriately. /// </summary> [System.Serializable] public class ExampleCollection { public Example jrGetExampleDataType = new Example(); public int JRGetExampleInt() { return jrGetExampleDataType.GetExampleInt(); } public int JRGetExampleString() { return jrGetExampleDataType.GetExampleString(); } }
For a more deeper understanding and context download the 'Item_JSON_Reader.cs' file.
Solution Justification
The reasoning behind these tasks being conducted during this spike was to ensure I was maintaining proper coding conventions as per the coding guidelines from the previous spike. Not to mention object orientated languages are made for such cases to initialise a class once and be called when needed. So removing the duplicated classes and code to be set once and called when needed is the nature of object orientated languages like C#.
It was also essential for me to parse through a field of type int when creating new records from the data as it is appropriate for the fields from the data to be more than just a string. The video source, 'Unity Tutorial - Using CSV Files' from the Technologies, Tools, and Resources used section helped me remember the solution as I have previously refereed to this source back in spike two.
Status | Released |
Category | Other |
Author | Duck Pond Studios |
Leave a comment
Log in with itch.io to leave a comment.