Solved

How to Access Protected methods in C#

Posted on 2012-03-19
5
401 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

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

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

Suggested Solutions

This article describes a simple method to resize a control at runtime.  It includes ready-to-use source code and a complete sample demonstration application.  We'll also talk about C# Extension Methods. Introduction In one of my applications…
Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

734 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