Answered by:
How to specify "Implements" to a VB.NET function using AddFunction

Question
-
Hi
I am writing an plugin that will add a function to a class using ClassObj.AddFunction method. Problem is if the class containing that methos implements an interface then how should I add implements keyword to the newly created function.
For Example -Public
Interface IAbc
Function GetAbc(ByVal tMsg As string)
End Interface
also
Public
Class Abc
Implements IAbc
Private
Function NewAbc(ByVal tMsg As string) Implements IAbc
' Do Somethiong
End Function
End Class
My question is how to add Implements IAbc this to the function. I searched a lot but all in vain.
Please, can anybody help me.
Thanks
Gaurav
Tuesday, August 5, 2008 12:18 PM
Answers
-
As far as I know, we have to parse the code searching for the text position and manually insert the text: "Implements IAbc.GetAbc". For more information, please refer to the following reference:
Code Model & its Interop with Text Editor Object Model
Thanks!
Please remember to mark the replies as answers if they help and unmark them if they provide no help.- Proposed as answer by Feng Chen Monday, August 11, 2008 6:37 AM
- Marked as answer by Feng Chen Tuesday, August 12, 2008 4:13 AM
- Unmarked as answer by gsm.gaurav Thursday, August 14, 2008 8:35 AM
- Marked as answer by Feng Chen Thursday, August 14, 2008 8:52 AM
Monday, August 11, 2008 6:36 AM
All replies
-
As far as I know, we have to parse the code searching for the text position and manually insert the text: "Implements IAbc.GetAbc". For more information, please refer to the following reference:
Code Model & its Interop with Text Editor Object Model
Thanks!
Please remember to mark the replies as answers if they help and unmark them if they provide no help.- Proposed as answer by Feng Chen Monday, August 11, 2008 6:37 AM
- Marked as answer by Feng Chen Tuesday, August 12, 2008 4:13 AM
- Unmarked as answer by gsm.gaurav Thursday, August 14, 2008 8:35 AM
- Marked as answer by Feng Chen Thursday, August 14, 2008 8:52 AM
Monday, August 11, 2008 6:36 AM -
Thanks for your response :)
Actually, I was generating methods that implements some interfaces. To do this, I used addFunction of class object to create the methods and then created edit points at the end of method line and inserted required interface code. (Similar to what you have mentioned)
However, I am wondering is there no way one could find out whether a method implements some interface method using Code Model?- Marked as answer by gsm.gaurav Thursday, August 14, 2008 8:35 AM
- Marked as answer by gsm.gaurav Thursday, August 14, 2008 8:35 AM
- Unmarked as answer by gsm.gaurav Thursday, August 14, 2008 8:35 AM
- Unmarked as answer by gsm.gaurav Thursday, August 14, 2008 8:35 AM
- Marked as answer by gsm.gaurav Thursday, August 14, 2008 8:35 AM
- Unmarked as answer by gsm.gaurav Thursday, August 14, 2008 8:35 AM
- Unmarked as answer by gsm.gaurav Thursday, August 14, 2008 8:35 AM
- Unmarked as answer by gsm.gaurav Thursday, August 14, 2008 8:36 AM
Thursday, August 14, 2008 8:35 AM -
However, I am wondering is there no way one could find out whether a method implements some interface method using Code Model?
If you just want to retrieve to determine whether a class is derived from another specific class, please use the ImplementedInterfaces property of CodeClass2 interface.
Thanks!
Please remember to mark the replies as answers if they help and unmark them if they provide no help.Thursday, August 14, 2008 9:04 AM -
No its not about the class its about the method which implements the interface method.
As far as I know(I am not a VB.NET guy) in VB.NET we need to specifically write the Implements Interface.Method against all those methods which are interface methods.
My task is to write an interface method in the class in VB.NET which is implementing an interface.
As per above example I have to insert -
Private Function NewAbc(ByVal tMsg As string) Implements IAbc.GetAbc
' Do Somethiong
End Function
in Abc Class. I am able to add this -
Private Function NewAbc(ByVal tMsg As string)
' Do Somethiong
End Function
However, I am unable to append this Implements IAbc.GetAbc directly from Code Model.Monday, August 18, 2008 9:45 AM -
Gaurav,
Did you ever find an answer to your question? I have the same question, but only under C#. I want to add an explicity implemented interface method (i.e. IDisposable.Dispose), but cannot find a way to do that. If I pass "IDisposable.Dispose" to AddFunction, I get an exception.
Thanks,
mikeTuesday, December 9, 2008 4:55 AM -
Mike,
In C# it is not required to write the implemented interface function name against the function implementing it. You can simply specify name of the Interface with the class name.
Regards
Gaurav
Sunday, December 14, 2008 3:57 PM