当前位置: 首页>>代码示例>>C#>>正文


C# MemberPath.Push方法代码示例

本文整理汇总了C#中MemberPath.Push方法的典型用法代码示例。如果您正苦于以下问题:C# MemberPath.Push方法的具体用法?C# MemberPath.Push怎么用?C# MemberPath.Push使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在MemberPath的用法示例。


在下文中一共展示了MemberPath.Push方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: TestCanBeModifiedOrphan

        public void TestCanBeModifiedOrphan()
        {
            // -------------------------------------------
            // Check that CanBeModified is always true 
            // whatever are the values of the overrides
            //
            // For that set all the possible values of the overrides
            // at two first level of fields and check the reset
            // 
            // Field checked is orphan.MyClass.Value
            //
            // --------------------------------------------

            Initialize();

            var orphan = new TestAssetUpdate { MyClass = new MyClass() };
            var testValues = new[] { OverrideType.Base, OverrideType.Sealed, OverrideType.New, OverrideType.Sealed | OverrideType.New };

            var pathToValue = new MemberPath();
            pathToValue.Push(memberMyClass);
            pathToValue.Push(MemberValue);

            foreach (var value1 in testValues)
            {
                orphan.SetOverride(memberMyClass, value1);

                foreach (var value2 in testValues)
                {
                    orphan.MyClass.SetOverride(MemberValue, value2);

                    Assert.IsTrue(assetUpdater.CanBeModified(orphan, pathToValue));
                }
            }
        }
开发者ID:h78hy78yhoi8j,项目名称:xenko,代码行数:34,代码来源:TestAssetUpdater.cs

示例2: TestResolveComplex

        public void TestResolveComplex()
        {
            var memberPath = new MemberPath();
            memberPath.Push(MemberSubs);
            memberPath.Push(ListClassDesc, 1);
            memberPath.Push(MemberSub);
            memberPath.Push(MemberValue);

            var id = Guid.NewGuid();
            var referenceElt = new MyClass { Sub = new MyClass { Value = 1 } };
            var dualElt1 = new MyClass { Sub = new MyClass { Value = 2 } };
            var dualElt2 = new MyClass { Sub = new MyClass { Value = 3 } };
            var brokenDual = new MyClass();
            IdentifiableHelper.SetId(referenceElt, id);
            IdentifiableHelper.SetId(dualElt1, id);
            IdentifiableHelper.SetId(dualElt2, id);
            IdentifiableHelper.SetId(brokenDual, id);

            var reference = new MyClass { Subs = { new MyClass(), referenceElt } };
            var dual = new MyClass { Subs = { new MyClass(), new MyClass(), dualElt1, brokenDual, new MyClass(), dualElt2 } };

            var resolvedPaths = memberPath.Resolve(reference, dual).ToList();
            Assert.AreEqual(2, resolvedPaths.Count);

            object value;
            Assert.IsTrue(resolvedPaths[0].TryGetValue(dual, out value));
            Assert.AreEqual(dual.Subs[2].Sub.Value, value);

            Assert.IsTrue(resolvedPaths[1].TryGetValue(dual, out value));
            Assert.AreEqual(dual.Subs[5].Sub.Value, value);
        }
开发者ID:psowinski,项目名称:xenko,代码行数:31,代码来源:TestMemberPath.cs

