@@ -540,7 +540,6 @@ object ICustomAstVisitor.VisitHashtable(HashtableAst hashtableAst)
540
540
foreach ( var kv in hashtableAst . KeyValuePairs )
541
541
{
542
542
string name = null ;
543
- string typeName = null ;
544
543
if ( kv . Item1 is StringConstantExpressionAst stringConstantExpressionAst )
545
544
{
546
545
name = stringConstantExpressionAst . Value ;
@@ -554,32 +553,46 @@ object ICustomAstVisitor.VisitHashtable(HashtableAst hashtableAst)
554
553
name = nameValue . ToString ( ) ;
555
554
}
556
555
557
- if ( name != null )
556
+ if ( name is not null )
558
557
{
559
- object value = null ;
560
558
if ( kv . Item2 is PipelineAst pipelineAst && pipelineAst . GetPureExpression ( ) is ExpressionAst expression )
561
559
{
562
- switch ( expression )
560
+ object value ;
561
+ if ( expression is ConstantExpressionAst constant )
563
562
{
564
- case ConstantExpressionAst constantExpression :
565
- value = constantExpression . Value ;
566
- break ;
567
- default :
568
- typeName = InferTypes ( kv . Item2 ) . FirstOrDefault ( ) ? . Name ;
569
- if ( typeName == null )
570
- {
571
- if ( SafeExprEvaluator . TrySafeEval ( expression , _context . ExecutionContext , out object safeValue ) )
572
- {
573
- value = safeValue ;
574
- }
575
- }
563
+ value = constant . Value ;
564
+ }
565
+ else
566
+ {
567
+ _ = SafeExprEvaluator . TrySafeEval ( expression , _context . ExecutionContext , out value ) ;
568
+ }
576
569
577
- break ;
570
+ PSTypeName valueType ;
571
+ if ( value is null )
572
+ {
573
+ valueType = new PSTypeName ( "System.Object" ) ;
578
574
}
575
+ else
576
+ {
577
+ valueType = new PSTypeName ( value . GetType ( ) ) ;
578
+ }
579
+
580
+ properties . Add ( new PSMemberNameAndType ( name , valueType , value ) ) ;
579
581
}
582
+ else
583
+ {
584
+ bool foundAnyTypes = false ;
585
+ foreach ( var item in InferTypes ( kv . Item2 ) )
586
+ {
587
+ foundAnyTypes = true ;
588
+ properties . Add ( new PSMemberNameAndType ( name , item ) ) ;
589
+ }
580
590
581
- var pstypeName = value != null ? new PSTypeName ( value . GetType ( ) ) : new PSTypeName ( typeName ?? "System.Object" ) ;
582
- properties . Add ( new PSMemberNameAndType ( name , pstypeName , value ) ) ;
591
+ if ( ! foundAnyTypes )
592
+ {
593
+ properties . Add ( new PSMemberNameAndType ( name , new PSTypeName ( "System.Object" ) ) ) ;
594
+ }
595
+ }
583
596
}
584
597
}
585
598
@@ -2257,6 +2270,16 @@ private IEnumerable<PSTypeName> InferTypeFrom(IndexExpressionAst indexExpression
2257
2270
bool foundAny = false ;
2258
2271
foreach ( var psType in targetTypes )
2259
2272
{
2273
+ if ( psType is PSSyntheticTypeName syntheticType )
2274
+ {
2275
+ foreach ( var member in syntheticType . Members )
2276
+ {
2277
+ yield return member . PSTypeName ;
2278
+ }
2279
+
2280
+ continue ;
2281
+ }
2282
+
2260
2283
var type = psType . Type ;
2261
2284
if ( type != null )
2262
2285
{
0 commit comments