PixBean b = new PixBean("az", "123", "az235", "Action",l, 15, 0);
要得到当前对象的值放到ArrayList中这是实际应用
MyCreateAttribute(pix, "pixName", p.PixName);
MyCreateAttribute(pix, "pixDerict", p.PixDerict);
MyCreateAttribute(pix, "pixMostlyMan", p.PixMostlyMan);
MyCreateAttribute(pix, "pixType", p.PixType);
MyCreateAttribute(pix, "pixPrice", p.PixPrice.ToString());
MyCreateAttribute(pix, "pixRebate", p.PixRebate.ToString());
MyCreateAttribute(pix, "pixPictruePath",p.PixPictruePath);
MyCreateTestNode(pix, p.PixTime);
我的意思是我不想 MyCreateAttribute(pix, "pixName", p.PixName);这样p.xxx,p.xxx,p.xxx;取值
要得到当前对象的值放到ArrayList中这是实际应用
MyCreateAttribute(pix, "pixName", p.PixName);
MyCreateAttribute(pix, "pixDerict", p.PixDerict);
MyCreateAttribute(pix, "pixMostlyMan", p.PixMostlyMan);
MyCreateAttribute(pix, "pixType", p.PixType);
MyCreateAttribute(pix, "pixPrice", p.PixPrice.ToString());
MyCreateAttribute(pix, "pixRebate", p.PixRebate.ToString());
MyCreateAttribute(pix, "pixPictruePath",p.PixPictruePath);
MyCreateTestNode(pix, p.PixTime);
我的意思是我不想 MyCreateAttribute(pix, "pixName", p.PixName);这样p.xxx,p.xxx,p.xxx;取值
//List<T>//T的类型定为P.XXX的类型//循环取值//不知道楼主说的是不是这个意思。
ArrayList list = new ArrayList();
list.add(p.xxx);
using System;
using System.Collections.Generic;
using System.Text;
using System.Reflection;namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{ B b = new B();
b.P1 = 6;
B c = new B();
Console.WriteLine(c.P1.ToString());
PropertyInfo[] props = typeof(B).GetProperties();
foreach (PropertyInfo p in props)
{
p.SetValue(c, p.GetValue(b, null), null);//(p.PropertyType);
} Console.WriteLine(c.P1.ToString());
Console.Read(); }
} public class B
{
int p1; public int P1
{
get { return p1; }
set { p1 = value; }
} public B()
{
}
}
}
using System;
using System.Collections.Generic;
using System.Text;
using System.Reflection;namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{ B b = new B();
b.P1 = 6;
B c = new B();
Console.WriteLine(c.P1.ToString());
PropertyInfo[] props = typeof(B).GetProperties();
foreach (PropertyInfo p in props)
{
p.SetValue(c, p.GetValue(b, null), null);//(p.PropertyType);
} Console.WriteLine(c.P1.ToString());
Console.Read(); }
} public class B
{
int p1; public int P1
{
get { return p1; }
set { p1 = value; }
} public B()
{
}
}
}
不过要注意的是如果属性是一个引用类型的话,这个方法只会将对象的引用传给c
也就是c和b的该属性会指向同一个对象要想拷贝真的值的话还要加入一些判断或者直接该类B
h这句话是什么意思呢
using System;
using System.Collections.Generic;
using System.Text;
using System.Reflection;namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{ B b = new B();
b.P1 = 6;
b.MyList.Add(1);
b.MyList.Add(2);
B c = new B(); PropertyInfo[] props = typeof(B).GetProperties();
foreach (PropertyInfo p in props)
{
p.SetValue(c, p.GetValue(b, null), null);//(p.PropertyType);
} c.MyList.Remove(1); // Console.WriteLine("Mylist of b:");
foreach(int item in b.MyList)
Console.WriteLine(item.ToString()); Console.WriteLine("Mylist of c:");
foreach (int item in c.MyList)
Console.WriteLine(item.ToString()); Console.Read(); }
} public class B
{
int p1;
List<int> list; public int P1
{
get { return p1; }
set { p1 = value; }
} public List<int> MyList
{
get { return list; }
set
{
foreach(int item in value)// 拷贝集合中的值而不是将该集合的引用传给list
list.Add(item);
}
} public B()
{
list = new List<int>();
}
}
}结果
------------
Mylist of b:
1
2
Mylist of c:
2
--------------------------------
是指将b对象的p这个property符给c对象的同一个property
foreach (PropertyInfo pr in p)
{
list.Add(像这个list里面怎么添加);
}