public static void ArgumentInRange(IComparable argument, IComparable minimum, IComparable maximum, string paramName = DefaultParamName) { if (argument.CompareTo(minimum) < 0 || argument.CompareTo(maximum) > 0) { throw new ArgumentException(string.Format("{0} must be between {1} and {2}.", paramName, minimum, maximum), paramName); } }
public bool CompareToRange(IComparable target, IComparable start, IComparable end) { if (target == null || start == null || end == null) return false; if (start.CompareTo(end) == 0 ) return target.CompareTo(start) == 0; return target.CompareTo(start) >= 0 && target.CompareTo(end) <= 0; }
/// <summary> Insert into the tree. Does nothing if item already present. /// </summary> /// <param name="item">the item to insert. /// </param> public virtual void Insert(IComparable item) { current = parent = grand = header; nullNode.element = item; while (current.element.CompareTo(item) != 0) { great = grand; grand = parent; parent = current; current = item.CompareTo(current.element) < 0?current.left:current.right; // Check if two red children; fix if so if (current.left.color == RED && current.right.color == RED) handleReorient(item); } // Insertion fails if already present if (current != nullNode) return ; current = new RedBlackNode(item, nullNode, nullNode); // Attach to parent if (item.CompareTo(parent.element) < 0) parent.left = current; else parent.right = current; handleReorient(item); }
public static IComparable vad(IComparable val1, IComparable val2) { if (val1.CompareTo(val2) < 0) return val1; if (val1.CompareTo(val2) > 0) return val2; if (val1.CompareTo(val2) == 0) return val1; return null; }
/// <summary> /// adds a new item to the tree /// </summary> /// <param name="newKey">the key for the new entry</param> /// <param name="o">the new item<</param> /// <returns>true id added successfully</returns> public bool Put(IComparable newKey, Object o) { if (key == null) { key = newKey; dataItem = o; return true; } else if (newKey.CompareTo(key) > 0) { if (rightSubTree == null) rightSubTree = new SimpleBST(); bool result = rightSubTree.Put(newKey, o); return result; } else if (newKey.CompareTo(key) < 0) { if (leftSubTree == null) leftSubTree = new SimpleBST(); bool result = leftSubTree.Put(newKey, o); return result; } else return false; }
internal static void ValidateMinMaxValue(this OpenType openType, IComparable defaultValue, IComparable minValue, IComparable maxValue) { if (minValue != null) { if (!openType.IsValue(minValue)) { throw new OpenDataException("Minimum value must be valid for supplied open type."); } if (defaultValue != null && minValue.CompareTo(defaultValue) > 0) { throw new OpenDataException("Minimum value must be less or equal to default value."); } } if (maxValue != null) { if (!openType.IsValue(maxValue)) { throw new OpenDataException("Maximum value must be valid for supplied open type."); } if (defaultValue != null && defaultValue.CompareTo(maxValue) > 0) { throw new OpenDataException("Maximum value must be greater than or equal to default value."); } } if (maxValue != null && minValue != null && minValue.CompareTo(maxValue) > 0) { throw new OpenDataException("Maximum value must be greater than or equal to minimum value."); } }
/// <summary> /// /// </summary> /// <param name="value"></param> /// <returns></returns> public override bool Verify(IComparable value) { int fr =value.CompareTo(this.From) ; int tr = value.CompareTo(this.To ); if (fr >= 0 && tr <= 0) { return true; } return false; }
public void delete(IComparable item) { ListNode currNode = list; if (item.CompareTo(currNode.info) == 0) list = list.next; // delete first node else { while (item.CompareTo(currNode.next.info) != 0) currNode = currNode.next; //move ahead currNode.next = currNode.next.next; //delete node at a location ie delete current.next node numItems--; } }
static bool compare(IComparable a, IComparable b) { if (a.CompareTo(b) > 0) { return true; } else { return false; } }
protected int DictentryCompare(DictionaryEntry d1, DictionaryEntry d2) { IComparable c1 = d1.Key as IComparable; IComparable c2 = d2.Key as IComparable; return(c1?.CompareTo(c2) ?? 0); }
/// <summary> /// Initializes a new instance of the <see cref="BetweenValidator"/> class. /// </summary> /// <param name="from">From.</param> /// <param name="to">The automatic.</param> public BetweenValidator(IComparable @from, IComparable to) { if (@from == null) { throw new ArgumentNullException("from"); } if (to == null) { throw new ArgumentNullException("to"); } if (!to.GetType().IsInstanceOfType(@from)) { throw new ArgumentException(string.Format(CultureInfo.CurrentCulture, "'To' value should be type of '{0}'", @from.GetType().FullName)); } if (to.CompareTo(@from) == -1) { throw new ArgumentOutOfRangeException("to", "'To' should be larger than 'from'."); } m_From = @from; m_To = to; m_ValidatorProperties = new ValidatorProperties { { Constants.ValidationMessageParameterNames.FROM_VALUE, FromValue }, { Constants.ValidationMessageParameterNames.TO_VALUE, ToValue } }; }
/// <summary> /// The following method compares any 2 objects and test if they are equal. /// It will also compare equality of numbers in a very special way. /// Examples: /// IsEqual(Int64.MaxValue, Int64.MaxValue) //is true /// IsEqual(Int64.MaxValue, Int64.MaxValue-1) //is false /// IsEqual(123, 123.0) //is true /// IsEqual(654f, 654d) //is true /// </summary> internal static int Compare(IComparable a, IComparable b) { if (IsNumber(a) && IsNumber(b)) { if (IsFloatingPoint(a) || IsFloatingPoint(b)) { double da, db; if (Double.TryParse(a.ToString(), out da) && Double.TryParse(b.ToString(), out db)) return da.CompareTo(db); } else { if (a.ToString().StartsWith("-") || b.ToString().StartsWith("-")) { var a1 = Convert.ToInt64(a); var b1 = Convert.ToInt64(b); return a1.CompareTo(b1); } else { var a1 = Convert.ToUInt64(a); var b1 = Convert.ToUInt64(b); return a1.CompareTo(b1); } } } return a.CompareTo(b); }
public static bool TryMaxElement <TSource>(this IEnumerable <TSource> src, Func <TSource, IComparable> selector, out TSource element) { using (IEnumerator <TSource> enumerator = src.GetEnumerator()) { if (!enumerator.MoveNext()) { element = default(TSource); return(false); } TSource maxItem = enumerator.Current; IComparable maxValue = selector(maxItem); while (enumerator.MoveNext()) { TSource item = enumerator.Current; IComparable value = selector(item); if (value?.CompareTo(maxValue) != 1) { continue; } maxItem = item; maxValue = value; } element = maxItem; return(true); } }
public static void ArgumentAtMost(IComparable argument, IComparable maximum, string paramName = DefaultParamName) { if (argument.CompareTo(maximum) > 0) { throw new ArgumentException(string.Format("{0} must be at most {1}.", paramName, maximum), paramName); } }
public override void InsertKeyAndValue(IComparable key, object value) { var position = GetPositionOfKey(key); var addToExistingCollection = false; int realPosition; if (position >= 0) { addToExistingCollection = true; realPosition = position - 1; } else { realPosition = -position - 1; } // If there is an element at this position and the key is different, // then right shift, size // safety is guaranteed by the rightShiftFrom method if (realPosition < NbKeys && key.CompareTo(Keys[realPosition]) != 0) RightShiftFrom(realPosition, true); Keys[realPosition] = key; // This is a non unique btree node, manage collection ManageCollectionValue(realPosition, value); if (!addToExistingCollection) NbKeys++; }
private static int newHole(int hole, IComparable item, int lastIndex) { int left = (hole*2) + 1; //left child int right = (hole*2) + 2; //right child if (left > lastIndex) // hole has no childerns return hole; if (left == lastIndex) // hole has left child only if (item.CompareTo(elements[left]) < 0) // item < left child return left; else // item >= right child return hole; // left child < right child if (elements[left].CompareTo(elements[right]) < 0) if (elements[right].CompareTo(item) < 0) // right child <= item return hole; else // item < right child return right; else // left child >=right child if (elements[left].CompareTo(item) < 0) // left child <= item return hole; else // item < left child return left; }
/// <summary> /// Checks that a comparable checked value is after another given value. /// </summary> /// <param name="checkedValue">The checked value.</param> /// <param name="givenValue">The other given value.</param> /// <exception cref="NFluent.FluentCheckException">The checked value is not after the given value.</exception> public static void IsAfter(IComparable checkedValue, IComparable givenValue) { if (checkedValue == null || checkedValue.CompareTo(givenValue) <= 0) { throw new FluentCheckException(FluentMessage.BuildMessage("The {0} is not after the reference value.").On(checkedValue).And.Expected(givenValue).Comparison("after").ToString()); } }
public ExclusiveBetweenValidator(IComparable from, IComparable to) : base(() => Messages.exclusivebetween_error, ValidationErrors.ExclusiveBetween) { To = to; From = from; if (to.CompareTo(from) == -1) { throw new ArgumentOutOfRangeException("to", "To should be larger than from."); } }
public static void NotEquals(IComparable a, IComparable b, string message=null) { if(a == null) throw new AssertFailedException("a is null"); if(b==null) throw new AssertFailedException("b is null"); if(a.CompareTo(b) == 0) throw new AssertFailedException(String.IsNullOrEmpty(message) ? a.ToString() + " == " + b.ToString() : message); }
/// <summary> /// Tries to compare the two objects, but will throw an exception if it fails. /// </summary> /// <returns>True on success, otherwise False.</returns> public static int GetComparisonResult(IComparable value, IComparable valueToCompare) { int result; if (TryCompare(value, valueToCompare, out result)) { return result; } return value.CompareTo(valueToCompare); }
/// <summary> /// Set ImplicitDefault to the default value of <paramref name="explicitDefault"/>'s type, /// and ExplicitDefault to <paramref name="explicitDefault"/>. /// </summary> /// <param name="explicitDefault"></param> /// <param name="storeInBase"></param> /// <param name="nativeToString"></param> internal ValueDescription(IComparable explicitDefault, bool storeInBase = true, ValueNativeToString nativeToString = null) { ImplicitDefault = GetImplicitDefault(explicitDefault.GetType()); ExplicitDefault = explicitDefault; DefaultsDiffer = (ImplicitDefault.CompareTo(ExplicitDefault) != 0); StoreInBase = storeInBase; NativeToString = nativeToString; }
/// <summary> /// finds an item by key /// </summary> /// <param name="target">the key for the target item</param> /// <returns>the item found</returns> public Object Get(IComparable target) { Object o = null; if (target.CompareTo(key) == 0) o = dataItem; else if (target.CompareTo(key) > 0) { o = rightSubTree.Get(target); } else if (target.CompareTo(key) < 0) { o = leftSubTree.Get(target); } return o; }
private void Initialize(IComparable minimum, IComparable maximum, Func<object, object> conversion) { if (minimum.CompareTo(maximum) > 0) { throw new InvalidOperationException(String.Format(CultureInfo.CurrentCulture, DataAnnotationsResources.RangeAttribute_MinGreaterThanMax, maximum, minimum)); } this.Minimum = minimum; this.Maximum = maximum; this.Conversion = conversion; }
/// <summary> /// public find function /// </summary> public object find(IComparable key) { Node x = _root; while (x != _nill) { int cmp = key.CompareTo(x.Key); if (cmp == 0) return x.Value; else if (cmp < 0) x = x.Left; else if (cmp > 0) x = x.Right; } return null; }
/// <summary> /// Compare two objects. /// </summary> /// <remarks>This function correctly handlers null references.</remarks> /// <param name="obj1">First object.</param> /// <param name="obj2">Second object.</param> /// <returns>Comparison result.</returns> private static int CompareObjects(IComparable obj1, IComparable obj2) { if (obj1 == null && obj2 == null) return 0; else if (obj1 == null) return -1; else if (obj2 == null) return +1; else return obj1.CompareTo(obj2); }
public KeyValuePair<RecordKey, RecordData> FindNext(IComparable<RecordKey> keytest, bool equal_ok) { var rangekey = new ScanRange<RecordKey>(keytest, new ScanRange<RecordKey>.maxKey(), null); foreach (var rec in this.scanForward(rangekey)) { if (!equal_ok && keytest.CompareTo(rec.Key) == 0) { continue; } return rec; } throw new KeyNotFoundException("SubSetStage.FindNext: no record found after: " + keytest + " equal_ok:" + equal_ok); }
private void reheapUp(IComparable item) { int hole = lastIndex; while (hole > 0 && item.CompareTo(elements[(hole - 1)/2]) > 0) { elements[hole] = elements[(hole - 1)/2] ; // move hole into its parent hole = (hole - 1)/2; // move hole up } elements[hole] = item; }
public InclusiveBetweenValidator(IComparable from, IComparable to) : base(() => Messages.inclusivebetween_error) { To = to; From = from; if (to.CompareTo(from) == -1) { throw new ArgumentOutOfRangeException("to", "To should be larger than from."); } SupportsStandaloneValidation = true; }
public override void insert(IComparable item) { var newNode = new ListNode {info = item}; if (list == null) //insert into an empty list { list = newNode; // first node newNode.next = newNode; // circular refernce } else { var prevLocation = new ListNode(); var location = new ListNode(); bool moreToSearch = true; location = list.next; // first element since list points to last element prevLocation = list; //last element //find insertion point while (moreToSearch) { if (item.CompareTo(location.info) < 0) //list element is larger than item moreToSearch = false; else { prevLocation = location; // make sure prev is one location behind location = location.next; // move ahead moreToSearch = (location != list.next); // make sure we havent reached the end.. ie completed the circle } } newNode.next = location; //Insert node into list prevLocation.next = newNode; //maintain circular reference if (item.CompareTo(list.info) > 0) // new item is last on this list list = newNode; //make sure list points to last node.. ALWAYS } numItems++; }
private void Initialize(IComparable minimum, IComparable maximum, Func<object, object> conversion) { if (minimum.CompareTo(maximum) > 0) { throw new ArgumentOutOfRangeException("maximum", maximum, string.Format(CultureInfo.CurrentCulture, "the minimum vallue {1} is higher then the maximum value {0}", minimum, maximum)); } valueMinimum = minimum; valueMaximum = maximum; valueConversion = conversion; }
//MAX HEAP protected override void reheapUp(IComparable item) { int hole = lastIndex; // initial insertion location.. always insert at last location while (hole > 0 && item.CompareTo(elements[(hole - 1)/2]) > 0) // if hole is not the root and item is greater than its parent value { elements[hole] = elements[(hole - 1)/2]; // move parent to hole hole = (hole - 1)/2; // move hole up } elements[hole] = item; // place item into final hole. }
public void Add( IComparable o ) { // PercolateUp int hole = ++m_Size; // Grow the list if needed while ( m_List.Count <= m_Size ) m_List.Add( null ); for( ; hole > 1 && o.CompareTo( m_List[ hole / 2 ] ) < 0; hole /= 2 ) m_List[ hole ] = m_List[ hole / 2 ]; m_List[ hole ] = o; }
/// <summary> /// Compare the actual values /// </summary> /// <param name="x"></param> /// <param name="y"></param> /// <returns></returns> public int CompareValues(object x, object y) { // Force case insensitive compares on strings string xStr = x as string; if (xStr != null) { return(string.Compare(xStr, (string)y, StringComparison.CurrentCultureIgnoreCase)); } else { IComparable comparable = x as IComparable; return(comparable?.CompareTo(y) ?? 0); } }
protected int Compare(IComparable lhs, IComparable rhs) { if (lhs == null || rhs == null) { return(lhs?.CompareTo(rhs) ?? (-1 * rhs?.CompareTo(lhs) ?? 0)); } if (TypeConverter.IsNumeric(lhs) && TypeConverter.IsNumeric(rhs)) { lhs = (decimal)TypeConverter.To(lhs, typeof(decimal)); rhs = (decimal)TypeConverter.To(rhs, typeof(decimal)); } if (!Equals(lhs.GetType(), rhs.GetType())) { throw ComparisionException.UnComparable(lhs.GetType(), rhs.GetType()).Decorate(Token); } return(lhs.CompareTo(rhs)); }
public static TSource MaxElement <TSource>(this IEnumerable <TSource> src, Func <TSource, IComparable> selector) { TSource maxItem; IEnumerable <TSource> remaining = src.Extract(out maxItem); IComparable maxValue = selector(maxItem); foreach (TSource item in remaining) { IComparable value = selector(item); if (value?.CompareTo(maxValue) != 1) { continue; } maxItem = item; maxValue = value; } return(maxItem); }
public AVL agregar(IComparable elem) { // si elem es mayor que el dato almacenado en la raiz if (((AVL)elem).CompareTo(this) > 0) { // si el hijo derecho esta vacio, insero elem en ese lugar if (this.getHijoDerecho() == null) { this.agregarHijoDerecho((AVL)elem); } else { // si el arbol derecho NO esta vacio, llamo recursivamente a agregar() AVL nuevoHijoDerecho = this.getHijoDerecho().agregar(elem); this.agregarHijoDerecho(nuevoHijoDerecho); } } // si elem es menor o igual que el dato almacenado en la raiz else { // idem anterior en hijo izquierdo if (this.getHijoIzquierdo() == null) { this.agregarHijoIzquierdo((AVL)elem); } else { AVL nuevoHijoIzquierdo = this.getHijoIzquierdo().agregar(elem); this.agregarHijoIzquierdo(nuevoHijoIzquierdo); } } // actualizar altura this.actualizarAltura(); // control de desbalance AVL nuevaRaiz = this; int balance = this.calcularDesbalance(); if (balance >= 2) // desbalance del lado derecho { // si elem es mayor que hijo derecho, entonces rotacion simple con derecho if (elem.CompareTo(this.getHijoDerecho()) > 0) { nuevaRaiz = this.rotacionSimpleDerecha(); } // si elem es menor o igual, entonces rotacion doble con derecho else { nuevaRaiz = this.rotacionDobleDerecha(); } } if (balance <= -2) // desbalance del lado izquierdo { // si elem es menor que hijo izquierdo, entonces rotacion simple con izquierdo if (elem.CompareTo(this.getHijoIzquierdo()) <= 0) { nuevaRaiz = this.rotacionSimpleIzquierda(); } // si elem es mayor, entonces rotacion doble con izquierdo else { nuevaRaiz = this.rotacionDobleIzquierda(); } } return(nuevaRaiz); }
private int SelectSubNode(IComparable key) { return((key.CompareTo(this.key) < 0) ? LESS : GREATER); }
public static void TestCompareToObjectInvalid() { IComparable comparable = (float)234; Assert.Throws <ArgumentException>(null, () => comparable.CompareTo("a")); //Obj is not a float }
public int CompareTo(FieldValue f) { return(value.CompareTo(f.value)); }
private static IComparable Min2(IComparable a, IComparable b) { return(a.CompareTo(b) < 0 ? a : b); }
public object this[IComparable key] { get { return(GetData(key)); } set { if (key == null) { throw new ArgumentNullException("Key is null"); } // traverse tree - find where node belongs int result = 0; // create new node OrderedTreeNode node = new OrderedTreeNode(); OrderedTreeNode temp = rbTree; // grab the rbTree node of the tree while (temp != SentinelNode) { // find Parent node.Parent = temp; result = key.CompareTo(temp.Key); if (result == 0) { lastNodeFound = temp; temp.Data = value; return; } if (result > 0) { temp = temp.Right; } else { temp = temp.Left; } } // setup node node.Key = key; node.Data = value; node.Left = SentinelNode; node.Right = SentinelNode; // insert node into tree starting at parent's location if (node.Parent != null) { result = node.Key.CompareTo(node.Parent.Key); if (result > 0) { node.Parent.Right = node; } else { node.Parent.Left = node; } } else { rbTree = node; // first node added } RestoreAfterInsert(node); // restore red-black properities lastNodeFound = node; intCount = intCount + 1; } }
/// <summary> /// 判断当前值是否介于指定范围内 /// </summary> /// <typeparam name="T"> 动态类型 </typeparam> /// <param name="value"> 动态类型对象 </param> /// <param name="start"> 范围起点 </param> /// <param name="end"> 范围终点 </param> /// <param name="leftEqual"> 是否可等于上限(默认等于) </param> /// <param name="rightEqual"> 是否可等于下限(默认等于) </param> /// <returns> 是否介于 </returns> public static bool IsBetween <T>(this IComparable <T> value, T start, T end, bool leftEqual = false, bool rightEqual = false) where T : IComparable { bool flag = leftEqual ? value.CompareTo(start) >= 0 : value.CompareTo(start) > 0; return(flag && (rightEqual ? value.CompareTo(end) <= 0 : value.CompareTo(end) < 0)); }
public int Compare(T x, T y) { Type type = typeof(T); // Null? if (!type.IsValueType() || (type.IsGenericType() && type.GetGenericTypeDefinition().IsAssignableFrom(typeof(Nullable <>)))) { if (Equals(x, default(T))) { return(Equals(y, default(T)) ? 0 : 1); } if (Equals(y, default(T))) { return(-1); } } var xIsAssignableFromY = x.GetType().IsAssignableFrom(y.GetType()); var yIsAssignableFromX = y.GetType().IsAssignableFrom(x.GetType()); if (!xIsAssignableFromY && !yIsAssignableFromX) { throw new InvalidOperationException(string.Format("Cannot compare objects of type {0} and {1} because neither is assignable from the other.", x.GetType().Name, y.GetType().Name)); } // x Implements IComparable<T>? IComparable <T> comparable1 = x as IComparable <T>; if (comparable1 != null && xIsAssignableFromY) { return(comparable1.CompareTo(y)); } // y Implements IComparable<T>? IComparable <T> comparable2 = y as IComparable <T>; if (comparable2 != null && yIsAssignableFromX) { return(comparable2.CompareTo(x) * -1); } // x Implements IComparable? IComparable comparable3 = x as IComparable; if (comparable3 != null && xIsAssignableFromY) { return(comparable3.CompareTo(y)); } // y Implements IComparable? IComparable comparable4 = y as IComparable; if (comparable4 != null && yIsAssignableFromX) { return(comparable4.CompareTo(x) * -1); } if (new AssertEqualityComparer <T>().Equals(x, y)) { return(0); } if (xIsAssignableFromY) { var result = CompareUsingOperators(x, y, x.GetType()); if (result.HasValue) { return(result.Value); } } if (yIsAssignableFromX) { var result = CompareUsingOperators(x, y, y.GetType()); if (result.HasValue) { return(result.Value); } } throw new InvalidOperationException(string.Format("Cannot compare objects of type {0} and {1} because neither implements IComparable or IComparable<T> nor overloads comparaison operators.", x.GetType().Name, y.GetType().Name)); }
protected override bool CompareTo(IComparable value, IComparable other) { return(value.CompareTo(other) > 0); }
protected void Veriler(int Baslangic, int Bitis, string s, string Kolon, string AscDesc, out IList Sonuc1, out IList Sonuc2) { #region Çalışan Hali using (BaglantiCumlesi db = new BaglantiCumlesi()) { try { #region Kolon Sorting Ayarı string KolonAdi = null; switch (Kolon) { #region Admin case "ekleyen": Kolon = "admin_id_ek"; KolonAdi = Kolon; break; #endregion #region İşlem case "guncelleyen": Kolon = "admin_id_gun"; KolonAdi = Kolon; break; #endregion } #endregion #region İlk SQL - SONUÇ 1 #region İlk (Ham) SQL var SQL0 = (db.tbl_kategoriler).AsEnumerable(); #region Dil ID Geldiyse int DilID = int.Parse(ComboBoxDil.SelectedItem.Value); if (DilID > -1) { SQL0 = SQL0.Where(p => p.dil_id == DilID); } #endregion var SQL1 = (from p in SQL0 select new { p.resim, p.dil_id, p.kategori_tip, p.sira, p.id, p.ad, p.kategori_id, p.tarih_ek, p.tarih_gun, p.admin_id_ek, p.admin_id_gun, p.onay }).AsQueryable(); #endregion #region SQL i Cache 'e Atma //CachedQueryOptions CQO = new CachedQueryOptions(); var SQL2 = (CacheOlayi ? SQL1.AsCached(SayfaAdi).AsQueryable().OrderBy(Kolon + " " + AscDesc).ToList() : SQL1.AsQueryable().OrderBy(Kolon + " " + AscDesc).ToList()); #endregion #region Sonuç 1 Sonuc1 = SQL2; #endregion #endregion #region İlk SQL in Ccount ı Sıfırdan Büyükse Filtreleme Yap if (SQL2.Any()) { #region Filtreleme if (!string.IsNullOrEmpty(s)) { FilterConditions FC = new FilterConditions(s); foreach (FilterCondition FCO in FC.Conditions) { Comparison C = FCO.Comparison; FilterType FT = FCO.FilterType; #region Kolon Adı Boşsa Değer Ver if (string.IsNullOrEmpty(KolonAdi)) { KolonAdi = FCO.Name; } #endregion #region Gelen Değerler object value; #endregion switch (FCO.FilterType) { #region Filtre Tipi Bool İse case FilterType.Boolean: value = FCO.ValueAsBoolean; break; #endregion #region Filtre Tipi Date İse case FilterType.Date: value = FCO.ValueAsDate; break; #endregion #region Filtre Tipi Liste İse case FilterType.List: value = FCO.ValuesList; break; #endregion #region Filtre Tipi Nümerik İse case FilterType.Numeric: if (SQL2.Any() && (SQL2[0].GetType().GetProperty(KolonAdi).PropertyType == typeof(int) || SQL2[0].GetType().GetProperty(KolonAdi).PropertyType == typeof(Int16) || SQL2[0].GetType().GetProperty(KolonAdi).PropertyType == typeof(Int32) || SQL2[0].GetType().GetProperty(KolonAdi).PropertyType == typeof(Int64) || SQL2[0].GetType().GetProperty(KolonAdi).PropertyType == typeof(Nullable <int>) || SQL2[0].GetType().GetProperty(KolonAdi).PropertyType == typeof(Nullable <Int16>) || SQL2[0].GetType().GetProperty(KolonAdi).PropertyType == typeof(Nullable <Int32>) || SQL2[0].GetType().GetProperty(KolonAdi).PropertyType == typeof(Nullable <Int64>))) { value = FCO.ValueAsInt; } else { value = FCO.ValueAsDouble; } break; #endregion #region Filtre Tipi String İse case FilterType.String: value = FCO.Value; break; #endregion #region Switch Default default: throw new ArgumentOutOfRangeException(); #endregion } SQL2.RemoveAll(i => { object o = i.GetType().GetProperty(KolonAdi).GetValue(i, null); IComparable IC = o as IComparable; switch (C) { case Comparison.Eq: switch (FT) { #region Filtre Tipi Liste İse case FilterType.List: return(!(value as ReadOnlyCollection <string>).Contains(o.ToString())); #endregion #region Filtre Tipi String İse case FilterType.String: return(!o.ToString().StartsWith(value.ToString())); #endregion #region Switch Default default: return(!IC.Equals(value)); #endregion } case Comparison.Gt: return(IC.CompareTo(value) < 1); case Comparison.Lt: return(IC.CompareTo(value) > -1); #region Switch Default default: throw new ArgumentOutOfRangeException(); #endregion } }); } } #endregion } #endregion #region SQL İçeriğini Değiştirme var SQL3 = SQL2.Skip(Baslangic).Take(Bitis).Select(p => new { p.resim, p.dil_id, p.sira, p.id, kategori_tip = AdminClass.EvetHayir(p.kategori_tip), p.ad, p.kategori_id, p.tarih_ek, p.tarih_gun, p.admin_id_ek, p.admin_id_gun, ziyaret = db.tbl_ziyaretler.Where(k => k.kategori_id == p.id).Count(), ekleyen = AdminClass.Admin(p.admin_id_ek), guncelleyen = AdminClass.Admin(p.admin_id_gun), ust_kategori = db.tbl_kategoriler.Where(k => k.id == p.kategori_id).Select(x => x.ad).FirstOrDefault(), dil = AdminClass.Dil(p.dil_id), onay = AdminClass.EvetHayir(p.onay) }).AsEnumerable().Cast <object>().ToList(); #endregion #region Sonuç 2 Sonuc2 = SQL3; #endregion } catch { #region Boş Değer Döndür Sonuc1 = null; Sonuc2 = null; #endregion } } #endregion }
protected void Veriler(int Baslangic, int Bitis, string s, string Kolon, string AscDesc, out IList Sonuc1, out IList Sonuc2) { #region İşlem Dictionary Dictionary <int, string> D = new Dictionary <int, string>(); D.Add(0, "ÜRÜN"); D.Add(1, "KATEGORİ"); D.Add(2, "ETİKET"); D.Add(3, "MARKA"); #endregion #region Çalışan Hali using (BaglantiCumlesi SME = new BaglantiCumlesi()) { try { #region Kolon Sorting Ayarı string KolonAdi = null; switch (Kolon) { #region İşlem case "tips": Kolon = "tip"; KolonAdi = Kolon; break; #endregion } #endregion #region İlk SQL - SONUÇ 1 #region İlk (Ham) SQL var SQL1 = (from p in SME.tbl_ziyaretler where p.urun_id != null || p.kategori_id != null || p.etiket_id != null || p.marka_id != null select p); #endregion #region SQL i Cache 'e Atma //CachedQueryOptions CQO = new CachedQueryOptions(); var SQL2 = (CacheOlayi ? SQL1.AsCached(SayfaAdi).AsQueryable().OrderBy(Kolon + " " + AscDesc).ToList() : SQL1.AsQueryable().OrderBy(Kolon + " " + AscDesc).ToList()); #endregion #region Sonuç 1 Sonuc1 = SQL2; #endregion #endregion #region İlk SQL in Ccount ı Sıfırdan Büyükse Filtreleme Yap if (SQL2.Count() > 0) { #region Filtreleme if (!string.IsNullOrEmpty(s)) { FilterConditions FC = new FilterConditions(s); foreach (FilterCondition FCO in FC.Conditions) { Comparison C = FCO.Comparison; FilterType FT = FCO.FilterType; #region Kolon Adı Boşsa Değer Ver if (string.IsNullOrEmpty(KolonAdi)) { KolonAdi = FCO.Name; } #endregion #region Gelen Değerler object value; #endregion switch (FCO.FilterType) { #region Filtre Tipi Bool İse case FilterType.Boolean: value = FCO.ValueAsBoolean; break; #endregion #region Filtre Tipi Date İse case FilterType.Date: value = FCO.ValueAsDate; break; #endregion #region Filtre Tipi Liste İse case FilterType.List: value = FCO.ValuesList; break; #endregion #region Filtre Tipi Nümerik İse case FilterType.Numeric: if (SQL2.Count() > 0 && (SQL2[0].GetType().GetProperty(KolonAdi).PropertyType == typeof(int) || SQL2[0].GetType().GetProperty(KolonAdi).PropertyType == typeof(Int16) || SQL2[0].GetType().GetProperty(KolonAdi).PropertyType == typeof(Int32) || SQL2[0].GetType().GetProperty(KolonAdi).PropertyType == typeof(Int64) || SQL2[0].GetType().GetProperty(KolonAdi).PropertyType == typeof(Nullable <int>) || SQL2[0].GetType().GetProperty(KolonAdi).PropertyType == typeof(Nullable <Int16>) || SQL2[0].GetType().GetProperty(KolonAdi).PropertyType == typeof(Nullable <Int32>) || SQL2[0].GetType().GetProperty(KolonAdi).PropertyType == typeof(Nullable <Int64>))) { value = FCO.ValueAsInt; } else { value = FCO.ValueAsDouble; } break; #endregion #region Filtre Tipi String İse case FilterType.String: value = FCO.Value; break; #endregion #region Switch Default default: throw new ArgumentOutOfRangeException(); #endregion } SQL2.RemoveAll(item => { object o = item.GetType().GetProperty(KolonAdi).GetValue(item, null); IComparable IC = o as IComparable; switch (C) { case Comparison.Eq: switch (FT) { #region Filtre Tipi Liste İse case FilterType.List: return(!(value as ReadOnlyCollection <string>).Contains(o.ToString())); #endregion #region Filtre Tipi String İse case FilterType.String: return(!o.ToString().StartsWith(value.ToString())); #endregion #region Switch Default default: return(!IC.Equals(value)); #endregion } case Comparison.Gt: return(IC.CompareTo(value) < 1); case Comparison.Lt: return(IC.CompareTo(value) > -1); #region Switch Default default: throw new ArgumentOutOfRangeException(); #endregion } }); } } #endregion } #endregion #region SQL İçeriğini Değiştirme var SQL3 = SQL2.Skip(Baslangic).Take(Bitis).Select(p => new { p.id, p.urun_id, p.kategori_id, p.etiket_id, p.tarih, p.marka_id, p.tip, #region İşlem Tipi tips = D.Where(x => x.Key == p.tip).Select(x => x.Value).FirstOrDefault(), #endregion urun_dil = (p.urun_id != null ? SME.tbl_urunler.Where(k => k.id == p.urun_id).Select(x => (x.dil_id != null ? SME.tbl_diller.Where(t => t.id == x.dil_id).Select(y => y.dil).FirstOrDefault() : null)).FirstOrDefault() : "------"), urun = (p.urun_id != null ? SME.tbl_urunler.Where(k => k.id == p.urun_id).Select(x => (x.kod_id != null ? SME.tbl_kodlar.Where(t => t.id == x.kod_id).Select(y => y.kod).FirstOrDefault() + " - " : "") + x.ad).FirstOrDefault() : "------"), kategori_dil = (p.kategori_id != null ? SME.tbl_kategoriler.Where(k => k.id == p.kategori_id).Select(x => (x.dil_id != null ? SME.tbl_diller.Where(t => t.id == x.dil_id).Select(y => y.dil).FirstOrDefault() : null)).FirstOrDefault() : "------"), kategori = (p.kategori_id != null ? SME.tbl_kategoriler.Where(k => k.id == p.kategori_id).Select(x => x.ad).FirstOrDefault() : "------"), etiket_dil = (p.etiket_id != null ? SME.tbl_etiketler.Where(k => k.id == p.etiket_id).Select(x => (x.dil_id != null ? SME.tbl_diller.Where(t => t.id == x.dil_id).Select(y => y.dil).FirstOrDefault() : null)).FirstOrDefault() : "------"), etiket = (p.etiket_id != null ? SME.tbl_etiketler.Where(k => k.id == p.etiket_id).Select(x => x.ad).FirstOrDefault() : "------"), marka = (p.marka_id != null ? SME.tbl_markalar.Where(k => k.id == p.marka_id).Select(x => x.ad).FirstOrDefault() : "------"), }).AsEnumerable().Cast <object>().ToList(); #endregion #region Sonuç 2 Sonuc2 = SQL3; #endregion } catch { #region Boş Değer Döndür Sonuc1 = null; Sonuc2 = null; #endregion } } #endregion }
public override bool IsValid(IComparable value, IComparable valueToCompare) { return(value.CompareTo(valueToCompare) >= 0); }
public void CompareTo_Null() { IComparable minValue = SpannerNumeric.MinValue; Assert.InRange(minValue.CompareTo(null), 1, int.MaxValue); }
public int Compare(SortKey x, SortKey y) { int c = 0; if (x == null && y == null) { c = 0; } else if (x == null) { c = -1; } else if (y == null) { c = 1; } else { if (x.Value == null && y.Value == null) { c = 0; } else if (x.Value == null) { c = -1; } else if (y.Value == null) { c = 1; } else if (!(x.Value is int && y.Value is int)) { c = 0; } else if (x.Value.GetType() != y.Value.GetType()) { IComparable o = Convert.ChangeType(y.Value, x.Value.GetType()) as IComparable; if (o != null) { c = x.Value.CompareTo(o); } else { o = Convert.ChangeType(x.Value, y.Value.GetType()) as IComparable; c = o.CompareTo(y.Value); } } else { c = x.Value.CompareTo(y.Value); } } if (c == 0) { c = x.GetHashCode().CompareTo(y.GetHashCode()); } if (sd == ListSortDirection.Descending) { c = -c; } return(c); }
public static IComparable ShouldBeGreaterThan(this IComparable arg1, IComparable arg2) { (arg1.CompareTo(arg2) > 0).ShouldBeTrue(); return(arg2); }
public bool less(IComparable v, IComparable w) { return(v.CompareTo(w) < 0); }
protected override bool IsValid(IComparable currentValue, object otherValue) { return(currentValue.CompareTo(otherValue) == 0); }
public int Compare(T x, T y) { // Compare against null if (Object.Equals(x, default(T))) { if (Object.Equals(y, default(T))) { return(0); } return(-1); } if (Object.Equals(y, default(T))) { return(-1); } // Are they the same type? if (x.GetType() != y.GetType()) { return(-1); } // Are they arrays? if (x.GetType().IsArray) { Array arrayX = x as Array; Array arrayY = y as Array; if (arrayX != null && arrayY != null) { if (arrayX.Rank != 1) { throw new ArgumentException("Multi-dimension array comparison is not supported"); } if (arrayX.Length != arrayY.Length) { return(-1); } for (int index = 0; index < arrayX.Length; index++) { if (!Object.Equals(arrayX.GetValue(index), arrayY.GetValue(index))) { return(-1); } } } return(0); } // Compare with IComparable<T> IComparable <T> comparable1 = x as IComparable <T>; if (comparable1 != null) { return(comparable1.CompareTo(y)); } // Compare with IComparable IComparable comparable2 = x as IComparable; if (comparable2 != null) { return(comparable2.CompareTo(y)); } // Compare with IEquatable IEquatable <T> equatable1 = x as IEquatable <T>; if (equatable1 != null && equatable1.Equals(y)) { return(0); } // Last case, rely on Object.AreEquals return(Object.Equals(x, y) ? 0 : -1); }
private bool Less(IComparable a, IComparable b) { return(a.CompareTo(b) <= -1); }
public static bool Between(this IComparable date, IComparable startDate, IComparable Enddate) { return(date.CompareTo(startDate) >= 0 && date.CompareTo(Enddate) <= 0); }
public int CompareTo(byte[] other) { return(_wrapped.CompareTo(Convert <K>(other))); }
public override bool CompareTo(IComparable value, object toCompare) { return(value.CompareTo(toCompare) >= 0); }
private static bool IsLess(IComparable v, IComparable w) { return(v.CompareTo(w) < 0); }
/// <summary> /// Determines whether the specified value is valid. /// </summary> /// <param name="value">The value.</param> /// <param name="field">The field.</param> /// <param name="summary">The summary.</param> /// <returns></returns> public override bool IsValid(object value, string field, ref ValidationSummary summary) { if (value == null) { return(false); } if (!(value is IComparable)) { return(false); } IComparable toValidate = (IComparable)value; bool isValid = true; string message = string.Empty; switch (_restriction) { case Restriction.Less: if (toValidate.CompareTo(_value) >= 0) { isValid = false; message = Resources.NumberValidatorLess; } break; case Restriction.LessOrEqual: if (toValidate.CompareTo(_value) > 0) { isValid = false; message = Resources.NumberValidatorLessEqual; } break; case Restriction.Equal: if (toValidate.CompareTo(_value) != 0) { isValid = false; message = Resources.NumberValidatorEqual; } break; case Restriction.Greater: if (toValidate.CompareTo(_value) <= 0) { isValid = false; message = Resources.NumberValidatorGreater; } break; case Restriction.GreaterOrEqual: if (toValidate.CompareTo(_value) < 0) { isValid = false; message = Resources.NumberValidatorGreaterEqual; } break; } if (isValid == false) { ValidationEntry ve = new ValidationEntry(false, String.Format(message, new[] { field, _value }), field, _value); summary.Add(ve); } return(isValid); }
/// <summary> /// Compares two elements to determine their positions within the tree. /// </summary> public static int CompareElements(IComparable x, IComparable y) { return(x.CompareTo(y)); }