示例3: TestMyClass

        public void TestMyClass()
        {
            var testClass = new MyClass { Sub = new MyClass() };
            testClass.Maps["XXX"] = new MyClass();
            testClass.Subs.Add(new MyClass());

            // 1) MyClass.Value = 1
            var memberPath = new MemberPath();
            memberPath.Push(MemberValue);

            object value;
            Assert.IsTrue(memberPath.Apply(testClass, MemberPathAction.ValueSet, 1));
            Assert.IsTrue(memberPath.TryGetValue(testClass, out value));
            Assert.AreEqual(1, value);
            Assert.AreEqual(1, testClass.Value);

            // 2) MyClass.Sub.Value = 1
            memberPath.Clear();
            memberPath.Push(MemberSub);
            memberPath.Push(MemberValue);

            Assert.IsTrue(memberPath.Apply(testClass, MemberPathAction.ValueSet, 1));
            Assert.IsTrue(memberPath.TryGetValue(testClass, out value));
            Assert.AreEqual(1, value);
            Assert.AreEqual(1, testClass.Sub.Value);

            // 3) MyClass.Struct.X = 1
            memberPath.Clear();
            memberPath.Push(MemberStruct);
            memberPath.Push(MemberX);

            Assert.IsTrue(memberPath.Apply(testClass, MemberPathAction.ValueSet, 1));
            Assert.IsTrue(memberPath.TryGetValue(testClass, out value));
            Assert.AreEqual(1, value);
            Assert.AreEqual(1, testClass.Struct.X);

            // 3) MyClass.Maps["XXX"].Value = 1
            memberPath.Clear();
            memberPath.Push(MemberMaps);
            memberPath.Push(MapClassDesc, "XXX");
            memberPath.Push(MemberValue);

            Assert.IsTrue(memberPath.Apply(testClass, MemberPathAction.ValueSet, 1));
            Assert.IsTrue(memberPath.TryGetValue(testClass, out value));
            Assert.AreEqual(1, value);
            Assert.AreEqual(1, testClass.Maps["XXX"].Value);

            // 4) MyClass.Subs[0].Value = 1
            memberPath.Clear();
            memberPath.Push(MemberSubs);
            memberPath.Push(ListClassDesc, 0);
            memberPath.Push(MemberValue);

            Assert.IsTrue(memberPath.Apply(testClass, MemberPathAction.ValueSet, 1));
            Assert.IsTrue(memberPath.TryGetValue(testClass, out value));
            Assert.AreEqual(1, value);
            Assert.AreEqual(1, testClass.Subs[0].Value);

            // 5) MyClass.Subs[0].X (invalid)
            memberPath.Clear();
            memberPath.Push(MemberSubs);
            memberPath.Push(ListClassDesc, 0);
            memberPath.Push(MemberX);

            Assert.IsFalse(memberPath.TryGetValue(testClass, out value));
            Assert.IsFalse(memberPath.Apply(testClass, MemberPathAction.ValueSet, 1));

            // 6) Remove key MyClass.Maps.Remove("XXX")
            memberPath.Clear();
            memberPath.Push(MemberMaps);
            memberPath.Push(MapClassDesc, "XXX");
            Assert.IsTrue(memberPath.Apply(testClass, MemberPathAction.DictionaryRemove, null));
            Assert.IsFalse(testClass.Maps.ContainsKey("XXX"));

            // 7) Re-add a value to the dictionary
            Assert.IsTrue(memberPath.Apply(testClass, MemberPathAction.ValueSet, new MyClass()));
            Assert.IsTrue(testClass.Maps.ContainsKey("XXX"));

            // 8) Remove key MyClass.Subs.Remove(0)
            memberPath.Clear();
            memberPath.Push(MemberSubs);
            memberPath.Push(ListClassDesc, 0);
            Assert.IsTrue(memberPath.Apply(testClass, MemberPathAction.CollectionRemove, null));
            Assert.AreEqual(0, testClass.Subs.Count);

            // 9) Add a key MyClass.Subs.Add(new MyClass())
            memberPath.Clear();
            memberPath.Push(MemberSubs);
            memberPath.Push(ListClassDesc, 0);
            Assert.IsTrue(memberPath.Apply(testClass, MemberPathAction.CollectionAdd, new MyClass()));
            Assert.AreEqual(1, testClass.Subs.Count);
        }
开发者ID:psowinski,项目名称:xenko,代码行数:92,代码来源:TestMemberPath.cs

