attached_methods
Differences
This shows you the differences between two versions of the page.
| Next revision | Previous revision | ||
| attached_methods [2018/01/28 17:24] – created wolfgangriedmann | attached_methods [2018/01/28 17:41] (current) – wolfgangriedmann | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| - | ====== | + | ====== |
| + | |||
| + | In Visual Objects, you could define methods to classes where you had no sources and that are defined in other libraries. | ||
| + | In the .NET Framework this is not possible, but since this is a very powerful language feature, you can use the '' | ||
| + | |||
| + | Please look at this code: | ||
| + | < | ||
| + | local cResult as string | ||
| + | |||
| + | cString := "Hello world!" | ||
| + | cResult := cString: | ||
| + | |||
| + | But the '' | ||
| + | |||
| + | The solution is this one: | ||
| + | < | ||
| + | static method Left( self cString as string, nLen as int ) as string | ||
| + | local cReturn as string | ||
| + | |||
| + | if nLen >= cString: | ||
| + | cReturn := cString | ||
| + | else | ||
| + | cReturn := cString: | ||
| + | endif | ||
| + | |||
| + | return cReturn</ | ||
| + | The secret stays in the first parameter: '' | ||
| + | |||
| + | If you have defined this extension method in an assembly with a different namespace, this namespace of course must be included by a '' | ||
| + | |||
| + | And if you look at the sample code, you will see that the length of the string is checked before the '' | ||
| + | |||
attached_methods.1517160241.txt.gz · Last modified: 2018/01/28 17:24 by wolfgangriedmann