mirror of
https://github.com/wiremock/WireMock.Net.git
synced 2026-04-21 00:11:44 +02:00
test utils
This commit is contained in:
@@ -52,12 +52,19 @@ namespace WireMock.Net.Tests
|
|||||||
public static void SetPrivatePropertyValue<T>(this object obj, string propertyName, T value)
|
public static void SetPrivatePropertyValue<T>(this object obj, string propertyName, T value)
|
||||||
{
|
{
|
||||||
Type t = obj.GetType();
|
Type t = obj.GetType();
|
||||||
if (t.GetProperty(propertyName, BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance) == null)
|
PropertyInfo propertyInfo = null;
|
||||||
|
while (propertyInfo == null && t != null)
|
||||||
{
|
{
|
||||||
throw new ArgumentOutOfRangeException(nameof(propertyName), $"Property {propertyName} was not found in Type {obj.GetType().FullName}");
|
propertyInfo = t.GetProperty(propertyName, BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance);
|
||||||
|
t = t.BaseType;
|
||||||
}
|
}
|
||||||
|
|
||||||
t.InvokeMember(propertyName, BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.SetProperty | BindingFlags.Instance, null, obj, new object[] { value });
|
if (propertyInfo == null)
|
||||||
|
{
|
||||||
|
throw new ArgumentOutOfRangeException(nameof(propertyName), $"Private property {propertyName} was not found in Type {obj.GetType().FullName}");
|
||||||
|
}
|
||||||
|
|
||||||
|
propertyInfo.SetValue(obj, value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user