I'm trying to make a delegate assignment to methods that are contained inside a library of extension indicator methods. The signature of the library methods is represented by the "Indic" extension below. The code below is a rough idea of what I'm trying to achieve went evaluating a library method with the named indicator, passed in via the indicator parameter. The example code is not passing the input list to library extension property... and that's the problem I'm having.
I looked at stackoverflow question: Extension method calling other extension wethod (not really applicable)
I'm also confused at when I should use generic delegate extensions.
using Infrastructure;
using Skender.Stock.Indicators;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Windows;
public static class IndicatorExt
{
public static object? Indic<T>(this T quote,
string indicator, int? LookBack = null)
where T : List<RawTick>
{
// Get a MethodInfo that represents indicator.
BindingFlags flags = BindingFlags.NonPublic | BindingFlags.Static;
MethodInfo? minfo = typeof(Indicator).GetMethod(indicator, flags);
// Get the Type and MethodInfo. These string are for testing
Type? MyType = Type.GetType("System.Reflection.FieldInfo");
MethodInfo? Mymethodinfo = MyType?.GetMethod("GetValue");
// I'm not sure on how to pass the input data quote (per above)
return Mymethodinfo?.Invoke(null, new Object?[]
{ guote, indicator, LookBack }); //******* quote is unaccessible
}
}
I also need to know how to pass the list into the delegate as input.
public void main()
{
var quotes = new List<RawTick>(Enumerable.Range(1, 25)
.Select((x, i) => new RawTick() { Close = x, Open = i }));
Func<List<RawTick>, string, int?, object?> results = IndicatorExt.Indic;
var ind = (List<AdxResult>)quotes.results(CalcAdx", 8);
MessageBox.Show($"{ind.Count}");
}
Aucun commentaire:
Enregistrer un commentaire