/// <summary> /// The token key, which might be a property of the <paramref name="application"/> object or an /// application value in the application data. /// </summary> /// <param name="application">The application to source data from.</param> /// <param name="token">The token key.</param> /// <param name="path">Specifies the path to the token. Defaults to <see langword="null"/>.</param> /// <returns>The value of the token.</returns> /// <remarks>Order of precedence: (1) <paramref name="application"/> object; (2) application data.</remarks> public static object GetTokenValue(this Application application, string token, ApplicationDataPath path = null) { object tokenValue; if (application.TryGetPropertyValue(token, '.', out tokenValue)) { return tokenValue; } // We are going to be be popping items so we should create our own copy of the path. ApplicationDataPath pathIterator = new ApplicationDataPath(path ?? new ApplicationDataPath()); string tokenPath = pathIterator.ToString(token); tokenValue = application.ApplicationData.GetValue<object>(tokenPath, null); while (tokenValue == null && pathIterator.Count != 0) { pathIterator.TraverseUp(); tokenPath = pathIterator.ToString(token); tokenValue = application.ApplicationData.GetValue<object>(tokenPath, null); } return tokenValue; }
public void ReturnsFirstItem() { ApplicationDataPath path = new ApplicationDataPath(); path.Append("Foo", 42); path.Append("Bar", 16); ApplicationDataPathSegment segment = path.TraverseUp(); Assert.AreEqual(16, segment.Index); }
public void LeavesObjectInCorrectState() { ApplicationDataPath path = new ApplicationDataPath(); path.Append("Foo", 42); path.Append("Bar", 16); path.TraverseUp(); Assert.AreEqual(42, path.First().Index); }