access-modifiers

Protected member visible for user

穿精又带淫゛_ 提交于 2019-12-12 18:25:24
问题 It will be my first question here so please be lenient. How is this possible: //there is a Form1 class which has a TableAdapter member generated by designer... partial class Form1 { private void InitializeComponent() { this.SomeTableTableAdapter = new SomeDatabaseDataSetTableAdapters.SomeTableTableAdapter(); } private SomeDatabaseDataSetTableAdapters.SomeTableTableAdapter SomeTableTableAdapter; } //here is this TableAdapter class //It has PROTECTED member called "Adapter" public partial class

Regarding access specifiers

非 Y 不嫁゛ 提交于 2019-12-12 14:22:32
问题 I defined a Class Base class Base { private int i; Base(int i) { this.i = i; } } So object of Base class can access private variable. class BaseDemo { public static void main(String[] args) { Base objBase = new Base(10); System.out.println(objBase.i); } } But it's giving me a compiler error I has private access in Base . I'm confused while coding, what is wrong? 回答1: See Controlling Access to Members of a Class: Modifier Class Package Subclass World -------------------------------------------

Add a web reference to a project but make the auto-generated proxy classes internal (i.e. not public)

岁酱吖の 提交于 2019-12-12 13:16:16
问题 I'm building a class library that uses a web reference in its data access layer, but much to my dismay, there doesn't seem to be an acceptable way to set the access for the auto-generated proxy classes. By default, they're public , but I don't want to expose the proxy classes outside the library. I've found this on MSDN, but all the answers indicate manually altering the proxy classes to set the access modifiers. Not surprisingly, the proxy classes all have this at the top: //----------------

What kind of access modifiers can be applied to a class?

南楼画角 提交于 2019-12-12 12:00:56
问题 After a little research I've determined that the only access modifiers which you can apply to classes are: public - available in any assembly internal - available only in the current assembly but the error message below seems to imply that if a class is not defined in a namespace that it could be defined as private , protected , or protected internal . Are public and internal the only class modifiers you can use on class or are there more? using System; using System.Collections.Generic; using

Serialize List<> of classes declared with internal modifier?

萝らか妹 提交于 2019-12-12 11:01:49
问题 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 otherObjects { get; set; } } public class AnotherClass { [XmlAttribute("Name")] internal string name { get; set; } } When serializing, I'd like for both these classes to be

What is the equivalent of Java's default (package) access in C#?

天涯浪子 提交于 2019-12-12 08:46:33
问题 What is the equivalent of Java's default (package) access in C#? Is there one? Is there anyway to restrict access to a particular namespace? The Problem: I'm trying to restrict access to certain methods to just my NUnit tests - in JUnit I would do this by making the methods package access and having the test in the same package but under src/test/java instead of src/main/java. How can I achieve something similar in C#? Note: I can't make the methods internal because my tests are in a separate

Why does collection initialization ignore access modifiers? [duplicate]

人盡茶涼 提交于 2019-12-11 12:18:59
问题 This question already has answers here : C# object initialization of read only collection properties (4 answers) Closed 6 years ago . Spawing from this answer, some code appeared that seems to not make sense: class Program { static void Main(string[] args) { var t = new Testing { ListOfStrings = { "hello", "goodbye" } }; Console.ReadKey(); } } public class Testing { public List<string> ListOfStrings { get; private set; } public Testing() { ListOfStrings = new List<string>(); } } At first

c# RuntimeBinderException when using dynamic variable to handle internal types. How can I fix that?

南笙酒味 提交于 2019-12-11 10:21:39
问题 I'm using a not-fully-exposed API in the add-on that I'm currently writing. Some classes there are still kept internal, although some public methods require parameters of these types. To handle the problem I tried to use dynamic typing with a helper DymamicObject implementation. I was pretty successful doing so but at one point I get a RuntimeBinderException, which doesn't tell me the exact details: "The best overloaded method match for Autodesk.Civil.DatabaseServices.PressurePipeNetwork

Make field/method accessible only to derived classes within same assembly? [duplicate]

一曲冷凌霜 提交于 2019-12-11 07:30:28
问题 This question already has answers here : How to make a property protected AND internal in C#? (7 answers) Closed 6 years ago . On a public class in C# is there a way to make a field/method accessible only to derived classes within the same assembly? From what I understand protected internal in C# means the same as protected or internal (ie accessible to derived classes or classes from the same assembly), which is not what I need. 回答1: What if you removed the "internal" only fields/methods

Protected “read only” proxy class for primitives in c++

会有一股神秘感。 提交于 2019-12-11 07:18:33
问题 I recently stumbled up this proxy class for making c++ primitive members "read only" (publicly act as const references, but privately non const). This potentially eliminates the need for boilerplate "getters". The proxy class looks like: template <Container,Primitive> class RO { friend Container; public: inline operator Primitive() const { return x; } template<typename Other> inline bool operator==(const Other& y) const { return x == y; } template<typename Other> inline bool operator!=(const