public static int Main(string[] args) { Console.WriteLine("\nReflection.PropertyInfo"); // Define a property. Myproperty Myproperty = new Myproperty(); Console.Write("\nMyproperty.Caption = " + Myproperty.Caption); // Get the type and PropertyInfo. Type MyType = Type.GetType("Myproperty"); PropertyInfo Mypropertyinfo = MyType.GetProperty("Caption"); // Get and display the attributes property. PropertyAttributes Myattributes = Mypropertyinfo.Attributes; Console.Write("\nPropertyAttributes - " + Myattributes.ToString()); return(0); }
static void Main(string[] args) { Console.WriteLine("\nReflection.PropertInfo"); //定义一个Myproperty类对象 Myproperty myproperty = new Myproperty(); //定义MyType获取Myproperty的类型 Type Mytype = Type.GetType("Myproperty"); //定义一个PropertyInfo类对象,获取MyType的Caption值 PropertyInfo MypropertyInfo = Mytype.GetProperty("Caption"); Console.Write("\nGetValue - " + MypropertyInfo.GetValue(myproperty, null)); //重新设置Myproperty的Caption值 MypropertyInfo.SetValue(myproperty, "This caption has been changed", null); Console.Write("\n" + Mytype.FullName + "." + MypropertyInfo.Name + " has a PropertyType of " + MypropertyInfo.PropertyType); Console.Write("\nGetValue - " + MypropertyInfo.GetValue(myproperty, null)); MethodInfo MygetmethodInfo = MypropertyInfo.GetSetMethod(); Console.Write("\nSetAccessor for " + MypropertyInfo.Name + " return a " + MygetmethodInfo.ReturnType); Console.Write("\n\n" + Mytype.FullName + "." + MypropertyInfo.Name + " GetSetMethod - " + MypropertyInfo.GetSetMethod()); }
public void NavigateToMyProperty() { _Wait.Until(ExpectedConditions.ElementExists(By.XPath("//a[@href='/PropertyOwners']"))); Myproperty.Click(); }