Hi, I am working with an App on Xamarin.Forms that instances an object and saves it on a JSON file. I have the following classes
[Serializable]
public class CustomTask
{
public string collectionId { get; set; }
public string taskId { get; set; }
public int taskPosition { get; set; }
public string taskName { get; set; }
public int taskHours { get; set; }
public int taskMinutes { get; set; }
public int taskSeconds { get; set; }
}
[Serializable]
public class TaskCollection
{
public string collectionId { get; set; }
public string collectionName { get; set; }
public int collectionPosition { get; set; }
public List<CustomTask> tasks { get; set; }
public TaskCollection() { tasks = new List<CustomTask>(); }
}
Then I call a method that creates an instance of TaskCollection for testing (which I made rather verbose for testing) :
public TaskCollection getTC()
{
string colId= "Test ID";
TaskCollection tc = new TaskCollection();
tc.collectionId = colId;
tc.collectionName = "Test Task Collection";
tc.collectionPosition = 1;
CustomTask ct1 = new CustomTask { collectionId = colId, taskHours = 1, taskId = "1", taskMinutes = 10, taskName = "First Task", taskPosition = 1, taskSeconds = 0 };
CustomTask ct2 = new CustomTask { collectionId = colId, taskHours = 2, taskId = "2", taskMinutes = 12, taskName = "Second Task", taskPosition = 2, taskSeconds = 0 };
CustomTask ct3 = new CustomTask { collectionId = colId, taskHours = 3, taskId = "3", taskMinutes = 13, taskName = "Third Task", taskPosition = 3, taskSeconds = 0 };
CustomTask ct4 = new CustomTask { collectionId = colId, taskHours = 4, taskId = "4", taskMinutes = 14, taskName = "Fourth Task", taskPosition = 4, taskSeconds = 0 };
List<CustomTask> list = new List<CustomTask>();
list.Add(ct1);
list.Add(ct2);
list.Add(ct3);
list.Add(ct4);
tc.tasks = list;
return tc;
}
While Debugging I can see that all CustomTask and TaskCollection objects have all their properties under a Non-public members nest, and for each property an additional object called <"propety name">k_BackingField was created. For List list, the inspection shows a value of (null) right after being instantiated, yet it won't trigger a null reference during the Add calls. When it goes on to serialization and storage all it creates is an empty string, since everything became non-public.
I have tried using non automatic setters and getters, marking the class with [Newtonsoft.Json.JsonObject], and marking [DataContract] with [DataMember] on each property, changing the Linking options from None to SDK Assemblies Only to SDK and User. Also tried cleaning, rebuilding, restarting, and deleting obj and bin folders. Also tried creating new classes on new files, and changing targets Android API 23, 24, 25, and 26). None of these have worked.
My Xamarin version is 2.5.1.4449 and the project is a Xamarin.Forms Shared Project. I appreciate any new direction you might give me into making this simple data structure to be recognized properly. Thank you.
Update
Made a new Xamarin.Forms Project with .Net Standard, and ended up with the same results.
Also, I'm using Visual Studio 2017 (Version 15.6.6)