コード例 #1
0
        public void GroupBy_ObservableSourceItemAdded_Update()
        {
            var update = false;
            ICollection <Dummy <string> > coll = new ObservableCollection <Dummy <string> >();

            var test = coll.WithUpdates().GroupBy(d => d.Item);

            test.CollectionChanged += (o, e) =>
            {
                Assert.IsTrue(ContainsGroup(e.NewItems, "42"));
                Assert.AreEqual(1, e.NewItems.Count);
                update = true;
            };

            Assert.IsTrue(!test.Any());
            Assert.IsFalse(update);

            coll.Add(new Dummy <string>()
            {
                Item = "42"
            });

            Assert.IsFalse(!test.Any());
            Assert.IsTrue(Sys.Any(test, group => group.Key == "42"));
            Assert.IsTrue(update);
        }
コード例 #2
0
        public void Where_ObservableSourceItemAdded_Updates()
        {
            var update = false;
            ICollection <Dummy <bool> > coll = new ObservableCollection <Dummy <bool> >();
            var dummy = new Dummy <bool>()
            {
                Item = true
            };

            var test = coll.WithUpdates().Where(d => d.Item);

            test.CollectionChanged += (o, e) =>
            {
                update = true;
                Assert.AreEqual(NotifyCollectionChangedAction.Add, e.Action);
                Assert.AreEqual(dummy, e.NewItems[0]);
            };

            Assert.IsFalse(Sys.Any(test));
            Assert.IsFalse(update);

            coll.Add(dummy);

            Assert.IsTrue(update);
            Assert.IsTrue(Sys.Contains(test, dummy));
        }
コード例 #3
0
ファイル: GroupByTest.cs プロジェクト: walcher/NMF
        public void GroupBy_ObservableSourceItemRemoved_Update()
        {
            var update = false;
            ICollection <Dummy <string> > coll = new ObservableCollection <Dummy <string> >();
            var dummy = new Dummy <string>("42");

            coll.Add(dummy);

            var test = coll.WithUpdates().GroupBy(d => d.Item);

            test.CollectionChanged += (o, e) =>
            {
                Assert.AreEqual(NotifyCollectionChangedAction.Remove, e.Action);
                Assert.IsTrue(ContainsGroup(e.OldItems, "42"));
                Assert.AreEqual(1, e.OldItems.Count);
                update = true;
            };

            Assert.IsTrue(Sys.Any(test, group => group.Key == "42"));
            Assert.IsFalse(update);

            coll.Remove(dummy);

            Assert.IsFalse(test.Any());
            Assert.IsTrue(update);
        }
コード例 #4
0
ファイル: Launch.cs プロジェクト: ULuIQ12/com.iris.common
        public static void OnPostprocessAllAssets(string[] importedAssets, string[] deletedAssets, string[] movedAssets, string[] movedFromAssetPaths)
        {
            if (Enumerable.Any(importedAssets, str => str.Contains(EditorUtil.EditorConstants.ASSET_UID.ToString())))
            {
                Common.EditorTask.SetupResources.Setup();
                SetupResources.Setup();

                EditorIntegration.ConfigWindow.ShowWindow(4);
            }
        }
コード例 #5
0
        public static void WriteEncodedString(this Stream stream, string value)
        {
            bool isUnicode = Enumerable.Any(value, t => t > 0xFF && t != '…');

            if (isUnicode == false)
            {
                value = value.Replace("…", "...");

                stream.WriteValueEncodedS32(-value.Length);
                stream.WriteString(value, _WindowsEncoding);
            }
            else
            {
                stream.WriteValueEncodedS32(value.Length);
                stream.WriteString(value, Encoding.Unicode);
            }
        }
コード例 #6
0
        public void GroupBy_NoObservableSourceItemRemoved_NoUpdates()
        {
            var update = false;
            ICollection <Dummy <string> > coll = new List <Dummy <string> >();
            var dummy = new Dummy <string>("42");

            coll.Add(dummy);

            var test = coll.WithUpdates().GroupBy(d => d.Item);

            test.CollectionChanged += (o, e) => update = true;

            Assert.IsTrue(Sys.Any(test, group => group.Key == "42"));
            Assert.IsFalse(update);

            coll.Remove(dummy);

            Assert.IsTrue(test.Any());
            Assert.IsFalse(update);
        }
