473,324 Members | 1,646 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,324 software developers and data experts.

Q re Extension Methods

Hi

I have 2 classes which are both instantiated by shared factory methods
and both implement a common interface.

Public Class Factory

Public Shared Function CreateMyClass1() As MyClass1
Return New MyClass1
End Function

Public Shared Function CreateMyClass2() As MyClass2
Return New MyClass2
End Function

End Class
Public Interface IItemContainer
Readonly Property ItemGroups as
System.Collections.Generic.Dictionary(Of String, ItemGroup)
End Interface

Public Class MyClass1
Implements IItemContainer
....
Private ReadOnly Property ItemGroups() As
System.Collections.Generic.Dictionary(Of String, ItemGroup) _
Implements IItemGroupContainer.ItemGroups
Get
Return m_itemGroups
End Get
End Property
....
End Class

Public Class MyClass2
Implements IItemContainer
....
Private ReadOnly Property ItemGroups() As
System.Collections.Generic.Dictionary(Of String, ItemGroup) _
Implements IItemGroupContainer.ItemGroups
Get
Return m_itemGroups
End Get
End Property
....
End Class

I also have an extension method so as not to duplicate code

<System.Runtime.CompilerServices.Extension()_
Public Function ItemCount(ByVal p_container As IItemContainer) As Integer
Return CType((From g In p_container.ItemGroups _
Select g.Value.Count).Sum(), Integer)
End Function
What I'm finding is that one of the classes is not recognising the
extension methods so I'm getting compilation errors for each extension
method call which is made. The other class is behaving correctly.

Any thoughts

Thx

Simon
Oct 30 '08 #1
1 1674
Oops

I had the tests in different classes and hadn't included the necessary
imports ...

Sorry

S
Simon Woods wrote:
Hi

I have 2 classes which are both instantiated by shared factory methods
and both implement a common interface.

Public Class Factory

Public Shared Function CreateMyClass1() As MyClass1
Return New MyClass1
End Function

Public Shared Function CreateMyClass2() As MyClass2
Return New MyClass2
End Function

End Class
Public Interface IItemContainer
Readonly Property ItemGroups as
System.Collections.Generic.Dictionary(Of String, ItemGroup)
End Interface

Public Class MyClass1
Implements IItemContainer
...
Private ReadOnly Property ItemGroups() As
System.Collections.Generic.Dictionary(Of String, ItemGroup) _
Implements IItemGroupContainer.ItemGroups
Get
Return m_itemGroups
End Get
End Property
...
End Class

Public Class MyClass2
Implements IItemContainer
...
Private ReadOnly Property ItemGroups() As
System.Collections.Generic.Dictionary(Of String, ItemGroup) _
Implements IItemGroupContainer.ItemGroups
Get
Return m_itemGroups
End Get
End Property
...
End Class

I also have an extension method so as not to duplicate code

<System.Runtime.CompilerServices.Extension()_
Public Function ItemCount(ByVal p_container As IItemContainer) As Integer
Return CType((From g In p_container.ItemGroups _
Select g.Value.Count).Sum(), Integer)
End Function
What I'm finding is that one of the classes is not recognising the
extension methods so I'm getting compilation errors for each extension
method call which is made. The other class is behaving correctly.

Any thoughts

Thx

Simon
Oct 30 '08 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Frederik Vanderhaegen | last post by:
Hi, I'm writing a simple soap extension for a webservice I developed (without the use of an extension the webservice works perfect). The extension is registered through the web.config files of...
3
by: Deckarep | last post by:
I recently got into somewhat of a debate with a fellow co-worker. First I asked him if he new of a way to add a method to an existing class like enhancing a class but without using Inheritance. He...
5
by: pythoncurious | last post by:
Hi, I'm having a bit of trouble when writing a python extension. I can't seem to figure out what I did wrong. I tried to make a minimal example, but it's still quite a bit of code. It would be...
1
by: gregory.lielens | last post by:
Hello, We are currently writing python bindings to an existing C++ library, and we encountered a problem that some of you may have solved (or that has found unsolvable :( ): A C++ class...
8
by: Steven Nagy | last post by:
Some simple yes/no questions. I tried googling first and couldn't find specific answers. These are related to .Net 3.5 extension methods 1) I found that I would like to add properties as well as...
4
by: Steffen Bobek | last post by:
Extension methods are made for use with instances. I'd like to "misuse" them as static methods, too. Let me tell you my ambition: I use an extension method to serialize objects somehow like this:...
3
by: raylopez99 | last post by:
The headline says it all. Great minds think alike: read the blog below from three years ago, as endorsed by Ritchie, who coinvented C. BTW the below lambda expression code will not work (.Where...
4
by: Rene | last post by:
Hi, I was wondering if anyone could tell me why extension methods must be declared on static classes. I mean, why not allowing them to be declared as static methods in regular instance classes?...
3
by: johanatan | last post by:
When I first heard about these new features, I was very excited as it would have (if implemented as I had expected) rendered mimicking multiple inheritance almost painless in C#. Unfortunately,...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.