火星文 技术研习社

Noname Cat, Keep Thinking
  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

dot Net 版的 copyProperties

Posted on 2006-09-21 05:53  剑廿三  阅读(309)  评论(0编辑  收藏  举报

测试例

    [TestFixture]
    
public class Class1
    {
        
private string name;
        
public Class1()
        {
            
//
            
// TODO: 在此处添加构造函数逻辑
            
//
        }

        
public string Name
        {
            
get
            {
                
return this.name;
            }

            
set
            {
                
this.name = value;
                
            }
        }

        [Test]
        
public void Test()
        {
            Class1 c 
= new Class1();
            
object[] objs = new object[1];
            objs[
0= "stephen";

            MethodInfo[] methods 
= typeof(Class1).GetMethods();

            
foreach(MethodInfo m in methods)
            {
                
if(m.Name.StartsWith("set_"))
                {
                    m.Invoke(c, objs);


                }

                Console.WriteLine(m.Name);
            }

            Console.WriteLine(c.Name);
        }
    }

输出:

------ Test started: Assembly: Cosmos.SpaceStation.Share.BeanUtils.dll ------

GetHashCode
Equals
ToString
get_Name
set_Name
Test
GetType
stephen

1 passed, 0 failed, 0 skipped, took 0.77 seconds.