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); }
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); }
public void Struct() { EmployeeStruct employeeStruct = new EmployeeStruct(); employeeStruct.Id = _employee.Id; employeeStruct.Name = _employee.Name; employeeStruct.Designation = _employee.Designation; }