I Have a operator class that a func is on it, if argument of Function(it is a Func) was int or float or string i can convert object and call Func with "Function((T)a)", when T be a List how can i convert object a to T? (i know that T is List of Something)
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
namespace GameToolkit.Operator
{
public abstract class IOperator
{
public abstract Type OutputType { get; }
public abstract Type[] GetInputTypes();
public abstract object GetValue(object a);
public ValueToken GetValues(object a)
{
var v = GetValue(a);
return new ValueToken() { Type = v.GetType(), Value = v };
}
}
public class SingleOperand<T, O> : IOperator
{
public Func<T, O> Function { get; set; }
public SingleOperand()
{
}
public SingleOperand(Func<T, O> function)
{
Function = function;
}
public override object GetValue(object a)
{
if (Function == null)
return default(T);
if (a.GetType().IsGenericType)
{
///SOME CODE HERE!!!
}
else
return Function((T)a);
}
public override Type OutputType => typeof(O);
public override Type[] GetInputTypes()
{
return new[] { typeof(T) };
}
}
}
Aucun commentaire:
Enregistrer un commentaire