2008年9月27日星期六

C# 中的 ?? 操作符有什么用?

场景介绍:

程序存储一些用户设定到一个文件中,这些设置被分为多个集合,分别包装成class,每个集合中的值项被定义为property。如果取propertynull,则可以认为文件中不存在该值得记录。

示例代码:

public class MySettings
{
public string NumOfPoints{ get; set; }
}

public class UserPreferences
{
public MySettings Settings{ get; set; }
}

class Program
{
static void Main(string[] args)
{
UserPreferences option = new UserPreferences();
string num = option.MySettings01 ?? 10; // only ONE line
}
}

class Program
{
static void Main(string[] args)
{
UserPreferences option = new UserPreferences();

// THREE lines!
string num = 10;
if( option.MySettings01 != null )
num = option.MySettings01.NumOfPoints;
}
}

总结:

C#中的操作符 ?? 在处理 property null 时可以简化代码。

2008年9月23日星期二

使用Google阅读器,共享你看到的好文章

Google Reader有个功能,就是能向你的Google好友共享你看到的好文章

 


 

2008年8月24日星期日

Introduce WPF UI Automation Test

The video above is a MSDN example of WPF UI automation for automated testing. You can get the article here, get the example here. To run the example, you need VS2008 installed.

2008年8月12日星期二

C# code snippets

I started to use WPF in our recent project. I need implement INotifyPropertyChanged interface for some classes. So I learnt to use code snippets. I find it is very good! Here is a brief tutorial that can help you get started quickly.

1, dowload snippets, here is some provided by MS, here is some provied by Dr.WPF;


2, use code snippets manager import them;


3, right click mouse where you want to insert codes;



4, select the snippet;


5, see, the codes added!

Now, you may curious about how to create your own snippets. Here can help you to get start.

Here is a good free tool which can help you create your snippets.

2008年8月11日星期一

Use "HP Quick Lanch Buttons"

This may help if you own a HP laptop, if you do not have one, you can skip it.


I have seen this small rocket for almost 2 years, but I learnt to use it only few days ago.


One function I like is "ZOOM". When you use 1680 * 1050 screen resolution, you may want to use large font. Here is the quicker way than change screen properties. I change this frequently because I am using dual monitors.


Another function I like is the quick buttons. There is button, a circle around a question mark, on the left top of your laptop keybord. Press the button, you get the button menus. Right click on the small rocket, you can "Adjust HP Quick Lanch Buttons Properties".

2008年7月30日星期三

Visula Studio Tips

Tip #4 : Conditional Compilation Symbols


[Conditional("condition1")]
public void Foo()
{
...
}

But I found some limitations for it:
1, can not apply to interface functions;
2, the return type of functions MUST be void.


Tip #3
: In MFC projects, use "Call Browser". You can see it in right click popup menu.




Tip #2 : enable mixed mode debug. When you call managed functions from un-managed world. You may found the managed codes sample can NOT be loaded. Here is the trick to enable the load.



Tip #1 : use "ctrl + i" to search. after press the two keys, you can see a telescope shown on the screen, then type the word you want to search. Some time this is more convenient than "ctrl + f".

2008年7月22日星期二

Expression Blend Tips


Tip #1:
Use "search" to find the property you want.
Tip #2:
Use "Color Eyedropper", you can pick any displayed color on your PC screen.