Click here to Skip to main content
15,886,806 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I have the following Json and I have converted to classes

Json :
{
	"schedule": {
		"afterStartMinutesBase": 0,
		"beforeStartMinutesBase": 0,
		"scheduleType": 2,
		"id": "00000000-0000-0000-0000-000000000000",
		"currentSchedule": {
			"internalType": 2,
			"daysOfWeek": [
				0,
				4,
				5,
				3
			],
			"weeksInterval": 1,
			"daysOfWeekSource": [{
					"name": "Sunday",
					"value": 0,
					"isSelectedInternal": true
				},
				{
					"name": "Monday",
					"value": 1,
					"isSelectedInternal": false
				},
				{
					"name": "Tuesday",
					"value": 2,
					"isSelectedInternal": false
				},
				{
					"name": "Wednesday",
					"value": 3,
					"isSelectedInternal": true
				},
				{
					"name": "Thursday",
					"value": 4,
					"isSelectedInternal": true
				},
				{
					"name": "Friday",
					"value": 5,
					"isSelectedInternal": true
				},
				{
					"name": "Saturday",
					"value": 6,
					"isSelectedInternal": false
				}
			],
			"weeksIntervalOptions": {
				"min": 1,
				"max": 999,
				"decimals": 0,
				"format": "###,###"
			}
		},
		"startBoundary": "2020-02-04T00:00:00-05:00",
		"scheduleByWeek": {
			"internalType": 2,
			"daysOfWeek": [
				0,
				4,
				5,
				3
			],
			"weeksInterval": 1,
			"daysOfWeekSource": [{
					"name": "Sunday",
					"value": 0,
					"isSelectedInternal": true
				},
				{
					"name": "Monday",
					"value": 1,
					"isSelectedInternal": false
				},
				{
					"name": "Tuesday",
					"value": 2,
					"isSelectedInternal": false
				},
				{
					"name": "Wednesday",
					"value": 3,
					"isSelectedInternal": true
				},
				{
					"name": "Thursday",
					"value": 4,
					"isSelectedInternal": true
				},
				{
					"name": "Friday",
					"value": 5,
					"isSelectedInternal": true
				},
				{
					"name": "Saturday",
					"value": 6,
					"isSelectedInternal": false
				}
			],
			"weeksIntervalOptions": {
				"min": 1,
				"max": 999,
				"decimals": 0,
				"format": "###,###"
			}
		},
		"maxRunTime": "2:0:0",
		"repetition": null,
		"type": 32768
	},
	"taskOptions": {
		"internalType": 0,
		"information": "Data Clean up Auto"
	},
	"ignoreErrors": false
}



Here is my main model class that has the member properties:
I am having trouble setting the values of List<daysofweeksource> and List<daysofweeksource2>


public class Model
{



        public static AdminServiceTaskModel CreateServiceTaskModel()
        {
            return new AdminServiceTaskModel()
            {
                schedule = new AdminServiceTaskModel.Schedule
                {
                    afterStartMinutesBase = 0,
                    beforeStartMinutesBase = 0,
                    scheduleType = 2,
                    id = "00000000-0000-0000-0000-000000000000",
                    currentSchedule =
                    {
                        internalType = 2,
                        daysOfWeek = new List<int> { 0, 4, 5, 3 },
                        weeksInterval = 1,
                        daysOfWeekSource = new List<DaysOfWeekSource>
                        {
                           

                        },
                        weeksIntervalOptions =
                        {
                            min = 1,
                            max = 999,
                            decimals = 0,
                            format = "###,###"

                        }
                    },
          startBoundary = new DateTime(2020, 3, 31, 0, 0, 0, DateTimeKind.Local),
                    scheduleByWeek =
                    {
                        internalType = 2,
                        daysOfWeek =  new List<int> { 0,4,5,3},
                        weeksInterval = 1,
                        daysOfWeekSource  = new List<DaysOfWeekSource2>  
                        {
                            
                         
                        },
                        weeksIntervalOptions =
                        {
                            min = 1,
                            max = 999,
                            decimals = 0,
                            format = "###,###"
                        }
                        
                    },
                    maxRunTime = "2:0:0",
                    repetition = null,
                    type = 32768,
                    



                },
                taskOptions = new AdminServiceTaskModel.TaskOptions
                {
                    internalType = 0,
                    information = "Data Clean up Auto"
                },

                ignoreErrors = false

            };

        }






        public class DaysOfWeekSource
        {
            public string name { get; set; }
            public int value { get; set; }
            public bool isSelectedInternal { get; set; }
        }
        
        public class WeeksIntervalOptions
        {
            public int min { get; set; }
            public int max { get; set; }
            public int decimals { get; set; }
            public string format { get; set; }
        }
        
        public class CurrentSchedule
        {
            public int internalType { get; set; }
            public List<int> daysOfWeek { get; set; }
            public int weeksInterval { get; set; }
            public List<DaysOfWeekSource> daysOfWeekSource { get; set; }
            public WeeksIntervalOptions weeksIntervalOptions { get; set; }
        }
        
        public class DaysOfWeekSource2
        {
            public string name { get; set; }
            public int value { get; set; }
            public bool isSelectedInternal { get; set; }
        }
        
        public class WeeksIntervalOptions2
        {
            public int min { get; set; }
            public int max { get; set; }
            public int decimals { get; set; }
            public string format { get; set; }
        }
        
        public class ScheduleByWeek
        {
            public int internalType { get; set; }
            public List<int> daysOfWeek { get; set; }
            public int weeksInterval { get; set; }
            public List<DaysOfWeekSource2> daysOfWeekSource { get; set; }
            public WeeksIntervalOptions2 weeksIntervalOptions { get; set; }
        }
        
        public class Schedule
        {
            public int afterStartMinutesBase { get; set; }
            public int beforeStartMinutesBase { get; set; }
            public int scheduleType { get; set; }
            public string id { get; set; }
            public CurrentSchedule currentSchedule { get; set; }
            public DateTime startBoundary { get; set; }
            public ScheduleByWeek scheduleByWeek { get; set; }
            public string maxRunTime { get; set; }
            public object repetition { get; set; }
            public int type { get; set; }
        }
        
        public class TaskOptions
        {
            public int internalType { get; set; }
            public string information { get; set; }
        }
        
           
            public Schedule schedule { get; set; }
            public TaskOptions taskOptions { get; set; }
            public bool ignoreErrors { get; set; }



}


What I have tried:

I have tried to created a new instance of List<daysofweeksource> and List<daysofweeksource2> but I am unable to get the member properties
public string name { get; set; }
public int value { get; set; }
public bool isSelectedInternal { get; set; }
Posted
Comments
ZurdoDev 31-Mar-20 14:09pm    
Can you post the code that you are having problems with?
Member 14779968 31-Mar-20 14:12pm    
this is the exact code that i am having problem with
ZurdoDev 31-Mar-20 14:18pm    
But where is the code where you are trying to access the name property and can't and what is the error?
Member 14779968 31-Mar-20 14:30pm    
I am trying to access the properties here .

daysOfWeekSource = new List<daysofweeksource>
{
name = "Monday",
value = 1,
isSelectedInternal = true
},

Error: 'List<adminservicetaskmodel.daysofweeksource>' does not contain a definition of 'name'
ZurdoDev 31-Mar-20 14:42pm    
Because it is a list, not a single instance, so you can't initialize that way.

List<daysofweeksource> daysOfWeekSources = new List<daysofweeksource>();
daysOfWeekSource item = new daysOfWeekSource();
item.Name = "";
...
daysOfWeekSources.Add(item);

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900