反射可以通过FieldInfo.SetValue设置任何字段的值。using System;
反射可以通过FieldInfo.SetValue设置任何字段的值。
using System.Reflection;
反射可以通过FieldInfo.SetValue设置任何字段的值。
using System.Globalization;
反射可以通过FieldInfo.SetValue设置任何字段的值。
反射可以通过FieldInfo.SetValue设置任何字段的值。
public class MyClass
{
反射可以通过FieldInfo.SetValue设置任何字段的值。    
private string myString;
反射可以通过FieldInfo.SetValue设置任何字段的值。    
public MyClass()
{
反射可以通过FieldInfo.SetValue设置任何字段的值。        myString 
= "Old value";
反射可以通过FieldInfo.SetValue设置任何字段的值。    }

反射可以通过FieldInfo.SetValue设置任何字段的值。    
string GetField
{
反射可以通过FieldInfo.SetValue设置任何字段的值。        
get
{
反射可以通过FieldInfo.SetValue设置任何字段的值。            
return myString;
反射可以通过FieldInfo.SetValue设置任何字段的值。        }

反射可以通过FieldInfo.SetValue设置任何字段的值。    }

反射可以通过FieldInfo.SetValue设置任何字段的值。}

反射可以通过FieldInfo.SetValue设置任何字段的值。
反射可以通过FieldInfo.SetValue设置任何字段的值。
public class FieldInfo_SetValue
{
反射可以通过FieldInfo.SetValue设置任何字段的值。    
public static void Main()
{
反射可以通过FieldInfo.SetValue设置任何字段的值。        
try
{
反射可以通过FieldInfo.SetValue设置任何字段的值。            MyClass myObject 
= new MyClass();
反射可以通过FieldInfo.SetValue设置任何字段的值。            Type myType 
= Type.GetType("MyClass");
反射可以通过FieldInfo.SetValue设置任何字段的值。            FieldInfo myFieldInfo 
= myType.GetField("myString", BindingFlags.NonPublic | BindingFlags.Instance); 
反射可以通过FieldInfo.SetValue设置任何字段的值。            
// Display the string before applying SetValue to the field.
反射可以通过FieldInfo.SetValue设置任何字段的值。
            Console.WriteLine( " The field value of myString is {0}.", myFieldInfo.GetValue(myObject)); 
反射可以通过FieldInfo.SetValue设置任何字段的值。            
// Display the SetValue signature used to set the value of a field.
反射可以通过FieldInfo.SetValue设置任何字段的值。
            Console.WriteLine( "Applying SetValue(Object, Object).");    
反射可以通过FieldInfo.SetValue设置任何字段的值。            
// Change the field value using the SetValue method. 
反射可以通过FieldInfo.SetValue设置任何字段的值。
            myFieldInfo.SetValue(myObject, "New value"); 
反射可以通过FieldInfo.SetValue设置任何字段的值。            
// Display the string after applying SetValue to the field.
反射可以通过FieldInfo.SetValue设置任何字段的值。
            Console.WriteLine( "The field value of mystring is {0}.", myFieldInfo.GetValue(myObject));
反射可以通过FieldInfo.SetValue设置任何字段的值。            
// Set the field value to its old value. 
反射可以通过FieldInfo.SetValue设置任何字段的值。
            myFieldInfo.SetValue( myObject , "Old value" ); 
反射可以通过FieldInfo.SetValue设置任何字段的值。            myFieldInfo 
= myType.GetField("myString", BindingFlags.NonPublic | BindingFlags.Instance); 
反射可以通过FieldInfo.SetValue设置任何字段的值。            
// Display the string before applying SetValue to the field.
反射可以通过FieldInfo.SetValue设置任何字段的值。
            Console.Write( " The field value of mystring is {0}. ", myFieldInfo.GetValue(myObject)); 
反射可以通过FieldInfo.SetValue设置任何字段的值。            
// Display the SetValue signature used to set the value of a field.
反射可以通过FieldInfo.SetValue设置任何字段的值。
            Console.WriteLine("Applying SetValue(Object, Object, BindingFlags, Binder, CultureInfo)."); 
反射可以通过FieldInfo.SetValue设置任何字段的值。            
// Change the field value using the SetValue method. 
反射可以通过FieldInfo.SetValue设置任何字段的值。
            myFieldInfo.SetValue(myObject, "New value", BindingFlags.Public, nullnull);     
反射可以通过FieldInfo.SetValue设置任何字段的值。            
// Display the string after applying SetValue to the field.
反射可以通过FieldInfo.SetValue设置任何字段的值。
            Console.WriteLine( "The field value of mystring is {0}.", myFieldInfo.GetValue(myObject));
反射可以通过FieldInfo.SetValue设置任何字段的值。        }

反射可以通过FieldInfo.SetValue设置任何字段的值。        
catch( Exception e )
{
反射可以通过FieldInfo.SetValue设置任何字段的值。            
// Any exception generated is displayed. 
反射可以通过FieldInfo.SetValue设置任何字段的值。
            Console.WriteLine( "Exception: {0}", e.Message );
反射可以通过FieldInfo.SetValue设置任何字段的值。        }

反射可以通过FieldInfo.SetValue设置任何字段的值。    }

反射可以通过FieldInfo.SetValue设置任何字段的值。}

反射可以通过FieldInfo.SetValue设置任何字段的值。

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-10-17
  • 2022-12-23
  • 2021-08-10
  • 2022-12-23
猜你喜欢
  • 2021-07-29
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-01-21
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案