Solved

get members in partial class

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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
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…
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…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

840 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