Example #1
0
    public int CompareTo(SpecialArray <T> other)
    {
        int minLength = Math.Min(InternalArray.Length, other.InternalArray.Length);

        for (int i = 0; i < minLength; i++)
        {
            int result = InternalArray[i].CompareTo(other.InternalArray[i]);
            if (result != 0)
            {
                return(result);
            }
        }
        return(0);
    }
        public void TestSpecialArrays()
        {
            ICollection<PortableTypeConfiguration> typeCfgs =
                new List<PortableTypeConfiguration>();

            typeCfgs.Add(new PortableTypeConfiguration(typeof(SpecialArray)));
            typeCfgs.Add(new PortableTypeConfiguration(typeof(SpecialArrayMarshalAware)));

            PortableConfiguration cfg = new PortableConfiguration();

            cfg.TypeConfigurations = typeCfgs;

            PortableMarshaller marsh = new PortableMarshaller(cfg);

            Guid[] guidArr = { Guid.NewGuid() };
            Guid?[] nGuidArr = { Guid.NewGuid() };
            DateTime[] dateArr = { DateTime.Now.ToUniversalTime() };
            DateTime?[] nDateArr = { DateTime.Now.ToUniversalTime() };

            // Use special object.
            SpecialArray obj1 = new SpecialArray();

            obj1.GuidArr = guidArr;
            obj1.NGuidArr = nGuidArr;
            obj1.DateArr = dateArr;
            obj1.NDateArr = nDateArr;

            byte[] bytes = marsh.Marshal(obj1);

            IPortableObject portObj = marsh.Unmarshal<IPortableObject>(bytes, PortableMode.ForcePortable);

            Assert.AreEqual(guidArr, portObj.Field<Guid[]>("guidArr"));
            Assert.AreEqual(nGuidArr, portObj.Field<Guid?[]>("nGuidArr"));
            Assert.AreEqual(dateArr, portObj.Field<DateTime[]>("dateArr"));
            Assert.AreEqual(nDateArr, portObj.Field<DateTime?[]>("nDateArr"));

            obj1 = portObj.Deserialize<SpecialArray>();

            Assert.AreEqual(guidArr, obj1.GuidArr);
            Assert.AreEqual(nGuidArr, obj1.NGuidArr);
            Assert.AreEqual(dateArr, obj1.DateArr);
            Assert.AreEqual(nDateArr, obj1.NDateArr);

            // Use special with IGridPortableMarshalAware.
            SpecialArrayMarshalAware obj2 = new SpecialArrayMarshalAware();

            obj2.GuidArr = guidArr;
            obj2.NGuidArr = nGuidArr;
            obj2.DateArr = dateArr;
            obj2.NDateArr = nDateArr;

            bytes = marsh.Marshal(obj2);

            portObj = marsh.Unmarshal<IPortableObject>(bytes, PortableMode.ForcePortable);

            Assert.AreEqual(guidArr, portObj.Field<Guid[]>("a"));
            Assert.AreEqual(nGuidArr, portObj.Field<Guid?[]>("b"));
            Assert.AreEqual(dateArr, portObj.Field<DateTime[]>("c"));
            Assert.AreEqual(nDateArr, portObj.Field<DateTime?[]>("d"));

            obj2 = portObj.Deserialize<SpecialArrayMarshalAware>();

            Assert.AreEqual(guidArr, obj2.GuidArr);
            Assert.AreEqual(nGuidArr, obj2.NGuidArr);
            Assert.AreEqual(dateArr, obj2.DateArr);
            Assert.AreEqual(nDateArr, obj2.NDateArr);
        }
 public static IEnumerable <T> Filter <T>(this SpecialArray <T> array)
 {
     // validate inputs
     // filter and validate logs in collection
     // in end, return filtered logs, as an enumerable
 }