public ObjectInfo GetObjectInfo(object context, object obj) { obj = obj is EvaluationResult evalResult ? evalResult.Value : obj; if (obj == null || IsInvalid(obj)) { return(s_nullObj); } if (obj.GetType().IsArray) { return(ArrayObjInfo(((IEnumerable)obj).Cast <object>().ToArray())); } var customResult = m_customRenderer?.Invoke(this, context, obj); if (customResult != null) { return(customResult); } return(Match(obj, new CaseMatcher <ObjectInfo>[] { Case <ScopeLocals>(scope => new ObjectInfo(LocalsScopeName, null, Lazy.Create(() => GetLocalsForStackEntry(scope.EvalState, scope.FrameIndex)))), Case <ScopePipGraph>(scope => PipGraphInfo(scope.Graph).WithPreview(PipGraphScopeName)), Case <ScopeAllModules>(scope => ArrayObjInfo(scope.EvaluatedModules.ToArray()).WithPreview(EvaluatedModulesScopeName)), Case <IModuleAndContext>(mc => GetObjectInfo(mc.Tree.RootContext, mc.Module)), Case <ObjectInfo>(objInf => objInf), Case <IPipGraph>(graph => PipGraphInfo(graph)), Case <Pip>(pip => GenericObjectInfo(pip, $"<{pip.PipType}>")), Case <PipProvenance>(prov => ProvenanceInfo(prov)), Case <EnvironmentVariable>(envVar => EnvironmentVariableInfo(envVar)), Case <PipFragment>(pipFrag => PipFragmentInfo(context, pipFrag)), Case <Thunk>(thunk => thunk.Value != null ? GetObjectInfo(context, thunk.Value) : new ObjectInfo("<not evaluated>")), Case <FunctionLikeExpression>(lambda => LambdaInfo(lambda)), Case <Closure>(cls => LambdaInfo(cls.Function)), Case <SymbolAtom>(sym => new ObjectInfo(sym.ToString(StringTable))), Case <StringId>(id => new ObjectInfo(id.ToString(StringTable))), Case <PipId>(id => new ObjectInfo($"{id.Value}")), Case <UndefinedLiteral>(_ => new ObjectInfo("undefined", UndefinedLiteral.Instance)), Case <UndefinedValue>(_ => new ObjectInfo("undefined", UndefinedValue.Instance)), Case <AbsolutePath>(path => new ObjectInfo($"p`{path.ToString(PathTable)}`", path)), Case <RelativePath>(path => new ObjectInfo($"r`{path.ToString(StringTable)}`", path)), Case <PathAtom>(atom => new ObjectInfo($"a`{atom.ToString(StringTable)}`", atom)), Case <FileArtifact>(file => new ObjectInfo($"f`{file.Path.ToString(PathTable)}`", file)), Case <DirectoryArtifact>(dir => new ObjectInfo($"d`{dir.Path.ToString(PathTable)}`", dir)), Case <int>(num => new ObjectInfo($"{num}")), Case <uint>(num => new ObjectInfo($"{num}")), Case <short>(num => new ObjectInfo($"{num}", (int)num)), Case <long>(num => new ObjectInfo($"{num}")), Case <char>(ch => new ObjectInfo($"'{ch}'", ch.ToString())), Case <string>(str => new ObjectInfo($"\"{str}\"", str)), Case <Enum>(e => new ObjectInfo($"{e.GetType().Name}.{e}", e)), Case <NumberLiteral>(numLit => new ObjectInfo(numLit.UnboxedValue.ToString(), numLit)), Case <Func <object> >(func => FuncObjInfo(func)), Case <ArraySegment <object> >(arrSeg => ArrayObjInfo(arrSeg)), Case <IEnumerable>(enu => new ObjectInfo("IEnumerable", Lazy.Create(() => new[] { new Property("Result", enu.Cast <object>().ToArray()) }))), Case <ArrayLiteral>(arrLit => ArrayObjInfo(arrLit.Values.Select(v => v.Value).ToArray()).WithOriginal(arrLit)), Case <ModuleBinding>(binding => GetObjectInfo(context, binding.Body)), Case <ErrorValue>(error => ErrorValueInfo()), Case <object>(o => GenericObjectInfo(o, o?.ToString())) }, defaultResult: s_nullObj)); }
public ObjectInfo GetObjectInfo(object context, object obj) { obj = obj is EvaluationResult evalResult ? evalResult.Value : obj; if (obj == null || IsInvalid(obj)) { return(s_nullObj); } if (obj.GetType().IsArray) { return(ArrayObjInfo(((IEnumerable)obj).Cast <object>().ToArray())); } var customResult = m_customRenderer?.Invoke(this, context, obj); if (customResult != null) { return(customResult); } return(obj switch { ScopeLocals scope => new ObjectInfo(LocalsScopeName, null, Lazy.Create(() => GetLocalsForStackEntry(scope.EvalState, scope.FrameIndex))), ScopePipGraph scope => PipGraphInfo(scope.Graph).WithPreview(PipGraphScopeName), ScopeAllModules scope => ArrayObjInfo(scope.EvaluatedModules.ToArray()).WithPreview(EvaluatedModulesScopeName), IModuleAndContext mc => GetObjectInfo(mc.Tree.RootContext, mc.Module), ObjectInfo objInf => objInf, IPipGraph graph => PipGraphInfo(graph), Pip pip => GenericObjectInfo(pip, $"<{pip.PipType}>").Build(), PipProvenance prov => ProvenanceInfo(prov), EnvironmentVariable envVar => EnvironmentVariableInfo(envVar), PipFragment pipFrag => PipFragmentInfo(context, pipFrag), Thunk thunk => thunk.Value != null?GetObjectInfo(context, thunk.Value) : new ObjectInfo("<not evaluated>"), FunctionLikeExpression lambda => LambdaInfo(lambda), Closure cls => LambdaInfo(cls.Function), SymbolAtom sym => new ObjectInfo(sym.ToString(StringTable)), StringId id => new ObjectInfo(id.ToString(StringTable)), PipId id => new ObjectInfo($"{id.Value}"), UndefinedLiteral _ => new ObjectInfo("undefined", UndefinedLiteral.Instance), UndefinedValue _ => new ObjectInfo("undefined", UndefinedValue.Instance), AbsolutePath path => new ObjectInfo($"p`{path.ToString(PathTable)}`", path), RelativePath path => new ObjectInfo($"r`{path.ToString(StringTable)}`", path), PathAtom atom => new ObjectInfo($"a`{atom.ToString(StringTable)}`", atom), FileArtifact file => new ObjectInfo($"f`{file.Path.ToString(PathTable)}`", file), DirectoryArtifact dir => new ObjectInfo($"d`{dir.Path.ToString(PathTable)}`", dir), int num => new ObjectInfo($"{num}"), uint num => new ObjectInfo($"{num}"), short num => new ObjectInfo($"{num}", (int)num), long num => new ObjectInfo($"{num}"), char ch => new ObjectInfo($"'{ch}'", ch.ToString()), string str => new ObjectInfo($"\"{str}\"", str), Enum e => new ObjectInfo($"{e.GetType().Name}.{e}", e), NumberLiteral numLit => new ObjectInfo(numLit.UnboxedValue.ToString(), numLit), Func <object> func => FuncObjInfo(func), ArraySegment <object> arrSeg => ArrayObjInfo(arrSeg), IEnumerable enu => new ObjectInfoBuilder().Preview("IEnumerable").Prop("Result", Lazy.Create <object>(() => enu.Cast <object>().ToArray())).Build(), ArrayLiteral arrLit => ArrayObjInfo(arrLit.Values.Select(v => v.Value).ToArray()).WithOriginal(arrLit), ModuleBinding binding => GetObjectInfo(context, binding.Body), ErrorValue error => ErrorValueInfo(), object o => GenericObjectInfo(o).Build(), _ => s_nullObj });