Solved

How to Access Protected methods in C#

Posted on 2012-03-19
5
405 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
[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
  • 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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

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

This article introduced a TextBox that supports transparent background.   Introduction TextBox is the most widely used control component in GUI design. Most GUI controls do not support transparent background and more or less do not have the…
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…
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

688 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