private-members

Private Accessors in Visual Studio 2012

岁酱吖の 提交于 2019-12-07 03:40:02
问题 as far as I know Visual Studio 2012 will not support Private Accessors. Can you give me some infos on possible alternatives? PrivateObject.Invoke() is not the best solution for me. Thank you in advance! 回答1: Mark your members as "internal" and use the InternalsVisibleTo attribute. Simple to use and no type safety issues. 回答2: Maybe this posting Home-made Private Accessor for Visual Studio 2012+ will help you creating your own Private Accessor. Regards, Stefan 回答3: I started using the Dynamic

Modify private readonly member variable?

孤人 提交于 2019-12-06 04:47:14
I have the following code : public class MyClass { private readonly string name; public string Name { get { return name; } } public MyClass(string name) { this.name = name; } } class Program { static void Main(string[] args) { MyClass mc = new MyClass("SomeName"); } } Is there any way I can change the value of mc.name without modifying the class? You can only use reflection typeof(MyClass) .GetField("name",BindingFlags.Instance|BindingFlags.NonPublic) .SetValue(myclassInstance, 123); Adam Flanagan With reflection , yes ( Can I change a private readonly field in C# using reflection? ), but

Are you explicitly unit testing a private method when you use your knowledge of the private method to choose test cases

三世轮回 提交于 2019-12-06 01:57:35
It seems as though the general consensus of the testing community is to not test private methods. Instead, you should test private methods by testing the public methods that invoke them . However, something just doesn't feel right to me. Let's take this method for example: /** * Returns the base name of the output generator class. If the class is named * Reno_OutputGenerator_HTML, this would return "HTML". * * @return string */ protected function getName() { $class = get_class($this); $matches = array(); if (preg_match('/^Reno_OutputGenerator_(.+)$', $class, $matches)) { return $matches[1]; }

Javascript private methods — what is the memory impact?

你说的曾经没有我的故事 提交于 2019-12-05 23:13:47
I'm working on a bit of code where I'm attempting to hide some private variables inside closures. The thing is the environment is fairly constrained in terms of memory, so I'm also concerned with keeping the overall footprint of the classes low. What is the impact of using closures to hide private instance variables and methods when compared to just making all methods and variables on an object public? Would an instance of the one using closures take up more memory than an instance that did not use closures? If so, how much more memory would I expect to use? my code would look like this

Test a public method which calls a private method using NUnit

被刻印的时光 ゝ 提交于 2019-12-05 16:49:36
I have a public method in a class that internally calls a particular private method within that class. It looks something like this : public class MyClass : IMyClassInterface { public List<int> MyMethod(int a, int b) { MyPrivateMethod(a, b, ref varList, ref someVal); } private void MyPrivateMethod(int a, int b, ref List<int> varList, ref double someval) { } } Now, I basically want to test this public method using NUnit. I am using NMock 2.0 for mocking. How do I do it? Since, it internally calls this private method which I do not want to make public. Or is there a way to do it if I turn the

Private Accessors in Visual Studio 2012

混江龙づ霸主 提交于 2019-12-05 07:46:09
as far as I know Visual Studio 2012 will not support Private Accessors. Can you give me some infos on possible alternatives? PrivateObject.Invoke() is not the best solution for me. Thank you in advance! Mark your members as "internal" and use the InternalsVisibleTo attribute. Simple to use and no type safety issues. Maybe this posting Home-made Private Accessor for Visual Studio 2012+ will help you creating your own Private Accessor. Regards, Stefan I started using the Dynamic Private Accessor feature that is part of the nuget package Chaining Assertion for MSTest and I am rather happy with it

When to use one or two underscore in Python [duplicate]

坚强是说给别人听的谎言 提交于 2019-12-05 03:40:33
This question already has answers here : What is the meaning of a single and a double underscore before an object name? (14 answers) Closed 9 months ago . Ok I think I have understood the use of one and two heading underscores in Python. Correct me if I am wrong, In the case of one underscore, the underscore prevents the from X import * statement to import this kind of variables. In the case of two underscores, the variable's name is prepended with the name of the class it belongs to allow a higher level of "privateness". My question now is: why not use two underscores only? In which cases one

C++ override private pure virtual method as public

我与影子孤独终老i 提交于 2019-12-04 23:40:42
Why does this happen? http://coliru.stacked-crooked.com/a/e1376beff0c157a1 class Base{ private: virtual void do_run() = 0; public: void run(){ do_run(); } }; class A : public Base { public: // uplift ?? virtual void do_run() override {} }; int main() { A a; a.do_run(); } Why can I override a PRIVATE virtual method as public? According to https://en.cppreference.com/w/cpp/language/virtual#In_detail overwriting a base's virtual member function only care about the function name, parameters, const/volatile-ness and ref qualifier. It doesn't care about return type, access modifier or other things

How to instantiate PrivateType of inner private class

柔情痞子 提交于 2019-12-04 19:31:28
问题 I was trying to setup a unit test for a private inner class, but had very little success: namespace Stats.Model { public class DailyStat { private class DailyStatKey // The one to test { private DateTime date; public DateTime Date { get { return date; } set { date = value.Date; } } public StatType Type { get; set; } public override int GetHashCode() { return Date.Year * 1000000 + Date.Month * 10000 + Date.Day * 100 + (int)Type; } public override bool Equals(object obj) { DailyStatKey otherKey

Private members when extending a class using ExtJS

不打扰是莪最后的温柔 提交于 2019-12-04 07:47:57
问题 I have done some research on the ExtJS forum regarding private methods and fields inside a extended class , and I couldn't find any real answer to this. And when I say an extended class I mean something like this: Ext.ux.MyExtendedClass = Ext.extend(Ext.util.Observable, { publicVar1: 'Variable visible from outside this class', constructor: function(config) { this.addEvents("fired"); this.listeners = config.listeners; }, // to show that I need to use the base class publicMethod1: function() {