Solved

How to Access Protected methods in C#

Posted on 2012-03-19
5
391 Views
Last Modified: 2012-03-19
I was under the impression that it was plausible to accessing protected methods by deriving a new class by the class with the protected method..however, I am trying to use a method to add users with a certain GUID in C# and I am unable to access the GrantAccess methods that I am showing a link for below.  

http://technet.microsoft.com/en-us/library/microsoft.sharepoint.administration.spdatabase.grantaccess.aspx

So, how do I get access to the grantaccess methods in C#?  Thanks!
0
Comment
Question by:VBBRett
  • 3
  • 2
5 Comments
 
LVL 20

Accepted Solution

by:
BuggyCoder earned 500 total points
ID: 37738801
these are protected internal methods.
To Access these methods, you need to derive from SPDatabase class and then from your derived class you will be able to access these methods.

you can always write a public method in your derived class which allows user to add GUID as user, this method will internally use the protected grantacess method as given below:-
public sealed class MyDerivedDatabase : SPDatabase
{
public void AddUser(GUID userId)
{
this.GrantAccess(new SecurityIdentifier(userId.ToString());
}
}

MyDerivedDatabase db=new MyDerivedDatabase();
db.AddUser(GUID.NewGuid());

Open in new window

0
 
LVL 75

Expert Comment

by:käµfm³d 👽
ID: 37738893
To Access these methods, you need to derive from SPDatabase class and then from your derived class you will be able to access these methods.
Incorrect. The methods are marked internal, which means only other types from the same assembly can gain access to that method. You might be able to use Reflection, but the methods were marked internal for a reason (meaning someone didn't want outside code using them), so it may not be worthwhile fiddling with these methods.

What is your goal?
0
 
LVL 75

Expert Comment

by:käµfm³d 👽
ID: 37738898
P.S.

I agree with the explanation of protected. It's the internal that's giving you the grief  = )
0
 
LVL 20

Expert Comment

by:BuggyCoder
ID: 37738985
Hi @kaufmed,

i though i made a mess here!!!
Just Rechecking and found that Methods are marked as protected internal....

so they can be used by derived type as well as the types in the same assembly.

Keep Well...
Happy Coding -:)
0
 
LVL 75

Expert Comment

by:käµfm³d 👽
ID: 37739017
The mistake is mine--due to my misunderstanding of what protected internal entails. I took them as a combined meaning--can only be used within the same assembly, and only if derived--whereas it seems their meaning is separate--can be used within the same assembly or derived in an external assembly. I learned something new. Yay  = )
0

Featured Post

U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
WKHTMLTOPDF - --disable-smart-shrinking not working 10 90
Error on link 14 48
C# parent child form 5 29
FTP file download using c# 3 23
In order to hide the "ugly" records selectors (triangles) in the rowheaders, here are some suggestions. Microsoft doesn't have a direct method/property to do it. You can only hide the rowheader column. First solution, the easy way The first sol…
Introduction This article series is supposed to shed some light on the use of IDisposable and objects that inherit from it. In essence, a more apt title for this article would be: using (IDisposable) {}. I’m just not sure how many people would ge…
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.
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 …

803 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