public void SetDataInterceptor <T>(DataInterceptor dataInterceptor) where T : class, IData { if (this.DataInterceptors.ContainsKey(typeof(T))) { throw new InvalidOperationException("A data interceptor has already been set"); } this.DataInterceptors.Add(typeof(T), dataInterceptor); Log.LogVerbose(LogTitle, $"Data interception added to the data type '{typeof (T)}' with interceptor type '{dataInterceptor.GetType()}'"); }
public IEnumerable <DataInterceptor> GetDataInterceptors(Type dataType) { DataInterceptor globalDataInterceptor = GlobalDataInterceptors .FirstOrDefault(kvp => kvp.Key.IsAssignableFrom(dataType)).Value; DataInterceptor threadedDataInterceptor; this.DataInterceptors.TryGetValue(dataType, out threadedDataInterceptor); if (threadedDataInterceptor == null && globalDataInterceptor == null) { return(Enumerable.Empty <DataInterceptor>()); } var dataInterceptors = new List <DataInterceptor> { threadedDataInterceptor, globalDataInterceptor }; return(dataInterceptors.Where(d => d != null)); }