Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

使用ExampleConfig.cs中的热更新Delegate配置,会使C#方法通过反射调用 #1132

Open
iamabigartist opened this issue Apr 14, 2024 · 0 comments

Comments

@iamabigartist
Copy link

// 配置某Assembly下所有涉及到的delegate到CSharpCallLua下,Hotfix下拿不准那些delegate需要适配到lua function可以这么配置
	[CSharpCallLua]
	static IEnumerable<Type> AllDelegate
	{
		get
		{
			BindingFlags flag = BindingFlags.DeclaredOnly | BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public;
			List<Type> allTypes = new List<Type>();
			var allAssemblys = new Assembly[]
			{
				Assembly.Load("Assembly-CSharp")
			};
			foreach (var t in from assembly in allAssemblys from type in assembly.GetTypes() select type)
			{
				var p = t;
				while (p != null)
				{
					allTypes.Add(p);
					p = p.BaseType;
				}
			}
			allTypes = allTypes.Distinct().ToList();
			var allMethods = from type in allTypes
				from method in type.GetMethods(flag)
				select method;
			var returnTypes = from method in allMethods
				select method.ReturnType;
			var paramTypes = allMethods.SelectMany(m => m.GetParameters()).Select(pinfo => pinfo.ParameterType.IsByRef ? pinfo.ParameterType.GetElementType() : pinfo.ParameterType);
			var fieldTypes = from type in allTypes
				from field in type.GetFields(flag)
				select field.FieldType;
			return returnTypes.Concat(paramTypes).Concat(fieldTypes).Where(t => t.BaseType == typeof(MulticastDelegate) && !hasGenericParameter(t) && !delegateHasEditorRef(t)).Distinct();
		}
	}

开启符号NOT_GEN_WARNING,然后运行Example/09_GenericMethod,会提示方法通过反射调用。
image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant