Format:
Recent snippets matching tags of Expression
//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}$");
17 Views
no comments
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,"");
107 Views
no comments
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);
184 Views
no comments
using System; using System.Linq.Expressions; public static class Aaa { public class A { public string NameField; }
177 Views
no comments
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!");
310 Views
1 comments
[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()
302 Views
no comments
/// <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)
280 Views
no comments
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;
330 Views
no comments
// 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;
663 Views
no comments
[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");
264 Views
no comments
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, ""); }
303 Views
no comments
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);
298 Views
no comments
// 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");
283 Views
no comments
/// <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).
228 Views
no comments
Subscribe
Discuss
What's new
What is it
New Snippet
Recent Snippets
My Snippets
Web Code
Search
