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
This happily extends the graphics object so that I can call: e.graphics.DrawRoundedRectangle()
However every so often Visual Studio will report:
DrawRoundedRectangle is not a member of System.Drawing.Graphics
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.
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?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With