Althos
Althos
CC#
Created by Althos on 5/25/2024 in #help
Delegate.CreateDelegate returns "ArgumentException: method arguments are incompatible"
Any idea what I did wrong here ? My method seems to be of the correct type
public void RegenerateEventEnums()
{
FieldInfo[] fields = typeof(Card).GetFields();
foreach (FieldInfo field in fields)
{
var del = Delegate.CreateDelegate(typeof(Action<Card>), GetType().GetMethod("Test"));
}
}

public void Test(Card card)
{
Debug.Log("My card!");
}
public void RegenerateEventEnums()
{
FieldInfo[] fields = typeof(Card).GetFields();
foreach (FieldInfo field in fields)
{
var del = Delegate.CreateDelegate(typeof(Action<Card>), GetType().GetMethod("Test"));
}
}

public void Test(Card card)
{
Debug.Log("My card!");
}
5 replies
CC#
Created by Althos on 5/6/2024 in #help
Why isn't my generic working properly ?
No description
6 replies
CC#
Created by Althos on 3/4/2023 in #help
❔ Is there a better way to implement this "pattern"?
Hi, I'm trying to implement a pattern where I have a non-generic interface that exposes certain functions and can be used by any other class without the need for a generic, and then a generic version of the interface that helps restrict types properly when creating concrete implementations, here is an example
internal interface IVisualElement
{
IEnumerable<IVisualElement> Children { get; }
void Draw(IVisualElement parent);
}

internal interface IVisualElement<in T> : IVisualElement where T : IVisualElement
{
void DrawGeneric(T parent);
}

internal class ConcreteVisualElement : IVisualElement<Node>
{
public IEnumerable<IVisualElement> Children { get; } = new List<IVisualElement>();

public void DrawGeneric(Node parent)
{
throw new System.NotImplementedException();
}

public void Draw(IVisualElement parent)
{
DrawGeneric(parent as Node);
}
}
internal interface IVisualElement
{
IEnumerable<IVisualElement> Children { get; }
void Draw(IVisualElement parent);
}

internal interface IVisualElement<in T> : IVisualElement where T : IVisualElement
{
void DrawGeneric(T parent);
}

internal class ConcreteVisualElement : IVisualElement<Node>
{
public IEnumerable<IVisualElement> Children { get; } = new List<IVisualElement>();

public void DrawGeneric(Node parent)
{
throw new System.NotImplementedException();
}

public void Draw(IVisualElement parent)
{
DrawGeneric(parent as Node);
}
}
Is there a name for what I'm trying to do, and is there a better way to implement it? Thanks a lot for your help!
16 replies