You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Some sinks contain configuration properties/arguments that are delegate types (Action, Func).
The StringArgumentValue class already supports static field and property accessors for non-delegate types, and can be extended to support delegate values that are accessed from static properties, static fields or static non-generic methods. If the argument value points to a method, overload resolution should be done to match the target delegate with the reflected method.
A disadvantage could be that this would encourage the creation of static methods which some view as bad for testability.
Below is my proposed change:
if(TryParseStaticMemberAccessor(argumentValue,outvar accessorTypeName,outvar memberName)){varaccessorType= Type.GetType(accessorTypeName, throwOnError:true);// if target type is a delegate, look for a public static non-generic method in the accessor typeif(typeof(Delegate).IsAssignableFrom(toType)){varmethodCandidates= accessorType.GetTypeInfo().DeclaredMethods
.Where(x => x.Name ==memberName).Where(x => x.IsPublic).Where(x =>!x.IsGenericMethod).Where(x => x.IsStatic).ToList();// if more than 1 candidates, get target type signature and perform overload resolution on candidate methodsif(methodCandidates.Count >1){vardelegateSig= toType.GetMethod("Invoke");vardelegateParameters= delegateSig.GetParameters().Select(x => x.ParameterType);methodCandidates= methodCandidates
.Where(x => x.ReturnType == delegateSig.ReturnType).Where(x => x.GetParameters().Select(p => p.ParameterType).SequenceEqual(delegateParameters)).ToList();}varmethod= methodCandidates.SingleOrDefault();if(method!=null){return method.CreateDelegate(toType);}
The text was updated successfully, but these errors were encountered:
I guess this would solve my issue with Elasticsearch sink, in which I need to set a Func<,> delegate to option ModifyConnectionSettings but I couldn't find a way to do this.
Some sinks contain configuration properties/arguments that are delegate types (
Action
,Func
).The
StringArgumentValue
class already supports static field and property accessors for non-delegate types, and can be extended to support delegate values that are accessed from static properties, static fields or static non-generic methods. If the argument value points to a method, overload resolution should be done to match the target delegate with the reflected method.A disadvantage could be that this would encourage the creation of static methods which some view as bad for testability.
Below is my proposed change:
The text was updated successfully, but these errors were encountered: