Highlighted
Contributor.
Contributor.
812 views

Extension Methods

 Are extension methods still recognized in the latest visual cobol for .net?  I have a very simple ext method I am trying out and it does not seem to be recognized.  I keep getting the error Undefined Error Contact Tech Support.  I have a static extensions class like this.  

class-id Extensions static.

 

Method-id CountWords(str as string) returning result as binary-long extension static.
    declare #words as string occurs any = str::Split(' ')
    set result to size of #words
end method.
End class.

 

 

Then my calling method is in another class like this.

Method-id SomeMethod()

declare a as string = "Mary"
declare b as binary-long = a::CountWords

End method.

 

Intellisense does not recognize CountWords as an extension and I get the error noted above.

Tags (1)
0 Likes
8 Replies
Highlighted
Micro Focus Expert
Micro Focus Expert

RE: Extension Methods

I just copied your example into a new project and it works fine.
I am using Visual COBOL V4.0 Patch Update 3 for Visual Studio 2017.

What version are you using?
0 Likes
Highlighted
Contributor.
Contributor.

RE: Extension Methods

Micro Focus Visual COBOL 4.0 Version 4.0.00243.
0 Likes
Highlighted
Contributor.
Contributor.

RE: Extension Methods

Visual Studio 2017
0 Likes
Highlighted
Micro Focus Expert
Micro Focus Expert

RE: Extension Methods

That is the same version I am using.
I just created a new managed console application and copied the following into the default program.
Does this work for you or do you get the same error?

program-id. Program1 as "testextensions.Program1".

data division.
working-storage section.

procedure division.
declare a as string = "Mary"
declare b as binary-long = a::CountWords

goback.

end program Program1.

class-id Extensions static.
Method-id CountWords(str as string) returning result as binary-long extension static.
declare #words as string occurs any = str::Split(' ')
set result to size of #words
end method.
End class.
0 Likes
Highlighted
Contributor.
Contributor.

RE: Extension Methods

I will test that and see. Currently I am developing a managed windows form application and trying to use extension methods per my previous post.
0 Likes
Highlighted
Contributor.
Contributor.

RE: Extension Methods

That worked in a console application, but is still not working in my managed windows form application. I found some old code I developed using Visual Studio 2015 Visual Cobol and a windows form application where the extension methods worked and were recognized.
0 Likes
Highlighted
Micro Focus Expert
Micro Focus Expert

RE: Extension Methods

It would probably be best for you to open up a support incident with Customer Support and I could take a look at what you are doing. You could put my name in the description and that way it will be routed to me.
0 Likes
Highlighted
Contributor.
Contributor.

RE: Extension Methods

OK. Thanks Chris. I will do that shortly.
0 Likes
The opinions expressed above are the personal opinions of the authors, not of Micro Focus. By using this site, you accept the Terms of Use and Rules of Participation. Certain versions of content ("Material") accessible here may contain branding from Hewlett-Packard Company (now HP Inc.) and Hewlett Packard Enterprise Company. As of September 1, 2017, the Material is now offered by Micro Focus, a separately owned and operated company. Any reference to the HP and Hewlett Packard Enterprise/HPE marks is historical in nature, and the HP and Hewlett Packard Enterprise/HPE marks are the property of their respective owners.