コード例 #7
0
ファイル: ReflectionHelper.cs プロジェクト: mmvlad/ecs
        public static System.Reflection.MemberInfo[] GetCachedFields(this System.Type type,
                                                                     System.Reflection.BindingFlags flags =
                                                                     System.Reflection.BindingFlags.Instance |
                                                                     System.Reflection.BindingFlags.Public |
                                                                     System.Reflection.BindingFlags.NonPublic)
        {
            if (ReflectionHelper.fieldInfoCache.TryGetValue(type, out var fieldInfos) == false)
            {
                var fieldInfosArr = Enumerable.Cast <System.Reflection.MemberInfo>(Enumerable.Where(type.GetAllFields(flags), f =>
                                                                                                    f.IsPublic == true ||
                                                                                                    Enumerable.Any(f.CustomAttributes, a => a.AttributeType == typeof(ME.ECS.Serializer.SerializeFieldAttribute)) == true));
                fieldInfosArr = Enumerable.Union(fieldInfosArr, Enumerable.Where(type.GetAllProperties(flags), f =>
                                                                                 f.CanRead == true &&
                                                                                 f.CanWrite == true &&
                                                                                 Enumerable.Any(f.CustomAttributes, a => a.AttributeType == typeof(ME.ECS.Serializer.SerializeFieldAttribute))
                                                                                 )
                                                 );

                fieldInfos = Enumerable.ToArray(Enumerable.OrderBy(fieldInfosArr, x => x.Name));
                ReflectionHelper.fieldInfoCache.Add(type, fieldInfos);
            }

            return(fieldInfos);
        }
コード例 #8
0
ファイル: EquipmentFactory.cs プロジェクト: kitfka/AlleyCat
        protected override Validation <string, Equipment> CreateService(RigidBody node, ILoggerFactory loggerFactory)
        {
            var key         = Key.TrimToOption().IfNone(() => Name);
            var displayName = DisplayName.TrimToOption().Map(Tr).IfNone(key);
            var description = Description.TrimToOption().Map(Tr);

            return
                (from mesh in Mesh
                 .ToValidation("Failed to find the mesh instance.")
                 from colliders in Optional(Colliders).Filter(Enumerable.Any)
                 .ToValidation("Failed to find the collision shape.")
                 from itemMesh in Optional(ItemMesh)
                 .ToValidation("Failed to find the item mesh.")
                 from configurations in Optional(Configurations.Freeze()).Filter(c => Enumerable.Any(c))
                 .ToValidation("Failed to find equipment configuration.")
                 select new Equipment(
                     key,
                     displayName,
                     description,
                     EquipmentType,
                     configurations,
                     colliders,
                     mesh,
                     itemMesh,
                     Optional(Markers).Flatten(),
                     Morphs,
                     node,
                     loggerFactory));
        }
