mirror of
https://github.com/Laupetin/OpenAssetTools.git
synced 2025-06-10 14:58:10 -05:00
Import code from previous AssetBuilder version
This commit is contained in:
27
test/ZoneCodeGeneratorTests/FieldInjector.cs
Normal file
27
test/ZoneCodeGeneratorTests/FieldInjector.cs
Normal file
@ -0,0 +1,27 @@
|
||||
using System;
|
||||
using System.Reflection;
|
||||
|
||||
namespace ZoneCodeGeneratorTests
|
||||
{
|
||||
internal static class FieldInjector
|
||||
{
|
||||
public static bool InjectToField(object target, object toInject)
|
||||
{
|
||||
if(target == null || toInject == null)
|
||||
throw new ArgumentException("Params must not be null");
|
||||
|
||||
var injectType = toInject.GetType();
|
||||
var fields = target.GetType().GetFields(BindingFlags.NonPublic | BindingFlags.Instance);
|
||||
|
||||
foreach(var field in fields)
|
||||
{
|
||||
if (!field.FieldType.IsAssignableFrom(injectType)) continue;
|
||||
|
||||
field.SetValue(target, toInject);
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user