diff --git a/GameFrameX.Hotfix.WrapperGenerator/Agent/HotfixWrapperGenerator.cs b/GameFrameX.Hotfix.WrapperGenerator/Agent/HotfixWrapperGenerator.cs index 580bbb94b..602fd472d 100644 --- a/GameFrameX.Hotfix.WrapperGenerator/Agent/HotfixWrapperGenerator.cs +++ b/GameFrameX.Hotfix.WrapperGenerator/Agent/HotfixWrapperGenerator.cs @@ -433,20 +433,7 @@ private static void ApplyAttribute(List diagnostics, string fullName } else if (string.Equals(name, StripAttributeSuffix(TimeOutAttributeName), StringComparison.OrdinalIgnoreCase)) { - mth.TimeOut = ParseTimeout(attribute, out var parsed); - if (parsed) - { - mth.HasTimeout = true; - } - else - { - // 解析失败降级为未配置超时(走 EnqueueAsync 框架默认值),并以诊断指明写法约束 - mth.HasTimeout = false; - var rawArgument = attribute.ArgumentList != null && attribute.ArgumentList.Arguments.Count > 0 - ? attribute.ArgumentList.Arguments[0].ToString() - : string.Empty; - diagnostics.Add(Logger.Error($"{fullName}.{method.Identifier.Text}【{TimeOutAttributeName}】参数必须是整数字面量(毫秒),当前无法解析:{rawArgument}", method.GetLocation())); - } + ApplyTimeoutAttribute(diagnostics, fullName, method, attribute, mth); } else if (string.Equals(name, StripAttributeSuffix(ThreadSafeAttributeName), StringComparison.OrdinalIgnoreCase)) { @@ -455,6 +442,35 @@ private static void ApplyAttribute(List diagnostics, string fullName } } + /// + /// 应用命中的 TimeOut 特性:解析成功置超时标记,失败降级为未配置并以 Error 诊断指明写法约束。 + /// + /// + /// Applies the matched TimeOut attribute: a successfully parsed literal sets the timeout flag; + /// otherwise it degrades to "not configured" and emits an Error diagnostic stating the expected literal form. + /// + /// 诊断缓冲 / Diagnostics buffer + /// 代理类完全限定名 / Fully qualified name of the agent class + /// 方法声明语法节点 / Method declaration syntax node + /// 命中的 TimeOut 特性语法节点 / The matched TimeOut attribute syntax node + /// 待填充的方法元数据 / Method metadata to populate + private static void ApplyTimeoutAttribute(List diagnostics, string fullName, MethodDeclarationSyntax method, AttributeSyntax attribute, MethodInfoData mth) + { + mth.TimeOut = ParseTimeout(attribute, out var parsed); + if (parsed) + { + mth.HasTimeout = true; + return; + } + + // 解析失败降级为未配置超时(走 EnqueueAsync 框架默认值),并以诊断指明写法约束 + mth.HasTimeout = false; + var rawArgument = attribute.ArgumentList != null && attribute.ArgumentList.Arguments.Count > 0 + ? attribute.ArgumentList.Arguments[0].ToString() + : string.Empty; + diagnostics.Add(Logger.Error($"{fullName}.{method.Identifier.Text}【{TimeOutAttributeName}】参数必须是整数字面量(毫秒),当前无法解析:{rawArgument}", method.GetLocation())); + } + /// /// 剥离特性名尾部的 Attribute 后缀([Service] 与 [ServiceAttribute] 书写等价)。 ///