Imports System.Reflection Namespace SimpleHistory Public Class ObjectState Inherits ObjectBase ''' ''' The Object including the members to patch. ''' ''' Public Property [Object] As Object = Nothing ''' ''' The name of the Member to patch. ''' ''' Public Property MemberName As String = "" ''' ''' The Value that should be patched. ''' ''' Public Property ValueToPatch As Object = Nothing ''' ''' The member types to include at searching for the member. ''' ''' Public Property MemberType As ObjectValueType = ObjectValueType.Field ''' ''' The Binding Flags that are used at searching for the member. ''' ''' Public Property MemberFlags As BindingFlags = BindingFlags.Default ''' ''' Creates a new Instance of ObjectState from input. ''' ''' The Object including the members to patch. ''' The name of the Member to patch. ''' The member types to include at searching for the member. ''' The Binding Flags that are used at searching for the member. Public Sub New(obj As Object, valname As String, valToPatch As Object, valtype As ObjectValueType) [Object] = obj MemberName = valname ValueToPatch = valToPatch MemberType = valtype End Sub ''' ''' Creates a new Instance of ObjectState. ''' Public Sub New() End Sub Friend Sub Patch() Dim t As Type = [Object].GetType Select Case MemberType Case ObjectValueType.Field Dim f As FieldInfo = t.GetField(MemberName, MemberFlags) Dim temp As Object = Nothing If f IsNot Nothing Then temp = f.GetValue([Object]) f.SetValue([Object], ValueToPatch) ValueToPatch = temp End If Case ObjectValueType.Property Dim p As PropertyInfo = t.GetProperty(MemberName, BindingFlags.Instance Or BindingFlags.Public Or BindingFlags.NonPublic Or BindingFlags.Static) Dim temp As Object = Nothing If p IsNot Nothing Then temp = p.GetValue([Object]) p.SetValue([Object], ValueToPatch) ValueToPatch = temp End If Case Else Throw New Exception("ValueType is invalid!") End Select End Sub End Class End Namespace