示例4: TestResolveCollectionBroken

        public void TestResolveCollectionBroken()
        {
            var memberPath = new MemberPath();
            memberPath.Push(MemberSubs);
            memberPath.Push(ListClassDesc, 0);

            var referenceElt = new MyClass();
            IdentifiableHelper.SetId(referenceElt, Guid.NewGuid());

            var reference = new MyClass { Subs = { referenceElt } };
            var dual = new MyClass();
            dual.Subs.Add(new MyClass());
            dual.Subs.Add(new MyClass());

            var resolvedPaths = memberPath.Resolve(reference, dual).ToList();
            Assert.AreEqual(0, resolvedPaths.Count);

            memberPath = new MemberPath();
            memberPath.Push(MemberSubs);
            memberPath.Push(ListClassDesc, 1);
            
            resolvedPaths = memberPath.Resolve(reference, dual).ToList();
            Assert.AreEqual(0, resolvedPaths.Count);
        }
开发者ID:psowinski,项目名称:xenko,代码行数:24,代码来源:TestMemberPath.cs

示例5: TestResolveBroken

        public void TestResolveBroken()
        {
            var memberPath = new MemberPath();
            memberPath.Push(MemberSub);
            memberPath.Push(MemberStruct);
            memberPath.Push(MemberClass);
            memberPath.Push(MemberValue);

            var reference = new MyClass { Sub = new MyClass { Struct = new MyStruct { Class = new MyClass { Value = 1 } } } };
            var dual = new MyClass { Sub = new MyClass { Struct = new MyStruct { Class = null } } };

            var resolvedPaths = memberPath.Resolve(reference, dual).ToList();
            Assert.AreEqual(0, resolvedPaths.Count);
        }
开发者ID:psowinski,项目名称:xenko,代码行数:14,代码来源:TestMemberPath.cs

示例6: TestResolveSimple

        public void TestResolveSimple()
        {
            var memberPath = new MemberPath();
            memberPath.Push(MemberSub);
            memberPath.Push(MemberStruct);
            memberPath.Push(MemberClass);
            memberPath.Push(MemberMaps);
            memberPath.Push(MapClassDesc, "toto");
            memberPath.Push(MemberValue);

            var reference = new MyClass { Sub = new MyClass { Struct = new MyStruct { Class = new MyClass { Maps = { {"toto", new MyClass { Value = 1 } } } } } } };
            var dual = new MyClass { Sub = new MyClass { Struct = new MyStruct { Class = new MyClass { Maps = { { "toto", new MyClass { Value = 2 } } } } } } };

            var resolvedPaths = memberPath.Resolve(reference, dual).ToList();
            Assert.AreEqual(1, resolvedPaths.Count);

            object value;
            Assert.IsTrue(resolvedPaths[0].TryGetValue(dual, out value));
            Assert.AreEqual(dual.Sub.Struct.Class.Maps["toto"].Value, value);
        }
开发者ID:psowinski,项目名称:xenko,代码行数:20,代码来源:TestMemberPath.cs

