/// <summary> /// Gets a <see cref="string"/> representing <see cref="ExpressionPath"/> instances added to current <see cref="PathManager"/> extended by the provided <see cref="ExpressionPath"/> /// </summary> /// <param name="additionalPath">A null reference or a <see cref="ExpressionPath"/> representing an additional path to be added to returned string</param> /// <returns>A constructed <see cref="string"/></returns> public string GetPath(ExpressionPath additionalPath) { var builder = new StringBuilder(_instance.GetType().Name); foreach (var path in _paths) { if (path.HasName && !path.StartsWithIndexer) { builder.Append("."); } if (path.HasName) { builder.Append(path); } } if (additionalPath == null || !additionalPath.HasName) { return(builder.ToString()); } if (!additionalPath.StartsWithIndexer) { builder.Append("."); } builder.Append(additionalPath); return(builder.ToString()); }
/// <summary> /// Gets a value indicating whether the <see cref="ExpressionPath.Instance"/> of the passed <see cref="ExpressionPath"/> as the object /// obtained by executing the <see cref="ExpressionPath"/> instances currently added to current <see cref="ExpressionPath"/> /// </summary> /// <param name="path"></param> /// <returns></returns> public bool IsAligned(ExpressionPath path) { if (path == null) { throw new ArgumentNullException(nameof(path)); } return(Result == path.Instance); }
/// <summary> /// Adds the passed <see cref="ExpressionPath"/> to the current <see cref="PathManager"/> instance /// </summary> /// <param name="path">A <see cref="ExpressionPath"/> instance to be added</param> public void Add(ExpressionPath path) { if (path == null) { throw new ArgumentNullException(nameof(path)); } if (!IsAligned(path)) { throw new InvalidOperationException("The provided ExpressionPath is not aligned with the last ExpressionPath added to PathManager"); } _paths.Insert(_paths.Count, path); }
public void IsNotNull <T>(Expression <Func <T> > propertyExpression) where T : class { if (propertyExpression == null) { throw new ArgumentNullException(nameof(propertyExpression)); } var expressionPath = ExpressionPath.Create(propertyExpression.Body); var actualValue = (T)(expressionPath.Result); if (actualValue == null) { var message = string.Format(ToStringFormatter, IsNullPattern, _pathManager.GetPath(expressionPath)); Assert.Fail(message); } }
public void AreEqual <T>(Expression <Func <T> > propertyExpression, T expectedValue) { if (propertyExpression == null) { throw new ArgumentNullException(nameof(propertyExpression)); } var expressionPath = ExpressionPath.Create(propertyExpression.Body); var actualValue = (T)(expressionPath.Result); if (!EqualityComparer <T> .Default.Equals(actualValue, expectedValue)) { var message = string.Format(ToStringFormatter, NotEqualMessagePattern, _pathManager.GetPath(expressionPath), expectedValue, actualValue); Assert.Fail(message); } }
public T StepInto <T>(Expression <Func <T> > propertyExpression, bool assertNotNull = true) { if (propertyExpression == null) { throw new ArgumentNullException(nameof(propertyExpression)); } _pathManager.Add(ExpressionPath.Create(propertyExpression.Body)); var result = (T)_pathManager.Result; if (assertNotNull && EqualityComparer <T> .Default.Equals(result, default(T))) { Assert.Fail(IsNullPattern, _pathManager.GetPath(null)); } return(result); }
public static async ETTask Refresh(this UIStageView self, GalGameEnginePara chapter = default) { foreach (var item in self.infos) //先全部隐藏 { item.Value.active = false; } var keys = self.Engine.StageRoleMap.Keys.ToList(); for (int i = 0; i < keys.Count; i++) { var key = keys[i]; if (!self.Engine.StageRoleMap.TryGetValue(key, out var value)) { continue; } var Expression = self.Engine.RoleExpressionMap[value]; //todo: 角色上场 if (self.Engine.RoleExpressionPathMap.TryGetValue(value, out var ExpressionPath)) { if (!ExpressionPath.TryGetValue(Expression, out var path)) { foreach (var exp in ExpressionPath) { Log.Debug("ExpressionPath not found:" + value + Expression + ", use " + exp.Value + " replace"); path = exp.Value; break; } } if (!string.IsNullOrEmpty(path)) { if (!self.infos.TryGetValue(key, out var info)) { info = await GameObjectPoolComponent.Instance.GetUIGameObjectAsync <UIStageRoleInfo>("UIGames/UIGalGame/Prefabs/Character.prefab"); if (self.infos.ContainsKey(key)) //异步加载回来已经有了 { GameObjectPoolComponent.Instance?.RecycleUIGameObject(info); info = self.infos[key]; } else { var pos = self.Engine.StagePosMap[key]; info.GetTransform().parent = self.GetTransform(); info.GetTransform().localPosition = pos; info.GetTransform().localScale = new Vector3(1, 1, 1); self.infos[key] = info; } info.active = true; } else { info.active = true; if (info.path == path) { continue; //没变化直接跳过 } } info.image.SetSpritePath(path).Coroutine(); info.path = path; if (string.Equals(chapter.Command, "CharacterOn", StringComparison.OrdinalIgnoreCase)) //入场 { string newUser = chapter.Arg1; if (string.Equals(newUser, value, StringComparison.OrdinalIgnoreCase)) { string type = chapter.Arg5; if (string.Equals(type, "FadeIn", StringComparison.OrdinalIgnoreCase)) { info.image.SetImageColor(Color.clear); float time = float.Parse(chapter.Arg6); DOTween.To(() => info.image.GetImageColor(), x => info.image.SetImageColor(x), Color.white, time); } } } else if (string.Equals(chapter.Command, "CharacterOff", StringComparison.OrdinalIgnoreCase)) //入场 { string newUser = chapter.Arg1; if (string.Equals(newUser, value, StringComparison.OrdinalIgnoreCase)) { string type = chapter.Arg5; if (string.Equals(type, "FadeOut", StringComparison.OrdinalIgnoreCase)) { info.image.SetImageColor(Color.white); float time = float.Parse(chapter.Arg6); DOTween.To(() => info.image.GetImageColor(), x => info.image.SetImageColor(x), Color.clear, time); } } } } else { Log.Debug("path is null:" + value + Expression); } } else { Log.Debug("RoleExpressionPathMap not found:" + value); } } foreach (var item in self.infos) //修改显隐状态 { item.Value.SetActive(item.Value.active); } }
public static Expression FullPathNotNull(ExpressionPath expressionPath, Expression compare) { expressionPath = expressionPath ?? throw new ArgumentNullException(nameof(expressionPath)); return(ComparisonBuilder.CheckNullInPath(expressionPath.ExpressionSteps, false, compare, false)); }