access-modifiers

Do access modifiers affect reflection also?

I always believe they did, but seeing some answers here make me doubt... Can I access private fields/properties/methods from outside a class through reflection? ...

Practical usings of "internal" keyword in C#

Would you explain, please, what are practical usings of "internal" keyword in C#? I know what "internal" modifier limits access to the current assembly. But when could I need it? Thanks! ...

Retrieving values in reflected types from reflected properties

I need to access some members marked internal that are declared in a third party assembly. I would like to return a value from a particular internal property in a class. Then I'd like to retrieve a value from a property on that returned value. However, these properties return types that are also internal and declared in this third party...

When would you use the "protected internal" access modifier?

As you may already know, the .NET Framework's protected internal access modifier works in a strange way: It doesn't mean the class is protected AND internal, it says the class is protected OR internal; that is, the modified class or member can be accessed from whitin the same assembly as well as from the same hierarchy. So, knowing this...

How can one type access a private setter of another type's property?

All I need is a way to make a property of one class only 'settable' from one other class (a sort of manager class). Is this even possible in c#? My colleague 'reliably' informs me that I have a design flaw, but I feel I should at least ask the community before I concede defeat! ...

override but don't call

How do you declare a method in C# that should be overridden (or overridable) by a dereived class - possibly even outside your assembly - but that should be callable only from within the actual class? (i.e. like a private virtual function in C++) [edit] private virtual is exactly what I intend: "Here's a way to modify my behavior, but y...

Is there a c# equivalent to c++'s access-modifier regions

Im not sure what they're called but im referring to the private: public: protected: float bla1; float bla2; float bla3; keywords in c++. Is there an equivalent in c#? It seems rather tedious having to repeat yourself! ala protected float bla1; protected float bla2; protected float bla3; ...

Why can't I have protected interface members?

What is the argument against declaring protected-access members on interfaces? This, for example, is invalid: public interface IOrange { public OrangePeel Peel { get; } protected OrangePips Seeds { get; } } In this example, the interface IOrange would guarantee that implementors at least provide an OrangePips instance to their...

Why can't I access C# protected members except like this?

This code: abstract class C { protected abstract void F(D d); } class D : C { protected override void F(D d) { } void G(C c) { c.F(this); } } Generates this error: Cannot access protected member 'C.F(D)' via a qualifier of type 'C'; the qualifier must be of type 'D' (or derived from it) What in ...

protected/public Inner Classes

Can someone please explain to me what is the difference between protected / public Inner classes? I know that public inner classes are to avoid as much as possible (like explained in this article). But from what I can tell, there is no difference between using protected or public modifiers. Take a look at this example: public class F...

Object Oriented Analysis and Design

Why I can't able to specify static type of methods in interface. Is there any alternative to do this?? but I should use only inerface insted of abstract class. / Is there any problem in specifing acess specifier in interface? I want to specify the events in Interface and that should be acessed only by implemented class so i want pr...

What is the difference between Public, Private, Protected, and Nothing?

All my college years I have been using public, and would like to know the difference between public, private, and protected? Also what does static do as opposed to having nothing? ...

Internal interfaces - exposing my ignorance

I'm aware of these two questions which explain why I can't have a protected/private method in an interface, what I'm trying to work out is how to control from where my methods are called, briefly: public class EditField : IEditField { public EditField() {} public EditField(IStateMachine stateMachine) {} public void Action_Co...

Problem extending jog4j RollingFileAppender rollOver() access Level

Hello All I am trying to extend RollingFileAppender so that it will rotate even when no messages are coming into the logging system. Normally the rollOver method is called when a message arrives and a time check is done to trigger the rotate. My Version of RollingFileAppender will call rollOver every x seconds so that I am guaranteed a...

OO: Why should constructors on abstract classes be protected, not public?

C# code: Resharper suggests changing the accessibility of a public constructor in an abstract class to protected, but it does not state the rationale behind this. Can you shed some light? ...

What is the difference between the "protected" and "protected internal" modifiers in .NET?

What is the difference between the "protected" and "protected internal" modifiers in .NET? ...

JavaFX bind, and var access modifiers

var width = 400; var height = 400; Stage { style: StageStyle.TRANSPARENT onClose: function():Void { System.exit(0); } scene: Scene { content: Scribble {} width: width height: bind height } } Why does the width work, but the height not? And, what can I do to fix this? Netbeans is ...

How to make protected AND internal?

Here is my shortened abstract class: abstract class Report { protected internal abstract string[] Headers { get; protected set; } } Here is a derived class: class OnlineStatusReport : Report { static string[] headers = new string[] { "Time", "Message" } protected internal override string[] Headers {...

C# private, static, and readonly

Hello, I was reviewing some code for log4net and I came across this. private static readonly ILog logger = LogManager.GetLogger(typeof(AdminClient)); I am wondering why would you need to have private static readonly. From my understanding private would mean that the variable cannot not be used outside the class unless there is a acc...

Why can clone set a private field on another object?

I'm learning Java, and the book I'm reading has the following example on cloning. In clone(), my first instance is able to set buffer on the new object even though buffer is private. It seems like it should require the field to be protected for this to work. Why is this allowed? Does clone() have special privileges that allows it to acc...