?
Solved

get members in partial class

Posted on 2010-08-31
5
Medium Priority
?
530 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 2000 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

Get your Conversational Ransomware Defense e‑book

This e-book gives you an insight into the ransomware threat and reviews the fundamentals of top-notch ransomware preparedness and recovery. To help you protect yourself and your organization. The initial infection may be inevitable, so the best protection is to be fully prepared.

Question has a verified solution.

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

For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
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…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…

770 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