1

I have a data contract "StudentInformation" in my class library, something like this:

public class StudentInformation
{
    public int StudentId { get; set; }
    public bool CanChangeBus { get; set; }
    public List<int> AvailableBuses { get; set; }
}

public class BusChangeRequestModel
{
    public StudentInformation StudentInfo { get; set; }
    ...
    ...
}

public class BusChangeResponseModel
{
    public StudentInformation StudentInfo { get; set; }
    ...
}

The Request model sends in StudentId, the class library processes the information and populates the properties "CanChangeBus" and "AvailableBuses", which are then returned in the response model.

I want to hide the properties "CanChangeBus" and "AvailableBuses" from the request model. If I change the setter of these properties to "internal" then the properties cannot be set by calling application but they are still visible. How can I hide them from calling application's instance of request model?

CodeFreak
  • 13
  • 3

3 Answers3

3
public class BasicStudentInformation
{
    public int StudentId { get; set; }
}

public class StudentInformation : BasicStudentinformation
{
    public bool CanChangeBus { get; set; }
    public List<int> AvailableBuses { get; set; }
}

public class BusChangeRequestModel
{
    public BasicStudentInformation StudentInfo { get; set; }
    ...
    ...
}

public class BusChangeResponseModel
{
    public StudentInformation StudentInfo { get; set; }
    ...
}
Riad Baghbanli
  • 3,105
  • 1
  • 12
  • 20
1

Using inheritance. Something like:

public class StudentBase
{
    public int StudentId { get; set; }
}

public class StudentInformation : StudentBase
{
    public bool CanChangeBus { get; set; }
    public List<int> AvailableBuses { get; set; }
}

public class BusChangeRequestModel
{
    public StudentBase StudentInfo { get; set; }
    ...
    ...
}

public class BusChangeResponseModel
{
    public StudentInformation StudentInfo { get; set; }
    ...
}
Charlie
  • 1,265
  • 15
  • 18
0

So BusChangeRequest only needs to see the id, then it should only have the id.

public class StudentInformation
{
    public int StudentId { get; set; }
    public bool CanChangeBus { get; set; }
    public List<int> AvailableBuses { get; set; }
}

public class BusChangeRequestModel
{
    public int StudentId { get; set; }
}

//I don't know what is expected as a repsonse?  Is StudentInfromation really the correct response
//or is something like "Accepted", "rejected", Fail...???
public class BusChangeResponseModel
{
    public StudentInformation StudentInfo { get; set; }
}
XenoPuTtSs
  • 1,254
  • 1
  • 11
  • 31