This thread looks to be a little on the old side and therefore may no longer be relevant. Please see if there is a newer thread on the subject and ensure you're using the most recent build of any software if your question regards a particular product.
This thread has been locked and is no longer accepting new posts, if you have a question regarding this topic please email us at support@mindscape.co.nz
|
is it possible or is there a feature built in to convert my returned say Customer object to and ICustomer object I have created?
|
|
|
If your ICustomer interface is consistent with the Customer methods and properties, you can just declare Customer as implementing ICustomer. (If you're using the designer, you can do this via the partial class.) If Customer and ICustomer have different interfaces, you'd need to implement ICustomer on Customer (again via the partial class). If you have another class that implements ICustomer, and you want to convert a LightSpeed Customer entity into an instance of this other class, you'll have to write your own method -- LightSpeed has no way of knowing about your class. Again, you can do this via the partial class if appropriate. If you just want to extract some Customer properties or methods into an interface, there are refactoring tools that will do this for you (e.g. Visual Studio 2008 has the Refactor > Extract Interface command). Not sure I've answered your question here -- if not, feel free to say a bit more about your scenario and I'll try to give you a more specific answer! |
|
|
thanks for the response!
I tried just what you stated above and when I Implement ICustomer (extracted using the method above) it duplicates the properties but with a 1 on the end of each property:
IE:
Public Property EmailAddress1() As String Implements ICustomer.EmailAddress
Get
End Get
Set(ByVal value As String)
End Set
End Property
Any ideas? I assumed I would be able to do what you described yesterday but was stumped when this kept happening to me.
|
|
|
Hi Max, This sounds like automated code generation going on through Visual Studio when you are implementing the interface on the partial. You should be able to just delete those stubs that it has created and it should compile fine as long as you have implemented everything that ICustomer declares already :)
Jeremy |
|
|
Tried the exact same thing but using C# instead of VB.net and it works perfectly - weird.
If you delete the extra 1 names properties in vb it gives you an error that you are not using the required properties.
|
|
|
Hmm. Looking through the Visual Basic language docs, it appears that it may be mandatory to provide the Implements keyword against every property or method that implements an interface member, even if the name and signature match. (Whereas C# automatically matches class members to interface members based on name and signature, but doesn't allow the class to use a different name.) That could make for a headache: we can't insert Implements clauses into the generated code, but it prevents the partial class from declaring the interface and having the generated code implement it. I'll look into this a bit more but right now I don't have a great solution other than to ask "is using C# an option for you?" (Bear in mind you could build the model in its own C# project and still write all your app code in VB via a separate project.) |
|
|
I've been needing a reason to goto C# anyways so I guess I found it!
Thanks for your help!
|
|
|
Hi Ivan - any developments on this? I have an old VB.Net project that I don't want to change to C# just so I can use interfaces on my partial classes. Yet I cannot seem to find a way to have the designer generated properties declare that they implement an interface property... I would have thoughts VS2012 would allow implicit implemented of interfaces in VB.Net by now... Frustrating! |
|