Archive for Gennaio 7th, 2008

Getting the binding element from the current DataContext

CodeKeep C# Feed Gennaio 7th, 2008

Description: Getting the binding element from the current DataContext

Link: http://www.codekeep.net/snippets/b88e163f-46da-41c1-b56d-f2d5112bfda8.aspx

private Binding GetBinding(string path)
        {
            Binding binding1 = new Binding();
            binding1.Source = this.DataContext;
            binding1.Mode = BindingMode.Default;
            binding1.Path = new PropertyPath(path);
            return binding1;
        }

Email Obfuscator

CodeKeep C# Feed Gennaio 7th, 2008

Description: Obfuscates email addresses found in given string

Link: http://www.codekeep.net/snippets/ef09155a-04df-44ea-9d90-bf6661392a98.aspx

protected string obfuscate(string input)
{

	string email = string.Empty;

	MatchCollection matches = Regex.Matches(input, @"[a-zA-Z]+[a-zA-Z0-9]*[\.|\-|_]?[a-zA-Z0-9]+@([a-zA-Z]+[a-zA-Z0-9]*[\.|\-|_]?[a-zA-Z]+[a-zA-Z0-9]*[a-zA-Z0-9]+){1,4}\.[a-zA-Z]{2,4}", RegexOptions.Singleline | RegexOptions.IgnoreCase);

	foreach (Match match in matches)
	{
		email = string.Empty;
		Array matcharray = match.Value.ToCharArray();
		foreach (char letter in matcharray)
		{
			email += "&#" + Convert.ToInt32(letter).ToString() + ";";
		}

		input = input.Substring(0, match.Index)+email+input.Substring((match.Index+match.Length));
	}
	return input;
}

Focus

CodeKeep C# Feed Gennaio 7th, 2008

Description: Set control focus

Link: http://www.codekeep.net/snippets/75f273fb-217d-47b8-a7f8-0b5d263dfb00.aspx

this.txtPassword.Select();