-
-
Notifications
You must be signed in to change notification settings - Fork 76
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #350 from LGouellec/issue/338
Issue/338
- Loading branch information
Showing
6 changed files
with
396 additions
and
28 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
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
49 changes: 49 additions & 0 deletions
49
test/Streamiz.Kafka.Net.Tests/Helpers/ReflectionHelperExtensionMethods.cs
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,49 @@ | ||
using System; | ||
using System.Linq; | ||
using System.Reflection; | ||
|
||
namespace Streamiz.Kafka.Net.Tests.Helpers; | ||
|
||
public static class ReflectionHelperExtensionMethods | ||
{ | ||
public static void SetPrivatePropertyValue<T, V>(this T member, string propName, V newValue) | ||
{ | ||
PropertyInfo[] propertiesInfo = | ||
typeof(T).GetProperties(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic); | ||
var propertyInfo = propertiesInfo.FirstOrDefault(p => p.Name.Equals(propName)); | ||
|
||
if (propertyInfo == null) return; | ||
propertyInfo.SetValue(member, newValue); | ||
} | ||
|
||
public static void SetPrivateFieldsValue<V>(this object member, Type type, string propName, V newValue) | ||
{ | ||
FieldInfo[] fieldsInfo = | ||
type.GetFields(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic); | ||
var fieldInfo = fieldsInfo.FirstOrDefault(p => p.Name.Equals(propName)); | ||
|
||
if (fieldInfo == null) return; | ||
fieldInfo.SetValue(member, newValue); | ||
} | ||
|
||
public static object GetInstance(string strFullyQualifiedName, ref Type outputType) | ||
{ | ||
Type type = Type.GetType(strFullyQualifiedName); | ||
if (type != null) | ||
{ | ||
outputType = type; | ||
return Activator.CreateInstance(type); | ||
} | ||
|
||
foreach (var asm in AppDomain.CurrentDomain.GetAssemblies()) | ||
{ | ||
type = asm.GetType(strFullyQualifiedName); | ||
if (type != null) | ||
{ | ||
outputType = type; | ||
return Activator.CreateInstance(type); | ||
} | ||
} | ||
return null; | ||
} | ||
} |
Oops, something went wrong.