コード例 #9
0
        public void Deserialize(Stream input)
        {
            var header = input.ReadStructure <Level.Header>();

            this.Width  = header.Width;
            this.Height = header.Height;

            this.OffsetX = header.OffsetX;
            this.OffsetY = header.OffsetY;

            if (Enumerable.Any(header.Padding, t => t != 0) == true)
            {
                throw new FormatException("non-zero data in padding");
            }

            Array.Copy(header.TerrainIds, this.TerrainIds, header.TerrainIds.Length);
            for (int i = 0; i < this.TerrainIds.Length; i++)
            {
                this.TerrainIds[i] %= 16;
            }

            if (header.Version >= 4)
            {
                this.LightColorWhite = header.LightColorWhite;
                this.LightColorRed   = header.LightColorRed;
                this.LightColorGreen = header.LightColorGreen;
                this.LightColorBlue  = header.LightColorBlue;

                Array.Copy(header.PhysicsLow, this.PhysicsLow, header.PhysicsLow.Length);
                Array.Copy(header.PhysicsHigh, this.PhysicsHigh, header.PhysicsHigh.Length);
            }
            else
            {
                this.SetDefaults();
            }

            var objects = new Level.BlobReference[header.ObjectCount];

            for (int i = 0; i < objects.Length; i++)
            {
                if (header.Version >= 6)
                {
                    objects[i] = input.ReadStructure <Level.BlobReference>();
                }
                else
                {
                    objects[i] = new Level.BlobReference
                    {
                        FileName = null,
                        Id       = string.Format("o{0}.cfs", i),
                    };
                }
            }
            this.Objects = new List <Level.BlobReference>();
            this.Objects.AddRange(objects);

            var floors = new Level.BlobReference[header.FloorCount];

            for (int i = 0; i < floors.Length; i++)
            {
                if (header.Version >= 6)
                {
                    floors[i] = input.ReadStructure <Level.BlobReference>();
                }
                else
                {
                    floors[i] = new Level.BlobReference
                    {
                        FileName = null,
                        Id       = string.Format("f{0}.cfs", i),
                    };
                }
            }
            this.Floors = new List <Level.BlobReference>();
            this.Floors.AddRange(floors);

            this.Tiles = new Level.Tile[this.Width * this.Height];

            var tileData = input.ReadRLE(3, this.Tiles.Length, true);

            for (int i = 0, j = 0; i < this.Tiles.Length; i++, j += 3)
            {
                this.Tiles[i].BitsA = tileData[j + 0];
                this.Tiles[i].BitsB = tileData[j + 1];
                this.Tiles[i].BitsC = tileData[j + 2];
            }

            if (header.Version < 4)
            {
                var magic = new byte[]
                {
                    0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x1A, 0x1B,
                    0x1C, 0x1D, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                    0x00, 0x06, 0x07, 0x08, 0x09, 0x10, 0x1A, 0x1B,
                    0x1C, 0x1D, 0x00, 0x00, 0x6C, 0x00, 0x00, 0x00,
                };

                for (int i = 0; i < this.Tiles.Length; i++)
                {
                    var a = this.Tiles[i].BitsC;
                    var b = (byte)((magic[a & 0x1F] ^ a) & 0x1F);
                    this.Tiles[i].BitsC ^= b;
                }
            }

            var entities = new Level.Entity[header.EntityCount];

            if (header.Version >= 3)
            {
                for (int i = 0; i < header.EntityCount; i++)
                {
                    entities[i] = input.ReadStructure <Level.Entity>();
                }
            }
            else
            {
                using (var entityData =
                           new MemoryStream(input.ReadRLE(14, header.EntityCount, true)))
                {
                    for (int i = 0; i < header.EntityCount; i++)
                    {
                        var oldEntity = entityData.ReadStructure <Level.OldEntity>();

                        //entities[i] = new Level.Entity();
                        entities[i].X     = oldEntity.X;
                        entities[i].Y     = oldEntity.Y;
                        entities[i].BitsA = oldEntity.BitsA & 0x3FFFFFFFu;
                        entities[i].BitsB = oldEntity.BitsB & 0x7FFFFFFFu;
                        entities[i].BitsC = (oldEntity.BitsD & 0x7Fu) << 23;
                        entities[i].BitsD = oldEntity.BitsC;
                    }
                }
            }

            if (header.Version < 5)
            {
                for (int i = 0; i < header.EntityCount; i++)
                {
                    entities[i].BitsC &= 0xBFFFFFFFu;
                }
            }

            this.Entities = new List <Level.Entity>();
            this.Entities.AddRange(entities);

            if (input.Position != input.Length)
            {
                throw new FormatException();
            }
        }
コード例 #10
0
 /// <summary>
 /// Checks if AnimatorComponent has a parameter name of parameterName
 /// </summary>
 /// <returns></returns>
 public static bool HasParameter(this Animator animator, string parameterName)
 {
     return(Enumerable.Any(animator.parameters, parameter => parameter.name == parameterName));
 }
コード例 #11
0
        private bool TypeIsStateless(Type type)
        {
            lock (mLock)
            {
                var fields = type.GetMembers(BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public);
                foreach (var info in fields)
                {
                    if (info.MemberType == MemberTypes.Field)
                    {
                        // maked
                        if (Enumerable.Any(info.CustomAttributes,
                                           attribute => attribute.AttributeType == typeof(Updateable)))
                        {
                            continue;
                        }

                        var field = type.GetField(info.Name,
                                                  BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public);
                        if (field.FieldType == typeof(Logger))
                        {
                            continue;
                        }

                        System.Diagnostics.Trace.Assert(false, string.Format("{0} has state: {1}", type, info.Name));
                    }
                }

                var statics = type.GetMembers(BindingFlags.Static | BindingFlags.NonPublic | BindingFlags.Public);
                foreach (var info in statics)
                {
                    // genrated
                    if (Enumerable.Any(info.CustomAttributes,
                                       attribute => attribute.AttributeType ==
                                       typeof(System.Runtime.CompilerServices.CompilerGeneratedAttribute)))
                    {
                        continue;
                    }

                    // maked
                    if (Enumerable.Any(info.CustomAttributes,
                                       attribute => attribute.AttributeType == typeof(Updateable)))
                    {
                        continue;
                    }

                    if (info.MemberType == MemberTypes.Field)
                    {
                        var field = type.GetField(info.Name,
                                                  BindingFlags.Static | BindingFlags.NonPublic | BindingFlags.Public);
                        if (field.FieldType == typeof(Logger))
                        {
                            continue;
                        }

                        System.Diagnostics.Trace.Assert(false,
                                                        string.Format("{0} has static state: {1}", type, info.Name));
                    }
                }

                return(true);
            }
        }