public static void AddChaosInterfaces(this IServiceCollection services, Assembly assembly, Func <System.Type, bool> predicate) { var types = assembly.GetTypes(); foreach (var type in types) { if (!type.IsInterface) { continue; } if (!predicate(type)) { continue; } var addChaosTransient = DynamicMethod.GetGenericMethod(typeof(ChaosExtension), new[] { type }, nameof(AddChaosTransient), new[] { typeof(IServiceCollection) }); addChaosTransient(null, new object[] { services }); } }
public object Deserialize(Type type, byte[] data) { if (IsGenericDictType(type)) { var myDict = (SerializableDictionary)_binarySerializer.Deserialize(typeof(SerializableDictionary), data); return(DeserializeDictionary(myDict)); } var json = Encoding.UTF8.GetString(data); if (typeof(string) == type) { if (data.Length == 0) { return(String.Empty); } return(json); } var deserialize = DynamicMethod.GetGenericMethod(typeof(InsensitiveJsonSerializer), new Type[] { type }, nameof(InsensitiveJsonSerializer.Deserialize), new Type[] { typeof(string) } ); return(deserialize(_jsonSerializer, new object[] { json })); }