c#

C#的反射笔记

☆樱花仙子☆ 提交于 2019-12-14 21:34:11
【推荐】2019 Java 开发者跳槽指南.pdf(吐血整理) >>> GetMembers ;成员,包括所有的get_和set_方法,以及GetHashCode() .ctor() GetType()等方法 以及public的成员属性 GetProperties public成员属性 GetMethods 所有的方法,不包括.ctor(),包括ToString Equals() GetHashCode() GetType()和默认的get_和set_方法 GetFields(BindingFlags.NonPublic|BindingFlags.Instance|BindingFlags

C# 为私有方法添加单元测试(使用反射) Add Unit Test for private ...

雨燕双飞 提交于 2019-12-14 21:33:57
【推荐】2019 Java 开发者跳槽指南.pdf(吐血整理) >>> C# 为私有方法添加单元测试(使用反射) Add Unit Test for private method in C# using reflection 在Visuall Studio 2010或更老的版本中,使用系统生成默认的单元测试就可以测试私有方法。以VS 2010为例,在一个方法上单击右键,选择创建单元测试即可。生成的单元测试中,会为私有方法生成accesor,这时就可以在单元测试中访问私有方法了。 但是,这个方法在Visual Studio 2012中被去掉了,并且微软官方声称这是不佳实践,以后可能都不会支持了

Equals() vs Static string.Equals()

天大地大妈咪最大 提交于 2019-12-14 04:27:50
问题 Reading about string comparison in c# i found many ways to compare 2 strings to see if they are equal. I was used to == coming from c++ but i learned that if you compare an object with a string then == defaults to reference value (or something like that). Then for the Equals() method lets say i

Custom attached property of ResourceDictionary with implicit declaration syntax?

二次信任 提交于 2019-12-14 04:27:22
问题 As you know a FrameworkElement has a property of type ResourceDictionary named Resources , in XAML we can declare it easily like this: <FrameworkElement.Resources> <SomeObject x:Key="someKey"/> <SomeOtherObject x:Key="someOtherKey"/> </FrameworkElement.Resources> It's some kind of implicit syntax

How to successfully drive a MassTransitStateMachine via the InMemoryTestHarness?

情到浓时终转凉″ 提交于 2019-12-14 04:27:15
问题 Following up to: How to write MassTransitStateMachine unit tests? Here's a simple test class (using MS Test) for a simple state machine called ProcedureStateMachine (note: this is not a real production state machine for us... just an experiment I'd used to play around with MassTransitStateMachine

Set DataGridViewComboBox default equal to existing DataGridView column

不羁的心 提交于 2019-12-14 04:26:42
问题 I have added a DataGridViewComboBox to a bound DataGridView ( grdBOOK ), the DataGridViewComboBox will replace column 3 to allow for user selection. I'm struggling to set the default of the DataGridViewComboBox equal to the value of column 3 so user selection is not required if the value is

How can I map JSON to a .NET class

淺唱寂寞╮ 提交于 2019-12-14 04:26:26
问题 I want to map this JSON into a .NET class. How can I map this JSON data into a class? Please suggest how. Here is the json: {"results": [ "43853", "43855", "43856", "43857", { "questionType": 3, "choiceAnswers": [123] } ]} 回答1: The easiest solution is to use Visual Studio Edit > Paste Special >

How to display a dictionary which contains a list in a listBox C#

无人久伴 提交于 2019-12-14 04:26:18
问题 I currently have a dictionary which contains a key value and a list associated with that key. I have read How to bind Dictionary to ListBox in winforms and when I try to implement that it just displays the key value. What I am trying to do is have two separate listboxs. In box 1 you select the