public static void ValueTypesShouldNotContainId()
        {
            //Struct as root.
            EmployeeStruct employee = new EmployeeStruct
            {
                Name = "Angela",
                //Struct as property.
                Job = new JobStruct
                {
                    Title = "Software Engineer"
                },
                //ImmutableArray<T> as property.
                Roles =
                    ImmutableArray.Create(
                        new RoleStruct
                {
                    Description = "Contributor"
                },
                        new RoleStruct
                {
                    Description = "Infrastructure"
                })
            };

            //ImmutableArray<T> as root.
            ImmutableArray <EmployeeStruct> array =
                //Struct as array element (same as struct being root).
                ImmutableArray.Create(employee);

            // Regardless of using preserve, do not emit $id to value types; that is why we compare against default.
            string actual   = JsonSerializer.Serialize(array, s_serializerOptionsPreserve);
            string expected = JsonSerializer.Serialize(array);

            Assert.Equal(expected, actual);
        }
示例#2
0
        static List <EmployeeStruct> ReadCsvFileAsStruct()
        {
            string filePath = GetCSVFileName();
            List <EmployeeStruct> employees = new List <EmployeeStruct>();

            char[]   separators = { ',' };
            string[] input;

            StreamReader sr = new StreamReader(filePath);

            string data = string.Empty;

            while ((data = sr.ReadLine()) != null)
            {
                input = data.Split(separators, StringSplitOptions.RemoveEmptyEntries);
                var            id        = Convert.ToInt32(input[0]);
                var            firstName = input[1];
                EmployeeStruct e         = new EmployeeStruct(id, firstName, input);

                employees.Add(e);
                //Console.WriteLine(input[1]);
            }

            return(employees);
        }
示例#3
0
        public void Struct()
        {
            EmployeeStruct employeeStruct = new EmployeeStruct();

            employeeStruct.Id          = _employee.Id;
            employeeStruct.Name        = _employee.Name;
            employeeStruct.Designation = _employee.Designation;
        }