@@ -720,12 +720,21 @@ static bool TryParsePath(ILContext context, string path, TypeReference tSourceRe
720720 && pd . GetMethod != null
721721 && TypeRefComparer . Default . Equals ( pd . GetMethod . Parameters [ 0 ] . ParameterType . ResolveGenericParameters ( previousPartTypeRef ) , module . ImportReference ( context . Cache , ( "mscorlib" , "System" , "Object" ) ) )
722722 && pd . GetMethod . IsPublic , out indexerDeclTypeRef ) ;
723+ // Try to find an indexer with an enum parameter type
724+ indexer ??= previousPartTypeRef . GetProperty ( context . Cache ,
725+ pd => pd . Name == indexerName
726+ && pd . GetMethod != null
727+ && pd . GetMethod . Parameters [ 0 ] . ParameterType . ResolveGenericParameters ( previousPartTypeRef ) . ResolveCached ( context . Cache ) ? . IsEnum == true
728+ && pd . GetMethod . IsPublic , out indexerDeclTypeRef ) ;
723729
724730 properties . Add ( ( indexer , indexerDeclTypeRef , indexArg ) ) ;
725731 if ( indexer != null ) //the case when we index on an array, not a list
726732 {
727733 var indexType = indexer . GetMethod . Parameters [ 0 ] . ParameterType . ResolveGenericParameters ( indexerDeclTypeRef ) ;
728- if ( ! TypeRefComparer . Default . Equals ( indexType , module . TypeSystem . String ) && ! TypeRefComparer . Default . Equals ( indexType , module . TypeSystem . Int32 ) )
734+ var indexTypeDef = indexType . ResolveCached ( context . Cache ) ;
735+ if ( ! TypeRefComparer . Default . Equals ( indexType , module . TypeSystem . String )
736+ && ! TypeRefComparer . Default . Equals ( indexType , module . TypeSystem . Int32 )
737+ && indexTypeDef ? . IsEnum != true )
729738 throw new BuildException ( BindingIndexerTypeUnsupported , lineInfo , null , indexType . FullName ) ;
730739 previousPartTypeRef = indexer . PropertyType . ResolveGenericParameters ( indexerDeclTypeRef ) ;
731740 }
@@ -743,7 +752,7 @@ static bool TryParsePath(ILContext context, string path, TypeReference tSourceRe
743752 return true ;
744753 }
745754
746- static IEnumerable < Instruction > DigProperties ( IEnumerable < ( PropertyDefinition property , TypeReference propDeclTypeRef , string indexArg ) > properties , Dictionary < TypeReference , VariableDefinition > locs , Func < Instruction > fallback , IXmlLineInfo lineInfo , ModuleDefinition module )
755+ static IEnumerable < Instruction > DigProperties ( IEnumerable < ( PropertyDefinition property , TypeReference propDeclTypeRef , string indexArg ) > properties , Dictionary < TypeReference , VariableDefinition > locs , Func < Instruction > fallback , IXmlLineInfo lineInfo , ModuleDefinition module , XamlCache cache = null )
747756 {
748757 var first = true ;
749758
@@ -781,7 +790,25 @@ static IEnumerable<Instruction> DigProperties(IEnumerable<(PropertyDefinition pr
781790 else if ( TypeRefComparer . Default . Equals ( indexType , module . TypeSystem . Int32 ) && int . TryParse ( indexArg , out index ) )
782791 yield return Create ( Ldc_I4 , index ) ;
783792 else
784- throw new BuildException ( BindingIndexerParse , lineInfo , null , indexArg , property . Name ) ;
793+ {
794+ // Try to handle enum types
795+ var indexTypeDef = cache != null ? indexType . ResolveCached ( cache ) : indexType . Resolve ( ) ;
796+ if ( indexTypeDef ? . IsEnum == true )
797+ {
798+ // Find the enum field with the matching name
799+ var enumField = indexTypeDef . Fields . FirstOrDefault ( f => f . IsStatic && f . Name == indexArg ) ;
800+ if ( enumField != null )
801+ {
802+ // Load the enum value as an integer constant
803+ var enumValue = Convert . ToInt32 ( enumField . Constant ) ;
804+ yield return Create ( Ldc_I4 , enumValue ) ;
805+ }
806+ else
807+ throw new BuildException ( BindingIndexerParse , lineInfo , null , indexArg , property . Name ) ;
808+ }
809+ else
810+ throw new BuildException ( BindingIndexerParse , lineInfo , null , indexArg , property . Name ) ;
811+ }
785812 }
786813 }
787814
@@ -860,7 +887,7 @@ static IEnumerable<Instruction> CompiledBindingGetGetter(TypeReference tSourceRe
860887 pop = Create ( Pop ) ;
861888
862889 return pop ;
863- } , node as IXmlLineInfo , module ) ) ;
890+ } , node as IXmlLineInfo , module , context . Cache ) ) ;
864891
865892 foreach ( var loc in locs . Values )
866893 getter . Body . Variables . Add ( loc ) ;
@@ -950,7 +977,7 @@ static IEnumerable<Instruction> CompiledBindingGetSetter(TypeReference tSourceRe
950977 pop = Create ( Pop ) ;
951978
952979 return pop ;
953- } , node as IXmlLineInfo , module ) ) ;
980+ } , node as IXmlLineInfo , module , context . Cache ) ) ;
954981
955982 foreach ( var loc in locs . Values )
956983 setter . Body . Variables . Add ( loc ) ;
@@ -1076,7 +1103,7 @@ static IEnumerable<Instruction> CompiledBindingGetHandlers(TypeReference tSource
10761103 il . Emit ( Ldarg_0 ) ;
10771104 var lastGetterTypeRef = properties [ i - 1 ] . property ? . PropertyType ;
10781105 var locs = new Dictionary < TypeReference , VariableDefinition > ( ) ;
1079- il . Append ( DigProperties ( properties . Take ( i ) , locs , null , node as IXmlLineInfo , module ) ) ;
1106+ il . Append ( DigProperties ( properties . Take ( i ) , locs , null , node as IXmlLineInfo , module , context . Cache ) ) ;
10801107 foreach ( var loc in locs . Values )
10811108 partGetter . Body . Variables . Add ( loc ) ;
10821109 if ( lastGetterTypeRef != null && lastGetterTypeRef . IsValueType )
0 commit comments