本文整理汇总了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;
}
示例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]);
}