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


C# MemberPath.GetNodeOverrides方法代码示例

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


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

示例1: CanBeModified

        /// <summary>
        /// Indicate if the referred member can be modified or not due to sealing.
        /// </summary>
        /// <param name="asset">The asset to modify</param>
        /// <param name="path">The path to the member to modify</param>
        /// <returns><value>true</value> if it can be modified</returns>
        public bool CanBeModified(Asset asset, MemberPath path)
        {
            if (path.GetNodeOverrides(asset).Any(x => x.IsNew()))
                return true;

            var assetBase = asset.Base;
            while (assetBase != null && assetBase.Asset != null)
            {
                var parent = assetBase.Asset;
                var parentPath = path.Resolve(asset, parent).FirstOrDefault(); // if several paths exist in parent, they should be all equal (same object instance)
                if (parentPath == null)
                    break;

                var parentOverrides = parentPath.GetNodeOverrides(parent).ToList();
                if (parentOverrides.LastOrDefault().IsSealed())
                    return false;

                if (parentOverrides.Any(x => x.IsNew()))
                    break;

                assetBase = parent.Base;
            }

            return true;
        }
开发者ID:h78hy78yhoi8j,项目名称:xenko,代码行数:31,代码来源:AssetUpdater.cs

示例2: 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


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