Skip to content

Commit

Permalink
Added ReflectionUtil that was missed in previous commit
Browse files Browse the repository at this point in the history
  • Loading branch information
edbmods committed Jul 11, 2018
1 parent da9c9e7 commit 937041d
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
1 change: 1 addition & 0 deletions EdBPrepareCarefully.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@
<Compile Include="Source\OptionsHair.cs" />
<Compile Include="Source\OptionsHeadType.cs" />
<Compile Include="Source\Randomizer.cs" />
<Compile Include="Source\ReflectionUtil.cs" />
<Compile Include="Source\RelatedPawn.cs" />
<Compile Include="Source\RelationshipBuilder.cs" />
<Compile Include="Source\RelationshipGroup.cs" />
Expand Down
29 changes: 29 additions & 0 deletions Source/ReflectionUtil.cs
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);
}
}
}
}

0 comments on commit 937041d

Please sign in to comment.