I have this code:
public static Tween.TweenExecuter To<T>(ref this T thisArg, T to, float time, EasingType easing = EasingType.Linear,
TweenType type = TweenType.Simple, Func<bool> trigger = null, Action callback = null) where T : struct
{
Tween.TweenElement<T> tween = new Tween.TweenElement<T>()
{
from = thisArg,
Setter = x => thisArg = x,
to = to,
time = time,
easing = easing,
type = type,
Trigger = trigger,
Callback = callback
};
tween = t;
return new Tween.TweenExecuter(tween);
}
Setter should be assigned to an Action<T> but compiler complains: error CS1628: Cannot use ref or out parameter 'thisArg' inside an anonymous method, lambda expression, or query expression
How can I use an Action<T> otherwise?
Edit:
Here is the type declaration:
public abstract class BaseTween
{
public float time;
public float currentTime;
public EasingType easing;
public TweenType type;
public bool deleteAtEnd = false;
public Func<bool> Trigger;
public Action Callback;
}
public class TweenElement<T> :BaseTween
{
public Action<T> Setter;
public T from;
public T to;
}
ref this T thisArginstead ofthis T thisArg? If that even works, it's very unusual for an extension method.thisArg? Instead of passing the variable byref, perhaps you could pass the object that contains it by value.thisrefers to, so why should an extension be able to?