?
Solved

Instanciating a shared class.

Posted on 2007-10-10
3
Medium Priority
?
214 Views
Last Modified: 2013-11-26
I have the following class:
Imports System.Web.Security

Public Class MYMembership

Shared Sub New()
End Sub

Public Shared ReadOnly MYMembership() as SqlMembershipProvider
   Get
      Return Membership.Providers("MyMembershipProvider")
   End Get
End Property
End Class

If I want to use this class I have to code MyMembership.MyMembership...(methods and properties)

How can I setup this class so that MyMembership.(methods and properties)

Thanks
0
Comment
Question by:DigitalDan3
3 Comments
 
LVL 86

Accepted Solution

by:
Mike Tomlinson earned 1000 total points
ID: 20049797
You need to create other Shared Properties that access "MYMembership.MYMembership" for you...

I have no idea how to use SqlMembershipProvider, but hopefully this should give you the idea:

    Public Class MYMembership

        Public Shared ReadOnly MYMembership() as SqlMembershipProvider
            Get
                Return Membership.Providers("MyMembershipProvider")
            End Get
        End Property

        Public Shared ReadOnly Property SomeProperty() As String
            Return MYMembership.MYMembership.SomeProperty()
        End Property

    End Class    

Then you can use:

    MYMembership.SomeProperty
0
 
LVL 18

Assisted Solution

by:vbturbo
vbturbo earned 1000 total points
ID: 20049876
You will need to make an instance to the class from the calling Form or class in order to access the
functionallity which your MYMembership class provide.

See: Shared members are properties, procedures, and fields that are shared by all instances of a class
http://msdn2.microsoft.com/en-us/library/4hbsxy95(VS.71).aspx
And
http://msdn2.microsoft.com/en-us/library/zc2b427x(vs.71).aspx

vbturbo
0
 

Author Comment

by:DigitalDan3
ID: 20051188
Heres what I came up with.

Imports System.Web.Security

Public Class MYMembership

Shared Sub New()
End Sub

Public Shared ReadOnly Membership() as SqlMembershipProvider
   Get
      Return System.Web.Security.Membership.Providers("MyMembershipProvider")
   End Get
End Property
End Class
0

Featured Post

NEW Veeam Agent for Microsoft Windows

Backup and recover physical and cloud-based servers and workstations, as well as endpoint devices that belong to remote users. Avoid downtime and data loss quickly and easily for Windows-based physical or public cloud-based workloads!

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…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
This Micro Tutorial will teach you how to add a cinematic look to any film or video out there. There are very few simple steps that you will follow to do so. This will be demonstrated using Adobe Premiere Pro CS6.
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
Suggested Courses

850 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