c# – 成员访问调用不编译但静态调用
所以今天在尝试构建我们公司的解决方案时遇到了一些有趣的问题,我想问你们,你们知道为什么会发生这种情况.我被告知可能来自我的机器/视觉工作室,因为其他人没有相同的问题.
所以我们在项目A中有一个方法: private static string RpcRoutingKeyNamingConvention(Type messageType,ITypeNameSerializer typeNameSerializer) { string queueName = typeNameSerializer.Serialize(messageType); return messageType.GetAttribute<GlobalRPCRequest>() != null || AvailabilityZone == null ? queueName : queueName + "_" + AvailabilityZone; } 其中GetAttribute< GlobalRPCRequest>()在公共静态类ReflectionHelpers中定义 public static TAttribute GetAttribute<TAttribute>(this Type type) where TAttribute : Attribute; 那么我们有项目B有方法: public static string GetAttribute(this XElement node,string name) { var xa = node.Attribute(name); return xa != null ? xa.Value : ""; } 我必须指出,我们参考了项目A中的项目B.
发生的是编译器认为我实际上是使用项目B中的GetAttribute方法(在我看来!).为什么会发生这种情况?因为当我尝试导航到GetAttribute VS导致我正确的方法(在ReflectionHelpers中的那个). 解决方法
这是一个猜测,但我认为你的功能:
私有静态字符串RpcRoutingKeyNamingConvention(类型messageType,ITypeNameSerializer typeNameSerializer)与您的帮助方法签名不匹配,因为您尝试返回一个字符串: public static TAttribute GetAttribute< TAttribute>(此类型类型)其中TAttribute:Attribute;这需要一个TAttribute返回类型. 也许您可以尝试修改函数RpcRoutingKeyNamingConvention返回GlobalRPCRequest并检查编译器是否继续疯狂. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |