Sunday, November 13, 2011

UI String Matching in XAML and CS

A few month ago, we were doing String Localization for our software. It is lame for us to manually find the strings in the .cs and .xaml files and replace them with localization resource files.

So I look for help from REGEX, which is always helpful when dealing with strings.

Below is the regex to match UI String in xaml and cs files:

for .cs files:

^(~(ArgumentNullException|AddCMEventLog|//|dw\.add|OnPropertyChanged|Assembly\:|\[System\.|this\.RaisePropertyChanged|GeneratedCodeAttribute|throw\ new\ Exception).)+".*"(~(ArgumentNullException|AddCMEventLog).)+$

for .xaml files:

(Title="[^{])|(\ Text="[^{])|(Content="[^{])|(Header="[^{])|(ToolTip="[^{])|(Label="[^{])|(\ Value="[^{])|(Description="[^{])|(\>[^<>]+\<)

This may work in Visual Stdio only

Thursday, November 10, 2011

When you want to import dll

using System.Runtime.InteropServices;//DLLimport

[DllImport("winmm.dll", SetLastError = true)]

Tuesday, September 20, 2011

How special var is in C#, var can't be the type of property of class C#


var is static typed - the compiler and runtime know the type - they just save you some typing... the following are 100% identical:
var s = "abc";
Console.WriteLine(s.Length);
and
string s = "abc";
Console.WriteLine(s.Length);

Finding an ancestor and children of a WPF dependency object

Below are from : http://www.hardcodet.net/2008/02/find-wpf-parent


This is a simple snippet which helps you to find a specified parent of a given WPF dependency object somewhere in its visual tree:
(Snippet updated 2009.09.14)

/// <summary>
/// Finds a parent of a given item on the visual tree.
/// </summary>
/// <typeparam name="T">The type of the queried item.</typeparam>
/// <param name="child">A direct or indirect child of the
/// queried item.</param>
/// <returns>The first parent item that matches the submitted
/// type parameter. If not matching item can be found, a null
/// reference is being returned.</returns>
public static T TryFindParent<T>(this DependencyObject child)
    where T : DependencyObject
{

Saturday, September 10, 2011

Mercurial .hgrc

[ui]
username = Steven You <email>
[hostfingerprints]
bitbucket.org = 81:2b:08:90:dc:d3:71:ee:e0:7c:b4:75:ce:9b:6c:48:94:56:a1:fe
[extensions]
color =

Monday, September 5, 2011

Read binary in Hex

$ hexdump dog

or

$ cat dog | xxd

od -x can be used in mac, but the hight byte and low byte position is different

Thursday, September 1, 2011

Mac Dev Utilities

/Developer/Applications/Utilities/PackageMaker.app/Contents/MacOS