扩展方法不是类的成员 [英] Extension Method is not a member of Class

查看:88
本文介绍了扩展方法不是类的成员的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

一段时间以来,我一直使用扩展方法来扩展已经存在的类的功能。示例:

For some time now I have been using extension methods to expand the functionality of already existing classes. An example:

<System.Runtime.CompilerServices.Extension()> _
Public Sub DrawRoundedRectangle(graphics As Graphics, pen As Pen, x As Single, y As Single, width As Single, height As Single, radius As Single)
    graphics.DrawRoundedRectangle(pen, x, y, width, height, radius, RectangleEdgeFilter.All)
End Sub

图形对象,以便我可以调用: e.graphics.DrawRoundedRectangle()

This happily extends the graphics object so that I can call: e.graphics.DrawRoundedRectangle()

report:


DrawRoundedRectangle不是System.Drawing.Graphics的成员

DrawRoundedRectangle is not a member of System.Drawing.Graphics

这意味着我无法构建由于错误,并且除了重新启动Visual Studio(耗时)之外,我还没有找到一种方法来克服这些错误。

This means that I am unable to build due to the errors, and as of yet other than restarting Visual Studio (time consuming) I am yet to find a way to overcome these errors.

我在各种不同的类中有许多扩展方法(目前大约为10个),所有这些方法都会同时发生,这会产生66个错误。

I have numerous extension methods (currently around 10) on various different classes, all of which fall over at the same time, this generates 66 errors.

我的问题是,在创建这些扩展方法时,我缺少什么,或者有什么可以做的来阻止这些错误发生?

My question is, Is there anything I am missing whilst creating these extension methods, or is there anything that can be done to stop these errors occuring?

推荐答案

您是否在公共模块中定义扩展?
试图重建解决方案,它是否解决了这个问题?

Do you define the extensions in a Public Module? Tried to 'rebuild solution', does it fix the issue?

这篇关于扩展方法不是类的成员的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