CodePaste Logo
New Snippet New Snippet Recent Snippets Recent Snippets My Snippets My Snippets Web Code Search Snippets Search
Sign inor Register
Format:
Recent snippets matching tags of expressions
C#
//Email regex validator
Regex regex = new Regex(@"\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*");
 
//Website regex validator
Regex regex = new Regex(@"^http\://[a-zA-Z0-9\-\.]+\.[a-zA-Z]{2,3}(/\S*)?$");
 
//Comments on forum regex validator (max 4000 characters)
Regex regex = new Regex(@"^[+_%@:,.'!?"\\\^\&\#\$\*\(\)\-\/a-zA-Z0-9\s]{1,4000}$");
by Egli   Monday @ 9:34pm
11 Views
no comments
 
C#
protected void Map(Expression<Func<T, object>> property, Func<PropertyDescriptor, string> columnNamer)
{
    MemberInfo memberInfo;
 
    if (property.Body is MemberExpression)
        memberInfo = ((MemberExpression)property.Body).Member;
    else
        memberInfo = ((MemberExpression)((UnaryExpression)property.Body).Operand).Member;
 
    Map(memberInfo.Name, columnNamer);
by Andy Sherwood   February 04, 2011 @ 3:24pm
184 Views
no comments
 
C#
using System;
using System.Linq.Expressions;
 
public static class Aaa
{
    public class A
    {
        public string NameField;
    }
by b1gbr0   October 26, 2010 @ 3:30am
177 Views
no comments
 
C#
public static void Copy(string sourceDirName, string destDirName, bool excludeSubdirectories)
{
    // Style #1: fluent
    Guard.MethodArgument("sourceDirName").IsNotNullOrEmpty(sourceDirName);
    Guard.MethodArgument("destDirName").IsNotNullOrEmpty(destDirName, "The destination directory is required!");
 
    // Style #2: lambdas and expressions
    Guard.Argument.IsNotNullOrWhiteSpace(()=>sourceDirName);
    Guard.Argument.IsNotNullOrWhiteSpace(()=>destDirName, "The destination directory is required!");
by Al Gonzalez   May 24, 2010 @ 8:58pm
310 Views
1 comments
 
C#
[TestMethod]
public void CanGetValueItemfromCollection()
{
    var col = new Collection<string> {"Hello", "World"};
    var testItem = col.GetValueItem(c => c.Equals("World"));
    Assert.AreEqual(testItem, "World");
}
 
[TestMethod]
public void CanGetReferenceItemfromCollectionByProperty()
by Bob Baker   December 18, 2009 @ 12:01pm
302 Views
no comments
 
C#
/// <summary>
/// Find an object in a value-type collection.
/// </summary>
/// <typeparam name="T">Type of collection.</typeparam>
/// <param name="collection">The collection to search.</param>
/// <param name="isMatch">The Predicate to test to find the collection item.</param>
/// <returns>The collection item.</returns>
public static T GetValueItem<T>(this ICollection<T> collection, Predicate<T> isMatch)
{
    foreach (var item in collection)
by Bob Baker   December 18, 2009 @ 12:00pm
280 Views
no comments
 
C#
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Text.RegularExpressions;
using System.Text;
using System.IO;
using System.Reflection;
by Dean Weber   October 08, 2009 @ 7:54am
329 Views
no comments
 
brought to you by:
West Wind Techologies



If you find this site useful and use it frequently please consider making a donation to support this free service.
Donate