我正在第一次在visual studio中编写测试用例c#我有一个返回对象列表的方法,我想通过使用该Assert.AreEqual()方法将它与另一个对象列表进行比较.
我尝试这样做,但即使两个对象相同,断言也会失败.
我想知道这个方法,这两个参数是比较引用还是对象的内容,
我是否必须让==操作员超负荷工作?
我想得到所有具有空值的字段,但我甚至得到任何字段:
[Serializable()]
public class BaseClass
{
[OnDeserialized()]
internal void OnDeserializedMethod(StreamingContext context)
{
FixNullString(this);
}
public void FixNullString(object type)
{
try
{
var properties = type.GetType().GetFields();
foreach (var property in from property in properties
let oldValue = property.GetValue(type)
where oldValue == null
select property)
{
property.SetValue(type, GetDefaultValue(property));
}
}
catch (Exception)
{
}
}
public object GetDefaultValue(System.Reflection.FieldInfo value)
{
try
{
if (value.FieldType == typeof(string))
return "";
if (value.FieldType == typeof(bool))
return false;
if (value.FieldType == typeof(int))
return 0;
if (value.FieldType …Run Code Online (Sandbox Code Playgroud)