I don't know how exactly to put this in words, Using a color as an example:
I know how to write basic
<Extension()>
methods:
<Extension()>
Public Function GetRedValue(byval c as Color) as byte
Return c.R
End Function
I could use:
Dim Col as Color = Color.LimeGreen
Label1.Text = Col.GetRedValue().ToString
And it would return the value of
Color.R
as expected.
What I am trying to figure out is how to run a method without having an instance of color already created in order to return a new instance of that object.
It seems like the Color structure can inherently do it. When you create a new color you can use a predefined color or define the object like:
Dim col as Color = Color.FromARGB(Alpha, Red, Green, Blue)
without having an instance already created.
How to I create my own method that work in the same fashion
Example:
<Extension()>
Public Function FromHSV(byval c as Color, Hue as Single, Saturation as Single, Value as Single) as Color
Dim ReturnColor as Color = ConvertToRGB(Hue, Saturation, Value)
Return ReturnColor
End Function
So that I may use it like:
Dim Col as Color = Color.FromHSV(0.5, 0.2, 1.0)
or even
Dim Col as Color = Color.MyCustomColor
I'm hoping I am making myself clear as I was not sure of the correct terminology for what I am trying to accomplish.
Any help is appreciated, Thank You!
What I have tried:
I thought the
Shared
parameter would work, but you can't use
Shared
within a module and you can't use
<Extension()>
within a class.
I have searched and found nothing that helps.