测试例

    [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.






 

相关文章:

  • 2021-11-25
  • 2021-05-19
  • 2021-10-23
  • 2021-07-08
  • 2022-01-15
  • 2021-12-03
  • 2022-01-05
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-08-10
  • 2022-12-23
  • 2022-01-03
  • 2022-12-23
  • 2021-09-25
相关资源
相似解决方案