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 Expression
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
17 Views
no comments
 
C#
var text = "I (Iceland) Found (Faroe Islands) the Needles (Norway) South (Sweden) of Finland (Finland). Drinks (Denmark) for Everyone (Estonia) Laughed (Latvia) the Little (Lithuania) Neanderthal (Northern Ireland) Selling (Scotland) English (England) Wales (Wales) Inside (Ireland) Northern Europe";
var rg = new Regex(@"\([^)]*\)", RegexOptions.IgnorePatternWhitespace);
var replacedStr = rg.Replace(text,"");
by nyinyithann   February 16, 2011 @ 7:43am
107 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
330 Views
no comments
 
C#
// works as expected
public wws_Item LoadBySku(string sku)
{
    Expression< Func<wws_Item, bool> > func = itm => itm.Sku == sku;
 
    Entity = Context.wws_Items.Where(func).SingleOrDefault();
    if (Entity != null)
        OnLoaded(Entity);
 
    return this.Entity;
by Rick Strahl   October 04, 2009 @ 5:02pm
663 Views
no comments
 
C#
[TestFixture]
public class DropDownListExpressionTester {
 
   [Test]
   public void should_add_specified_custom_html_attributes() {
      var viewModel = new DropDownListViewModel();
 
      var expr = new DropDownListExpression<DropDownListViewModel>(viewModel, c => c.Value, "");
      expr.HtmlAttributes.Add("disabled", "disabled");
by Rob S   October 02, 2009 @ 3:16pm
264 Views
no comments
 
C#
public static DropDownListExpression<VIEWMODEL> DropDownFor<VIEWMODEL>(
      this IFubuView<VIEWMODEL> viewPage, Expression<Func<VIEWMODEL, object>> expression)
   where VIEWMODEL : class {
 
   return new DropDownListExpression<VIEWMODEL>(viewPage.Model, expression, "");
}
 
by Rob S   October 02, 2009 @ 3:11pm
303 Views
no comments
 
C#
public class DropDownListExpression<VIEWMODEL> : BoundExpression<VIEWMODEL, DropDownListExpression<VIEWMODEL>>
   where VIEWMODEL : class {
 
   private readonly Accessor _accessor;
   private readonly object _value;
   private readonly string _name;
 
   public DropDownListExpression(VIEWMODEL viewModel, Expression<Func<VIEWMODEL, object>> expression, string prefix)
      : base(viewModel, expression, prefix) {
      _accessor = ReflectionHelper.GetAccessor(expression);
by Rob S   October 02, 2009 @ 3:07pm
298 Views
no comments
 
C#
//  Copy and Paste this code into LINQPad and use the Nutshell database
    
    void Main()
    {
        var text = @"$Purchase.Customer.Name purchased $Detail on $Purchase.Date for $$$Purchase.Price";
        var Hello = new ExpressionTemplate<PurchaseItem>(text);
        
        var query = PurchaseItems.Select(Hello.ToExpr());
        
        query.Dump("Data");
by Steve Goguen   July 24, 2009 @ 7:42am
283 Views
no comments
 
C#
/// <summary>
/// Writes the text (expression body) of the function being called, followed by its output.
/// </summary>
/// <typeparam name="T">The return type of expression/function.</typeparam>
/// <param name="expression">
/// The expression/function to be evaluated and whose output will be displayed.
/// </param>
/// <remarks>
/// Useful in seeing the results of function calls while debugging or 
/// working on spike solutions (see http://www.extremeprogramming.org/rules/spike.html). 
by Al Gonzalez   July 14, 2009 @ 4:31pm
228 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