-
Notifications
You must be signed in to change notification settings - Fork 92
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added ReflectionUtil that was missed in previous commit
- Loading branch information
Showing
2 changed files
with
30 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
using RimWorld; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Reflection; | ||
using System.Text; | ||
using Verse; | ||
|
||
namespace EdB.PrepareCarefully { | ||
public class ReflectionUtil { | ||
public static FieldInfo GetNonPublicField(Type type, string name) { | ||
FieldInfo info = type.GetField(name, BindingFlags.NonPublic | BindingFlags.Instance); | ||
if (info == null) { | ||
Log.Warning("Prepare Carefully could not find the field " + type.Name + "." + name + " via reflection"); | ||
} | ||
return info; | ||
} | ||
|
||
public static void SetNonPublicField(object target, string name, object value) { | ||
FieldInfo info = GetNonPublicField(target.GetType(), name); | ||
if (info == null) { | ||
Log.Warning("Prepare Carefully failed to set a value via reflection"); | ||
} | ||
else { | ||
info.SetValue(target, value); | ||
} | ||
} | ||
} | ||
} |