Solved

get members in partial class

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

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Tabcontrol Caption? 1 24
Why is "packages element is not declared"? 2 39
C# Error - Add Failed 12 38
Open a word document 23 13
For most people, the WrapPanel seems like a magic when they switch from WinForms to WPF. Most of us will think that the code that is used to write a control like that would be difficult. However, most of the work is done by the WPF engine, and the W…
Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
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…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

706 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

17 Experts available now in Live!

Get 1:1 Help Now