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
Solved

How to Access Protected methods in C#

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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
send messages to whatsapp programatically 2 60
Media.Imaging 1 23
Hey!!!! 1 24
Following an example - Why do I need to click Save button twice? 3 28
Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

789 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