Q re Extension Methods


S

Simon Woods

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
 
Ad

Advertisements

S

Simon Woods

Oops

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

Sorry

S
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top