Solved

get members in partial class

Posted on 2010-08-31
5
521 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
  • 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
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…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

932 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now