private void CallFuncstructorConfigurations() { if (this._CallFuncstructorConfigurations) { return; } // this._CallFuncstructorConfigurations = true; try { while (this._FuncstructorConfigurations.Count > 0) { var funcstructorConfigurations = System.Threading.Interlocked.Exchange( ref this._FuncstructorConfigurations, new List <IFuncstructorConfiguration>()); System.Threading.Interlocked.MemoryBarrier(); if (funcstructorConfigurations.Count > 0) { var funcstructorConfigurables = this._FuncstructorConfigurables; var funcstructorConfigurablesLength = funcstructorConfigurables.Length; foreach (var funcstructorConfiguration in funcstructorConfigurations) { for (int idxFunc = 0; idxFunc < funcstructorConfigurablesLength; idxFunc++) { IFuncstructorConfigurable funcstructorConfigurable = funcstructorConfigurables[idxFunc]; funcstructorConfiguration.Register(funcstructorConfigurable); } } } } } finally { this._CallFuncstructorConfigurations = false; } }
/// <summary> /// The decorated method should be registed. /// </summary> /// <param name="funcstructor">The given funcstructor to configure.</param> public void Register(IFuncstructorConfigurable funcstructor) { var returnType = this._MethodInfo.ReturnType; var methodParameters = this._MethodInfo.GetParameters(); var parameterTypes = new Type[methodParameters.Length]; var genericParameterTypes = new Type[methodParameters.Length + 1]; for (int idx = 0; idx < methodParameters.Length; idx++) { var methodParameter = methodParameters[idx]; var parameterType = methodParameter.ParameterType; parameterTypes[idx] = parameterType; genericParameterTypes[idx] = parameterType; } genericParameterTypes[methodParameters.Length] = returnType; // Type typeFunc; switch (methodParameters.Length) { case 0: typeFunc = typeof(Func <>); break; case 1: typeFunc = typeof(Func <,>); break; case 2: typeFunc = typeof(Func <, ,>); break; case 3: typeFunc = typeof(Func <, , ,>); break; case 4: typeFunc = typeof(Func <, , , ,>); break; case 5: typeFunc = typeof(Func <, , , , ,>); break; case 6: typeFunc = typeof(Func <, , , , , ,>); break; default: throw new NotSupportedException(); } var typeFuncT = typeFunc.MakeGenericType(genericParameterTypes); var delegateT = Delegate.CreateDelegate(typeFuncT, this._MethodInfo); funcstructor.Register(returnType, this._Key, parameterTypes, delegateT, false); }
/// <summary> /// When a assembly with <see cref="IFuncstructorConfiguration"/> was loaded this <paramref name="funcstructor"/> will be used. /// </summary> /// <param name="funcstructor">The funcstructor to use for <see cref="IFuncstructorConfiguration.Register(IFuncstructorConfigurable)"/></param> public void WireTo(IFuncstructorConfigurable funcstructor) { if (funcstructor == null) { throw new ArgumentNullException(nameof(funcstructor)); } lock (this) { var l = this._FuncstructorConfigurables.ToList(); l.Add(funcstructor); this._FuncstructorConfigurables = l.ToArray(); } this.Wire(); }