我有类ObservableCollection和其他属性。所以看起来有点像这样:
public class A
{
public int Id { get; set; }
...
public object AValue {get; set;}
}
Run Code Online (Sandbox Code Playgroud)
我想要此类的克隆对象。AValue属性可以是ObservableCollection或其他对象。当AValue类型为ObservableCollection时,我尝试向其中添加一些对象,似乎克隆具有与原始对象相同的对象。如果我仅将克隆方法用于AValueProperty,而不是对类对象使用,A则它将起作用。要克隆我尝试使用的对象:
private object Clone(object obj)
{
var t = obj.GetType();
if (obj == null)
return null;
if (t.IsValueType || t == typeof(string))
{
return obj;
}
else if (t.IsGenericType)
{
if (obj is IList)
{
var c= typeof(ObservableCollection<>);
var cType = type.GetGenericArguments().First();
var gType = c.MakeGenericType(cType);
var newC = …Run Code Online (Sandbox Code Playgroud) 我有一堂课:
public class Doc
{
public int Id {get; set;}
public string Name {get; set;}
public bool IsActive {get; set;}
}
Run Code Online (Sandbox Code Playgroud)
和两个列表Doc类型。
IsActive如果包含第二个列表的ID,如何编写LINQ来比较这些列表并更改第一个列表的属性。