本文整理汇总了C#中MemberPath.Resolve方法的典型用法代码示例。如果您正苦于以下问题:C# MemberPath.Resolve方法的具体用法?C# MemberPath.Resolve怎么用?C# MemberPath.Resolve使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MemberPath
的用法示例。
在下文中一共展示了MemberPath.Resolve方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: 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);
}
示例3: 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);
}
示例4: 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);
}
示例5: 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);
}