Merhaba Unity3d'nin kullandığı alt küme Mono 2.8.2'de bir elçi oluşturmaya çalışıyorum. Bir "abone" özelliği ile dekore edildiğinde haberciye otomatik olarak abone olma yöntemleri için bir yardımcı oluşturmak için elli olacağını düşündüm.Mono 2.8.2'de methodInfo'dan bir Delege oluşturma
Başım ağrıyordu ve problemle ilgili bir çözüm olmadan diğer ilgili yığın sorularının çoğunu okudum. Frankly, I don't know if I am doing something wrong or if this is a bug in Mono.
foreach (var methodInfo in methods)
{
var attr = methodInfo.GetAttribute<SubscribeAttribute>();
if (attr == null)
continue;
var parmas = methodInfo.GetParameters();
if (parmas.Length != 1)
{
Debug.LogError("Subscription aborted. Invalid paramters.");
continue;
}
var type = parmas[0].ParameterType;
// Crashes here
// ArgumentException: method argument length mismatch
// I have tried many combinations..
// Direct typing of the message type and dynamic typing
var action = (Action<object>)Delegate.CreateDelegate(typeof(Action<object>), methodInfo);
// also does not work
// var dt = Expression.GetActionType(parmas.Select(o => o.ParameterType).ToArray());
// var action = Delegate.CreateDelegate(dt, methodInfo);
Subscribe(type, action, instance);
}
Herhangi bir öneri veya geçici mutluluk duyacağız.
Düzenleme gibi yöntem imzası şöyledir:
[Subscribe]
void OnMessage(object message){
// Hello World
}
olsa, aslen bir statik olmayan yöntem ve sen bir hedef vermedi
[Subscribe]
void OnTestMessage(TestMessage message){
// Hello World
}
Abone olmaya çalıştığınız yöntemin imzası nedir? Void MyMethod (object arg) 'gibi bir imzası var mı? –
Doğru. Yayını güncelledim. – user2085865
mono 2.8 çok eski, lütfen 3.2.3'e geçin. – knocte