access-modifiers

Automatically Refactor Access Modifiers

Is there a tool that can run through a visual studio solution and adjust access modifiers to anything not being called in the solution is converted to private or internal where applicable? I suppose I could just change everything to private, and then use the compiler messages and do it by hand...but that could take a while, if there was...

Children Controls Are Inaccessible Due to Access Modifier

When I create a user control in WPF it would appear that all the children of this control are declared as internal? I've not been able to verify this, nor finding any resources discussing this matter at all. I can access the controls in the same assembly, but not in a project referencing the assembly where the user control is located. I...

.NET - how to make a class such that only one other specific class can instantiate it?

I'd like to have the following setup: class Descriptor { public string Name { get; private set; } public IList<Parameter> Parameters { get; private set; } // Set to ReadOnlyCollection private Descrtiptor() { } public Descriptor GetByName(string Name) { // Magic here, caching, loading, parsing, etc. } } class Parameter ...

How do I mimic access modifiers in JavaScript with the Prototype library?

I've been working with the prototype library for some time now and occasionally find myself wishing I had multiple access levels (public, private, and protected). The closest I've come so far is the following: SampleBase = Class.create({ /* virtual public constructor */ initialize: function(arg1, arg2) { // private ...

Private variables/methods in anonymous class?

Hello. I have created an anonymous class in which I declare a few variables and methods. My java teacher tells me to make these private. I don't see how changing the modifier makes any difference since these variables and methods are private to the anonymous class anyway, so I prefer to have no modifier at all. Who is right and what make...

C# internal getter, protected setter with an internal class parameter

I was having the problem of wanting a property to have an internal getter and a protected setter, as described in this question, and I thought I solved that by doing the following: public class Accessor : AccessorBase { private Connection _connection; protected void setConnection(Connection value) { _connection = va...

[C++] Changing Function Access Mode in Derived Class

Consider the following snippet: struct Base { virtual ~Base() {} virtual void Foo() const = 0; // Public }; class Child : public Base { virtual void Foo() const {} // Private }; int main() { Child child; child.Foo(); // Won't work. Foo is private in this context. static_cast<Base&> (child).Foo(); // Okay. Foo is public ...

Visual Studio's Access Modifier drop down option is disabled for resource file

Not sure why Access Modifier drop down is disabled for a Resource file. Here are file properties: ...

iPhone + access Controls from other class

I have classes: PropertyCalcViewController .m & .h In the .h I have IBOutlet UIButton *btnGo; @property (nonatomic, retain) IBOutlet UIButton *btnGo; and in the .m file I have @synthesize *btnGo; Now I also have another class Manager .m & .h. What I want to do is that access btnGo from the Manager class and remove it from Proper...

Private variables in a class can be accessed from main in Java?

I've recently started learning Java using JDK1.6. If this is a silly question, please excuse me. If private variables can be directly accessed by objects in main() how are they 'private'? public class Account1 { private int accountNum; private String name; Account1() { accountNum = 1101; name = "Scott"; } public void showData...

What is the difference between access specifiers and access modifiers ?

In Java, are access specifiers and access modifiers the same thing? ...

Help to understand the issue with protected method

I'm reading Sybex Complete Java 2 Certification Study Guide April 2005 (ISBN0782144195). This book is for java developers who wants to pass java certification. After a chapter about access modifiers (along with other modifiers) I found the following question (#17): True or false: If class Y extends class X, the two classes are in ...

Serialize List<> of classes declared with internal modifier?

I'm trying to add XML serialization to a fairly trivial class structure in C#. Essentially, there's a single instance of a root class (call it AClass), which holds a List of several instances of some other class (call it AnotherClass): [XmlRoot("RootNode")] public class AClass { [XmlElement("ListNode")] internal List otherObject...

How to make a ListView public in .NET winforms?

hi all, how can I make a ListView public? so I can access it from my first form thank you in advance best regards ...

internal abstract methods. Why would anyone have them ?

I was doing some code review today and came across an old code written by some developer. It goes something like this public abstract class BaseControl { internal abstract void DoSomething(); } If you have a derived class within the same assembly, it would work public class DerivedControl : BaseControl { ...

Java protected modifier not working as expected

I have the following two files: Fruit.java: package superClass; public class Fruit { protected static void printName() { System.out.println("My name is Khan"); } } Apple.java: package food; import superClass.*; public class Apple { public static void main(String[] args) { int i, j; for(i = 0; i < 5; i++) { for(j = ...

Why doesn't C# allow access modifiers on destructors?

I was making a simple class for a small project and decided to just add a destructor for a quick impl instead of using IDisposable, and I came across a compiler error whenever there is a destructor with an access modifier on it. public class MyClass { public ~MyClass() { // clean resources } } I tried public, priva...

public and private access modifiers

if we can access the private members through setters and getters then what is the use of private ? thanks in advance ...

Internal classes with ADO.NET Entity Framework

I'm using Entity Framework for creation of my Data Access Layer and I want for all of my classes to be internal. I know it is possible to manually assign it in the designer for each class. UPDATE I found that my initial statement But looks like it also requires to set internal modifier for each single property in every class! I hav...

Access modifiers - Property on business objects - getting and setting

Hi, I am using LINQ to SQL for the DataAccess layer. I have similar business objects to what is in the data access layer. I have got the dataprovider getting the message #23. On instantiation of the message, in the message constructor, it gets the MessageType and makes a new instance of MessageType class and fills in the MessageType in...