goated
I'm confused what IDisposable is used for
So I was expecting once the code run out of the using {} the class would be destroyed (and if we try to access it will throw a null ref exception)therefore helping the system, but it turns out if I keep a reference to it it wouldn't be destroyed, which means it's going to check is there any reference to the object anyways, it's not going to optimize the code right? Using a normal class and disposable feels the same
9 replies
how to use attribute to get functions and store in dict?
i want to store all functions with attribute from a specific instance of class(verifyHandler) to the dict
i tried to code with the help of gpt and im having some troubles
idk much about reflection so idk how to fix
public void VerifyMethods()
{
System.Type targetType = typeof(verifyHandler);
MethodInfo[] methods = targetType.GetMethods(BindingFlags.Instance | BindingFlags.Public);
foreach (MethodInfo method in methods)
{
verifyAttribute verifyAttribute = (verifyAttribute)System.Attribute.GetCustomAttribute(method, typeof(verifyAttribute));
if (verifyAttribute != null)
{
System.Func<JoinRequestMessage, bool> func =
(System.Func<JoinRequestMessage, bool>)System.Delegate.CreateDelegate(typeof(System.Func<JoinRequestMessage, bool>),method,verifyhandler);
JoinFailedCallback callback = verifyAttribute.callbackmsg;
checkers.Add(func, callback);
}
}
Debug.Log($"checkers(count):{checkers.Count}");
}
4 replies