Object class extension for IEnumerable, IComparable and where : IEnumerable « Collections Data Structure « C# / C Sharp

Home
C# / C Sharp
1.2D Graphics
2.Class Interface
3.Collections Data Structure
4.Components
5.Data Types
6.Database ADO.net
7.Design Patterns
8.Development Class
9.Event
10.File Stream
11.Generics
12.GUI Windows Form
13.Language Basics
14.LINQ
15.Network
16.Office
17.Reflection
18.Regular Expressions
19.Security
20.Services Event
21.Thread
22.Web Services
23.Windows
24.Windows Presentation Foundation
25.XML
26.XML LINQ
C# / C Sharp by API
C# / CSharp Tutorial
C# / CSharp Open Source
C# / C Sharp » Collections Data Structure » IEnumerableScreenshots 
Object class extension for IEnumerable, IComparable and where
 
//http://arolibraries.codeplex.com/
//The MIT License (MIT)
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace AroLibraries.ExtensionMethods.Objects
{
    public static class ObjectExt
    {
        public static bool Ext_In<T>(this T value, IEnumerable<T> values)
        {
            if (values == null)
                throw new ArgumentNullException("values is NULL");

            return values.Contains(value);
        }

        public static T Ext_Limit<T>(this T value, T maximumwhere T : IComparable<T>
        {
            return value.CompareTo(maximum? value : maximum;
        }
        public static bool Ext_IsBetween<T>(this T me, T lower, T upperwhere T : IComparable<T>
        {
            return me.CompareTo(lower>= && me.CompareTo(upper0;
        }

        public static T Ext_GetInRangeValue<T>(this T me, T lower, T upper, T defaultIfLower, T defaultIfUpperwhere T : IComparable<T>
        {
            if (me.CompareTo(lower>= && me.CompareTo(upper<= 0)
            {
                return me;
            }
            else if (me.CompareTo(lower0)
            {
                return defaultIfLower;
            }
            else if (me.CompareTo(upper0)
            {
                return defaultIfUpper;
            }
            return default(T);
        }
        public static T Ext_GetInRangeValue<T>(this T me, T lower, T upper)
            where T : IComparable<T>
        {
            return Ext_GetInRangeValue<T>(me, lower, upper, lower, upper);
        }

    }
}

   
  
Related examples in the same category
1.Determines whether the specified collection is null or empty.
2.Determines whether the collection contains the specified element
3.Determines whether the collection contains all the elements in the specified collection.
4.Aggregate IEnumerable
5.Convert IEnumerable To DataTable
6.Convert IEnumerable by Func
7.Split IEnumerable
8.Shuffle IEnumerable
9.For each IEnumerable
10.Sleep before yield each element in IEnumerable
11.Add WhereIf to IEnumerable
12.Add OrderBy to IEnumerable
13.Add Repeat extension to IEnumerable
14.Yield element in IEnumerable until Predicate
15.IEnumerable extension for get second and third element
16.Simple function to determine if an item is an IEnumerable
17.Output DataTable and IEnumerable to console
18.Convert IEnumerable to String
19.Convert XmlNodeList to IEnumerable
20.Returns the first element contained in both, source and candidates.
21.Given a range (start,end) and a number of steps, will yield that a number for each step
22.Compares two sequences.
23.Empty Enumerable/Enumerator
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.