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 Generics
C#
public static IList<T> ToList<T>(this System.Data.SqlClient.SqlDataReader dr) where T : new()
       {
           Type type = typeof(T);
           if(System.Web.HttpContext.Current.Cache[type.Name + "_properties"] == null)
           {
               System.Web.HttpContext.Current.Cache.Insert(type.Name + "_properties", type.GetProperties().ToList());
           }
           IList<PropertyInfo> properties = (IList<PropertyInfo>)System.Web.HttpContext.Current.Cache[type.Name + "_properties"];
           IList<T> result = new List<T>();
           while(dr.Read())
by ofer   September 25, 2011 @ 3:18am
82 Views
no comments
 
C#
public static decimal Accumulate(IEnumerable e)
{
   decimal sum = 0;
 
   foreach (Account a in e)
      sum += a.Balance;
 
   return sum;
}
by Athens Springer   October 15, 2010 @ 12:35pm
129 Views
no comments
 
C#
 
var realHandler = GetHandler<SomeType>();
var message = GetMessage(); //Returns derived type of SomeType
var handlerType = typeof(IHandler<>);
var genericType = message.GetType();
var genericHandler = handlerType.MakeGenericType(genericType);
 
return realHandler --> as genericHandler would not work
by Hadi Eskandari   July 19, 2010 @ 8:45am
Tags: Generics
181 Views
no comments
 
C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
 
namespace Orxxx.Data 
{
    public interface IRepository<T> 
    {
        void Create(T entity);
by darek156   May 07, 2010 @ 1:54am
Tags: generics
171 Views
no comments
 
C#
public interface IRepository<T>
{
    T GetById(Guid id);
    T GetByQuery(Query query);
    void Add(T item);
    void Remove(T item);
    void Update(T item);
}
 
//mozliwe jest rozszezenie generycznego interfejsu o metody specyfikczne
by darek156   April 02, 2010 @ 1:21am
303 Views
no comments
 
C#
public class AnonymousComparer<T> : IComparer<T>
{
    private Comparison<T> comparison;
 
    public AnonymousComparer(Comparison<T> comparison)
    {
        if (comparison == null)
            throw new ArgumentNullException("comparison");
        this.comparison = comparison;
    }
by darek156   April 01, 2010 @ 1:47am
Tags: generics
158 Views
no comments
 
C#
/// <summary>
/// Return all properties from a type up to a specified base type in the inheritance hierarchy
/// </summary>
/// <param name="type">Type that will be examined</param>
/// <param name="baseType">Where to stop in the inheritance hierarchy. Must be a type that first parameter inherits from
/// </param>
/// <returns>A list of all found properties</returns>
public static List<PropertyInfo> GetAllProperties(Type type, Type baseType)
{
   List<PropertyInfo> properties = new List<PropertyInfo>();
438 Views
no comments
 
C#
[XmlRoot("dictionary")]
public class XmlSerializableDictionary<TKey, TValue>
   : Dictionary<TKey, TValue>, IXmlSerializable {
 
   #region Constructors
   public XmlSerializableDictionary() : base() { }
 
   public XmlSerializableDictionary(IDictionary<TKey, TValue> dictionary) : base(dictionary) { }
 
   public XmlSerializableDictionary(IEqualityComparer<TKey> comparer) : base(comparer) { }
by Athens Springer   December 17, 2009 @ 10:34pm
319 Views
no comments
 
C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using LinqExtender.Configuration.Serialization;
 
namespace LinqExtender.Configuration
{
    /// <summary>
by Athens Springer   December 17, 2009 @ 10:14pm
185 Views
no comments
 
C#
GenericSorter<surveystateformatdata> gs = new GenericSorter<surveystateformatdata >();
SurveyStateFormatItems = gs.Sort(SurveyStateFormatItems.AsQueryable, 
                                 sortExpression, sortDirection).ToArray();
by Athens Springer   October 29, 2009 @ 9:12am
Tags: C#, Generics
204 Views
no comments
 
C#
using System; 
using System.Collections.Generic; 
using System.Linq; 
using System.Linq.Expressions; 
 
 
public class GenericSorter<T>
{
    public IEnumerable<T> Sort(IEnumerable<T> source, string sortBy, string sortDirection)
    {
by Athens Springer   October 29, 2009 @ 9:11am
Tags: C#, Generics, LINQ
305 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