Tôi đã hoàn thành mã hóa đơn đăng ký của mình. Nhưng khi tôi nhấn nút khởi động, ứng dụng của tôi nêu ra một trường hợp ngoại lệ ..: '(Tôi không biết tại sao lớp học của mình không thể được tuần tự hóa
A first chance exception of type 'System.Runtime.Serialization.InvalidDataContractException' occurred in System.Runtime.Serialization.dll
A first chance exception of type 'System.Reflection.TargetInvocationException' occurred in mscorlib.dll
A first chance exception of type 'System.Runtime.Serialization.InvalidDataContractException' occurred in System.Runtime.Serialization.dll
Vì vậy, tôi thấy lập luận của e 'Application_UnhandledException', và tôi có thể biết lý do ".' Loại 'GPACalculator.Subject' không thể được đăng. Cân nhắc đánh dấu nó với thuộc tính DataContractAttribute, và đánh dấu tất cả các thành viên của nó bạn muốn serialized với thuộc tính DataMemberAttribute."
tôi chỉ làm cho lớp học của tôi sử dụng các loại dữ liệu mặc định ..
public class Subject : INotifyPropertyChanged
{
private string name;
private GradePoint gradePoint;
private int credit;
public Subject(string name)
{
Name = name;
GradePoint = new GradePoint();
}
public string Name
{
get { return name; }
set
{
Debug.WriteLine("Name: " + value);
if (name != value)
{
name = value;
OnPropertyChanged("Name");
}
}
}
public GradePoint GradePoint
{
get { return gradePoint; }
set
{
if (gradePoint != value)
{
gradePoint = value;
OnPropertyChanged("GradePoint");
}
}
}
public int Credit
{
get { return credit; }
set
{
if (credit != value)
{
credit = value;
OnPropertyChanged("Credit");
}
}
}
public event PropertyChangedEventHandler PropertyChanged;
private void OnPropertyChanged(string propertyName)
{
if (PropertyChanged != null) PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
}
}
public class GradePoint : INotifyPropertyChanged
{
private string mainGradePoint;
private string subGradePoint;
private int credit;
public int Credit
{
get { return credit; }
set
{
if (credit != value)
{
credit = value;
OnPropertyChanged("Credit");
}
}
}
public string MainGradePoint
{
get { return mainGradePoint; }
set
{
value = value.ToUpper();
if (mainGradePoint != value)
{
mainGradePoint = value;
OnPropertyChanged("MainGradePoint");
}
}
}
public string SubGradePoint
{
get { return subGradePoint; }
set
{
if (subGradePoint != value)
{
subGradePoint = value;
OnPropertyChanged("SubGradePoint");
}
}
}
public override string ToString()
{
return string.Format("{0}{1}", mainGradePoint, subGradePoint);
}
public double ToDouble(double perfectScore = 4.5F)
{
double gap = perfectScore - Math.Floor(perfectScore);
double value;
switch (mainGradePoint)
{
case "A":
value = 4.0;
break;
case "B":
value = 3.0;
break;
case "C":
value = 2.0;
break;
case "D":
value = 1.0;
break;
default:
value = 0.0;
return value;
}
switch (subGradePoint)
{
case "+":
value += gap;
break;
case "-":
value -= gap;
break;
}
return value;
}
public event PropertyChangedEventHandler PropertyChanged;
private void OnPropertyChanged(string propertyName)
{
if (PropertyChanged != null) PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
}
}
các ở trên là m y lớp ..
hãy giúp tôi
Cảm ơn rất nhiều :) –