Solved

get members in partial class

Posted on 2010-08-31
5
526 Views
Last Modified: 2012-05-10
I am currently trying to use partial classes to extend my business logic for a project using the Entity Framework & vb.NET.  My question is this.  In my partial class is it possible to get the values for members (properties) from the main class.

So for instance if my main class was

Public Class MyClass

	Public Property String1 as string

End Class

Open in new window


I would want to be able to do something like this.  Is it possible?
Partial Class MyClass

	Public Function MyMethod() as string

		Return String1

	End Function

End Class

Open in new window

0
Comment
Question by:MRS
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
5 Comments
 
LVL 11

Accepted Solution

by:
ladarling earned 500 total points
ID: 33568809
Yes, you should have access to all of the members of your full class.
This example works fine for me:
 

Public Class Fish
    Dim name As String = "Nemo"
End Class
Partial Public Class Fish
    Public Function GetName() As String
        Return name
    End Function
End Class

Open in new window

0
 
LVL 8

Expert Comment

by:Gururaj Badam
ID: 33568858
The main class should also be marked as Partial otherwise I'm afraid whether it will work.
0
 
LVL 11

Expert Comment

by:ladarling
ID: 33568897
The Partial identifier is not required on the main class definition.... that is by design so that premade classes can be expanded with a Partial ....
0
 
LVL 8

Expert Comment

by:Gururaj Badam
ID: 33568948
In C# I see it as error - quite strange.
0
 

Author Closing Comment

by:MRS
ID: 33569094
Well that was a lot simpler the I expected.. :-)

Thank you for the quick turn around...
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question