2016-09-22 4 views
0

나는재사용 모델은

public class CreateStudent 
{ 
    public int Id { get; set; } 
    public string Name { get; set; } 
    public string Address { get; set; } 
    public int Age { get; set; } 
} 

아래와 같이 교류 # 클래스를 가지고 내가 그 하나 개의 필드 (Date_of_Birth) 제외하고 속성을 반복 한

public class EditStudent 
{ 
    public string Name { get; set; } 
    public string Address { get; set; } 
    public int Age { get; set; } 
    public DateTime Date_of_Birth { get; set; } 
} 

다음과 같은 특성을 가진 다른 클래스가 필요 EditStudent 모델에 추가됩니다. 이전 CreateStudent 모델

내 프런트 엔드에서 AngularJS와 기반 응용 프로그램을 JSON 개체로 이러한 데이터를 처리하기 위하여려고하고있다

+2

* 상속 * - https://msdn.microsoft.com/en-us/library/ms173149.aspx를 참조하십시오. – kiziu

답변

3

당신은 널 수 속성을 사용하여이 작업을 수행 할 수 있습니다.

public class Student 
{ 
    public int Id { get; set; } 
    public string Name { get; set; } 
    public string Address { get; set; } 
    public int Age { get; set; } 
    public DateTime? Date_of_Birth { get; set; } 
} 

이렇게하면 유스 케이스 둘 다를 수용 할 수있는 하나의 학생 모델 만 있습니다.

2

사용되어야 상속 기능에서 속성의 일부를 재사용 할 수있는 옵션이 있습니까 이리.

public class CreateStudent 
{ 
    public int Id { get; set; } 
    public string Name { get; set; } 
    public string Address { get; set; } 
    public int Age { get; set; } 
} 
public class EditStudent : CreateStudent 
{ 
    public DateTime Date_of_Birth { get; set; } 
} 

enter image description here