Visual Basic (Declaration) | |
---|---|
Public Function New( _ ByVal comparer As IComparer(Of TKey), _ ByVal unordered As IEnumerable(Of KeyValuePair(Of TKey,TValue)), _ ByVal serializer As ISerializer(Of KeyValuePair(Of TKey,TValue)) _ ) |
C# | |
---|---|
public OrderedKeyValuePairs<TKey,TValue>( IComparer<TKey> comparer, IEnumerable<KeyValuePair<TKey,TValue>> unordered, ISerializer<KeyValuePair<TKey,TValue>> serializer ) |
Parameters
- comparer
- unordered
- serializer
Library/Library.Test/TestOrderedEnumeration.cs
C# | Copy Code |
---|---|
IEnumerable<KeyValuePair<int,int>> e = new KeyValuePair<int,int>[0]; OrderedKeyValuePairs<int, int> ordered; ordered = new OrderedKeyValuePairs<int, int>(e); Assert.IsTrue(ordered.Comparer is KeyValueComparer<int, int>); Assert.IsTrue(ReferenceEquals(Comparer<int>.Default, ((KeyValueComparer<int, int>)ordered.Comparer).Comparer)); Assert.AreEqual(DuplicateHandling.None, ordered.DuplicateHandling); Assert.AreEqual(0x10000, ordered.InMemoryLimit); Assert.AreEqual(null, ordered.Serializer); ordered = new OrderedKeyValuePairs<int, int>(new ReverseOrder<int>(Comparer<int>.Default), e); Assert.IsTrue(ordered.Comparer is KeyValueComparer<int, int>); Assert.IsTrue(((KeyValueComparer<int, int>)ordered.Comparer).Comparer is ReverseOrder<int>); Assert.AreEqual(DuplicateHandling.None, ordered.DuplicateHandling); Assert.AreEqual(0x10000, ordered.InMemoryLimit); Assert.AreEqual(null, ordered.Serializer); KeyValueSerializer<int,int> ser = new KeyValueSerializer<int,int>(PrimitiveSerializer.Int32, PrimitiveSerializer.Int32); ordered = new OrderedKeyValuePairs<int, int>(new ReverseOrder<int>(Comparer<int>.Default), e, ser); Assert.IsTrue(ordered.Comparer is KeyValueComparer<int, int>); Assert.IsTrue(((KeyValueComparer<int, int>)ordered.Comparer).Comparer is ReverseOrder<int>); Assert.AreEqual(DuplicateHandling.None, ordered.DuplicateHandling); Assert.AreEqual(0x10000, ordered.InMemoryLimit); Assert.AreEqual(ser, ordered.Serializer); ordered = new OrderedKeyValuePairs<int, int>(new ReverseOrder<int>(Comparer<int>.Default), e, ser, 42); Assert.IsTrue(ordered.Comparer is KeyValueComparer<int, int>); Assert.IsTrue(((KeyValueComparer<int, int>)ordered.Comparer).Comparer is ReverseOrder<int>); Assert.AreEqual(DuplicateHandling.None, ordered.DuplicateHandling); Assert.AreEqual(42, ordered.InMemoryLimit); Assert.AreEqual(ser, ordered.Serializer); ordered = new OrderedKeyValuePairs<int, int>(new ReverseOrder<int>(Comparer<int>.Default), e, PrimitiveSerializer.Int32, PrimitiveSerializer.Int32); Assert.IsTrue(ordered.Comparer is KeyValueComparer<int, int>); Assert.IsTrue(((KeyValueComparer<int, int>)ordered.Comparer).Comparer is ReverseOrder<int>); Assert.AreEqual(DuplicateHandling.None, ordered.DuplicateHandling); Assert.AreEqual(0x10000, ordered.InMemoryLimit); Assert.IsNotNull(ordered.Serializer); ordered = new OrderedKeyValuePairs<int, int>(new ReverseOrder<int>(Comparer<int>.Default), e, PrimitiveSerializer.Int32, PrimitiveSerializer.Int32, 42); Assert.IsTrue(ordered.Comparer is KeyValueComparer<int, int>); Assert.IsTrue(((KeyValueComparer<int, int>)ordered.Comparer).Comparer is ReverseOrder<int>); Assert.AreEqual(DuplicateHandling.None, ordered.DuplicateHandling); Assert.AreEqual(42, ordered.InMemoryLimit); Assert.IsNotNull(ordered.Serializer); |
VB.NET | Copy Code |
---|---|
Dim e As IEnumerable(Of KeyValuePair(Of Integer, Integer)) = New KeyValuePair(Of Integer, Integer)(0) {} Dim ordered As OrderedKeyValuePairs(Of Integer, Integer) ordered = New OrderedKeyValuePairs(Of Integer, Integer)(e) Assert.IsTrue(TypeOf ordered.Comparer Is KeyValueComparer(Of Integer, Integer)) Assert.IsTrue(ReferenceEquals(Comparer(Of Integer).[Default], (DirectCast(ordered.Comparer, KeyValueComparer(Of Integer, Integer))).Comparer)) Assert.AreEqual(DuplicateHandling.None, ordered.DuplicateHandling) Assert.AreEqual(&H10000, ordered.InMemoryLimit) Assert.AreEqual(Nothing, ordered.Serializer) ordered = New OrderedKeyValuePairs(Of Integer, Integer)(New ReverseOrder(Of Integer)(Comparer(Of Integer).[Default]), e) Assert.IsTrue(TypeOf ordered.Comparer Is KeyValueComparer(Of Integer, Integer)) Assert.IsTrue(TypeOf (DirectCast(ordered.Comparer, KeyValueComparer(Of Integer, Integer))).Comparer Is ReverseOrder(Of Integer)) Assert.AreEqual(DuplicateHandling.None, ordered.DuplicateHandling) Assert.AreEqual(&H10000, ordered.InMemoryLimit) Assert.AreEqual(Nothing, ordered.Serializer) Dim ser As New KeyValueSerializer(Of Integer, Integer)(PrimitiveSerializer.Int32, PrimitiveSerializer.Int32) ordered = New OrderedKeyValuePairs(Of Integer, Integer)(New ReverseOrder(Of Integer)(Comparer(Of Integer).[Default]), e, ser) Assert.IsTrue(TypeOf ordered.Comparer Is KeyValueComparer(Of Integer, Integer)) Assert.IsTrue(TypeOf (DirectCast(ordered.Comparer, KeyValueComparer(Of Integer, Integer))).Comparer Is ReverseOrder(Of Integer)) Assert.AreEqual(DuplicateHandling.None, ordered.DuplicateHandling) Assert.AreEqual(&H10000, ordered.InMemoryLimit) Assert.AreEqual(ser, ordered.Serializer) ordered = New OrderedKeyValuePairs(Of Integer, Integer)(New ReverseOrder(Of Integer)(Comparer(Of Integer).[Default]), e, ser, 42) Assert.IsTrue(TypeOf ordered.Comparer Is KeyValueComparer(Of Integer, Integer)) Assert.IsTrue(TypeOf (DirectCast(ordered.Comparer, KeyValueComparer(Of Integer, Integer))).Comparer Is ReverseOrder(Of Integer)) Assert.AreEqual(DuplicateHandling.None, ordered.DuplicateHandling) Assert.AreEqual(42, ordered.InMemoryLimit) Assert.AreEqual(ser, ordered.Serializer) ordered = New OrderedKeyValuePairs(Of Integer, Integer)(New ReverseOrder(Of Integer)(Comparer(Of Integer).[Default]), e, PrimitiveSerializer.Int32, PrimitiveSerializer.Int32) Assert.IsTrue(TypeOf ordered.Comparer Is KeyValueComparer(Of Integer, Integer)) Assert.IsTrue(TypeOf (DirectCast(ordered.Comparer, KeyValueComparer(Of Integer, Integer))).Comparer Is ReverseOrder(Of Integer)) Assert.AreEqual(DuplicateHandling.None, ordered.DuplicateHandling) Assert.AreEqual(&H10000, ordered.InMemoryLimit) Assert.IsNotNull(ordered.Serializer) ordered = New OrderedKeyValuePairs(Of Integer, Integer)(New ReverseOrder(Of Integer)(Comparer(Of Integer).[Default]), e, PrimitiveSerializer.Int32, PrimitiveSerializer.Int32, 42) Assert.IsTrue(TypeOf ordered.Comparer Is KeyValueComparer(Of Integer, Integer)) Assert.IsTrue(TypeOf (DirectCast(ordered.Comparer, KeyValueComparer(Of Integer, Integer))).Comparer Is ReverseOrder(Of Integer)) Assert.AreEqual(DuplicateHandling.None, ordered.DuplicateHandling) Assert.AreEqual(42, ordered.InMemoryLimit) Assert.IsNotNull(ordered.Serializer) |
Target Platforms: Windows XP, Windows Server 2003, Windows Vista, Windows Server 2008, Windows 7