示例7: TestGetNodeAttributes

        public void TestGetNodeAttributes()
        {
            var memberPath = new MemberPath();
            memberPath.Push(MemberSubs);
            memberPath.Push(ListClassDesc, 2);
            memberPath.Push(MemberMaps);
            memberPath.Push(MapClassDesc, "toto");
            memberPath.Push(MemberStruct);
            memberPath.Push(MemberClass);
            memberPath.Push(MemberValue);

            var obj = new MyClass();
            obj.Subs.Add(new MyClass());
            obj.Subs.Add(new MyClass());
            obj.Subs.Add(new MyClass());
            obj.Subs[2].Maps["toto"] = new MyClass();
            obj.Subs[2].Maps["toto"].Struct = new MyStruct { Class = new MyClass() };

            obj.SetOverride(MemberSubs, OverrideType.New | OverrideType.Sealed);
            obj.Subs[2].SetOverride(ThisDescriptor.Default, OverrideType.Sealed);
            obj.Subs[2].SetOverride(MemberMaps, OverrideType.New);
            obj.Subs[2].Maps["toto"].SetOverride(ThisDescriptor.Default, OverrideType.Base);
            obj.Subs[2].Maps["toto"].SetOverride(MemberStruct, OverrideType.Sealed);
            obj.Subs[2].Maps["toto"].Struct.SetOverride(MemberClass, OverrideType.New);
            obj.Subs[2].Maps["toto"].Struct.Class.SetOverride(MemberValue, OverrideType.Sealed);

            var overrides = memberPath.GetNodeOverrides(obj).ToList();
            Assert.AreEqual(6, overrides.Count);
            Assert.AreEqual(OverrideType.New | OverrideType.Sealed, overrides[0]);
            Assert.AreEqual(OverrideType.Sealed, overrides[1]);
            Assert.AreEqual(OverrideType.New, overrides[2]);
            Assert.AreEqual(OverrideType.Base, overrides[3]);
            Assert.AreEqual(OverrideType.Sealed, overrides[4]);
            Assert.AreEqual(OverrideType.Sealed, overrides[5]);

            // check that override from leaf is correctly returned too (special case)
            var pathToToto = new MemberPath();
            pathToToto.Push(MemberSubs);
            pathToToto.Push(ListClassDesc, 2);
            pathToToto.Push(MemberMaps);
            pathToToto.Push(MapClassDesc, "toto");

            overrides = pathToToto.GetNodeOverrides(obj).ToList();
            Assert.AreEqual(4, overrides.Count);
            Assert.AreEqual(OverrideType.New | OverrideType.Sealed, overrides[0]);
            Assert.AreEqual(OverrideType.Sealed, overrides[1]);
            Assert.AreEqual(OverrideType.New, overrides[2]);
            Assert.AreEqual(OverrideType.Base, overrides[3]);
        }
开发者ID:psowinski,项目名称:xenko,代码行数:49,代码来源:TestMemberPath.cs

示例8: TestGetNodes

        public void TestGetNodes()
        {
            var memberPath = new MemberPath();
            memberPath.Push(MemberSubs);
            memberPath.Push(ListClassDesc, 2);
            memberPath.Push(MemberMaps);
            memberPath.Push(MapClassDesc, "toto");
            memberPath.Push(MemberStruct);
            memberPath.Push(MemberClass);
            memberPath.Push(MemberValue);

            var obj = new MyClass();
            obj.Subs.Add(new MyClass());
            obj.Subs.Add(new MyClass());
            obj.Subs.Add(new MyClass());
            obj.Subs[2].Maps["toto"] = new MyClass();
            obj.Subs[2].Maps["toto"].Struct = new MyStruct { Class = new MyClass() };

            var nodes = memberPath.GetNodes(obj).ToList();

            Assert.AreEqual(8, nodes.Count);

            Assert.AreEqual(obj, nodes[0].Object);
            Assert.AreEqual(obj.Subs, nodes[1].Object);
            Assert.AreEqual(obj.Subs[2], nodes[2].Object);
            Assert.AreEqual(obj.Subs[2].Maps, nodes[3].Object);
            Assert.AreEqual(obj.Subs[2].Maps["toto"], nodes[4].Object);
            Assert.AreEqual(obj.Subs[2].Maps["toto"].Struct, nodes[5].Object);
            Assert.AreEqual(obj.Subs[2].Maps["toto"].Struct.Class, nodes[6].Object);
            Assert.AreEqual(obj.Subs[2].Maps["toto"].Struct.Class.Value, nodes[7].Object);

            Assert.AreEqual(MemberSubs, nodes[0].Descriptor);
            Assert.AreEqual(null, nodes[1].Descriptor);
            Assert.AreEqual(MemberMaps, nodes[2].Descriptor);
            Assert.AreEqual(null, nodes[3].Descriptor);
            Assert.AreEqual(MemberStruct, nodes[4].Descriptor);
            Assert.AreEqual(MemberClass, nodes[5].Descriptor);
            Assert.AreEqual(MemberValue, nodes[6].Descriptor);
            Assert.AreEqual(null, nodes[7].Descriptor);
        }
开发者ID:psowinski,项目名称:xenko,代码行数:40,代码来源:TestMemberPath.cs

示例9: TestCanBeModifiedParentChild

        public void TestCanBeModifiedParentChild()
        {
            Initialize();

            // ----------------------------------------------
            // Case of Asset with only one level of parent.
            //
            // 1. Seal all the parent, play with the child override status.
            // 2. Break path between child and parent, and check that field can be modified in child.
            // 3. Set child to base and play with parent override status.
            //
            // -----------------------------------------------

            var parent = new TestAssetUpdate { MyClass = new MyClass { Maps = { { "0", new MyClass()} } } };
            var child = new TestAssetUpdate { MyClass = new MyClass { Maps = { { "0", new MyClass() } } }, Base = new AssetBase(parent) };

            var pathToMyClass = new MemberPath();
            pathToMyClass.Push(memberMyClass);

            var pathToSub = new MemberPath();
            pathToSub.Push(memberMyClass);
            pathToSub.Push(MemberSub);

            var pathTo0 = new MemberPath();
            pathTo0.Push(memberMyClass);
            pathTo0.Push(MemberMaps);
            pathTo0.Push(MapClassDesc, "0");

            // ## 1 ##

            parent.SetOverride(memberMyClass, OverrideType.Sealed);
            parent.MyClass.SetOverride(MemberSub, OverrideType.Sealed);
            parent.MyClass.SetOverride(MemberMaps, OverrideType.Sealed);
            parent.MyClass.Maps["0"].SetOverride(ThisDescriptor.Default, OverrideType.Sealed);

            Assert.IsFalse(assetUpdater.CanBeModified(child, pathToMyClass));
            Assert.IsFalse(assetUpdater.CanBeModified(child, pathToSub));
            Assert.IsFalse(assetUpdater.CanBeModified(child, pathTo0));

            child.SetOverride(memberMyClass, OverrideType.Sealed);
            child.MyClass.SetOverride(MemberSub, OverrideType.Sealed);
            child.MyClass.SetOverride(MemberMaps, OverrideType.Sealed);
            child.MyClass.Maps["0"].SetOverride(ThisDescriptor.Default, OverrideType.Sealed);

            Assert.IsFalse(assetUpdater.CanBeModified(child, pathToMyClass));
            Assert.IsFalse(assetUpdater.CanBeModified(child, pathToSub));
            Assert.IsFalse(assetUpdater.CanBeModified(child, pathTo0));
            
            child.SetOverride(memberMyClass, OverrideType.New);

            Assert.IsTrue(assetUpdater.CanBeModified(child, pathToMyClass));
            Assert.IsTrue(assetUpdater.CanBeModified(child, pathToSub));
            Assert.IsTrue(assetUpdater.CanBeModified(child, pathTo0));

            child.SetOverride(memberMyClass, OverrideType.Sealed);
            child.MyClass.SetOverride(MemberSub, OverrideType.New);
            child.MyClass.Maps["0"].SetOverride(ThisDescriptor.Default, OverrideType.New);

            Assert.IsFalse(assetUpdater.CanBeModified(child, pathToMyClass));
            Assert.IsTrue(assetUpdater.CanBeModified(child, pathToSub));
            Assert.IsTrue(assetUpdater.CanBeModified(child, pathTo0));
            
            child.SetOverride(memberMyClass, OverrideType.New | OverrideType.Sealed);
            child.MyClass.SetOverride(MemberSub, OverrideType.New | OverrideType.Sealed);
            child.MyClass.Maps["0"].SetOverride(ThisDescriptor.Default, OverrideType.New | OverrideType.Sealed);

            Assert.IsTrue(assetUpdater.CanBeModified(child, pathToMyClass));
            Assert.IsTrue(assetUpdater.CanBeModified(child, pathToSub));
            Assert.IsTrue(assetUpdater.CanBeModified(child, pathTo0));

            // ## 2 ##
            var parent0 = parent.MyClass.Maps["0"];
            parent.MyClass.Maps.Remove("0");

            child.SetOverride(memberMyClass, OverrideType.Base);
            child.MyClass.SetOverride(MemberSub, OverrideType.Base);
            child.MyClass.SetOverride(MemberMaps, OverrideType.Base);
            child.MyClass.Maps["0"].SetOverride(ThisDescriptor.Default, OverrideType.Base);
            
            Assert.IsFalse(assetUpdater.CanBeModified(child, pathToMyClass));
            Assert.IsFalse(assetUpdater.CanBeModified(child, pathToSub));
            Assert.IsTrue(assetUpdater.CanBeModified(child, pathTo0));

            var parentMyClass = parent.MyClass;
            parent.MyClass = null;

            Assert.IsFalse(assetUpdater.CanBeModified(child, pathToMyClass));
            Assert.IsTrue(assetUpdater.CanBeModified(child, pathToSub));
            Assert.IsTrue(assetUpdater.CanBeModified(child, pathTo0));

            // ## 3 ##
            parentMyClass.Maps["0"] = parent0;
            parent.MyClass = parentMyClass;

            parent.SetOverride(memberMyClass, OverrideType.New | OverrideType.Sealed);
            parent.MyClass.SetOverride(MemberSub, OverrideType.New | OverrideType.Sealed);
            parent.MyClass.Maps["0"].SetOverride(ThisDescriptor.Default, OverrideType.New | OverrideType.Sealed);

            Assert.IsFalse(assetUpdater.CanBeModified(child, pathToMyClass));
            Assert.IsFalse(assetUpdater.CanBeModified(child, pathToSub));
//.........这里部分代码省略.........
开发者ID:h78hy78yhoi8j,项目名称:xenko,代码行数:101,代码来源:TestAssetUpdater.cs

示例10: TestCanBeModifiedParentGrandChild

        public void TestCanBeModifiedParentGrandChild()
        {
            // ----------------------------------------------
            // Case of Asset with only two level of parent.
            //
            // 1. Seal all the parent, check that grand child cannot be modified.
            // 2. Play with new override of child, and check grand child can be modified.
            // 3. Break a path only in child and check that grand child can be modified (even if parent is sealed).
            //
            // -----------------------------------------------

            Initialize();

            var parent = new TestAssetUpdate { MyClass = new MyClass() };
            var child = new TestAssetUpdate { MyClass = new MyClass(), Base = new AssetBase(parent) };
            var grandChild = new TestAssetUpdate { MyClass = new MyClass(), Base = new AssetBase(child) };

            var pathToMyClass = new MemberPath();
            pathToMyClass.Push(memberMyClass);

            var pathToSub = new MemberPath();
            pathToSub.Push(memberMyClass);
            pathToSub.Push(MemberSub);

            // ## 1 ##

            parent.SetOverride(memberMyClass, OverrideType.Sealed);
            parent.MyClass.SetOverride(MemberSub, OverrideType.Sealed);

            Assert.IsFalse(assetUpdater.CanBeModified(grandChild, pathToMyClass));
            Assert.IsFalse(assetUpdater.CanBeModified(grandChild, pathToSub));

            // ## 2 ##

            child.SetOverride(memberMyClass, OverrideType.New);

            Assert.IsTrue(assetUpdater.CanBeModified(grandChild, pathToMyClass));
            Assert.IsTrue(assetUpdater.CanBeModified(grandChild, pathToSub));

            child.SetOverride(memberMyClass, OverrideType.Base);
            child.MyClass.SetOverride(MemberSub, OverrideType.New);

            Assert.IsFalse(assetUpdater.CanBeModified(grandChild, pathToMyClass));
            Assert.IsTrue(assetUpdater.CanBeModified(grandChild, pathToSub));

            // ## 3 ##
            
            child.SetOverride(memberMyClass, OverrideType.Base);
            child.MyClass.SetOverride(MemberSub, OverrideType.Base);

            child.MyClass = null;

            Assert.IsFalse(assetUpdater.CanBeModified(grandChild, pathToMyClass));
            Assert.IsTrue(assetUpdater.CanBeModified(grandChild, pathToSub));
        }
开发者ID:h78hy78yhoi8j,项目名称:xenko,代码行数:55,代码来源:TestAssetUpdater.cs


注:本文中的MemberPath.Push方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。