@@ -1150,6 +1150,22 @@ private static string GetStrictUnmarshalCode(TypeInfo type, string jsValueName,
11501150 {
11511151 var elementTypeName = type . ElementType . Replace ( "global::" , "" ) ;
11521152
1153+ // Check if element is a [JSEnum]
1154+ if ( type . ItemTypeSymbol != null && type . ItemTypeSymbol . IsJSEnum ( ) )
1155+ {
1156+ var fullEnumType = type . ItemTypeSymbol . ToDisplayString ( SymbolDisplayFormat . FullyQualifiedFormat ) ;
1157+
1158+ if ( type . ItemTypeSymbol . IsJSEnumFlags ( ) )
1159+ {
1160+ return $ "{ jsValueName } .ToArray<int>().Select(x => ({ fullEnumType } )x).ToArray()";
1161+ }
1162+ else
1163+ {
1164+ return
1165+ $ "{ jsValueName } .ToArray<string>().Select(x => global::System.Enum.Parse<{ fullEnumType } >(x, ignoreCase: true)).ToArray()";
1166+ }
1167+ }
1168+
11531169 if ( IsPrimitiveTypeName ( type . ElementType ) ||
11541170 elementTypeName is "System.Object" or "object" )
11551171 return $ "{ jsValueName } .ToArray<{ type . ElementType } >()";
@@ -1199,6 +1215,25 @@ private static string GetUnmarshalCode(TypeInfo type, string jsValueName, string
11991215 return
12001216 $ "({ jsValueName } .IsArrayBuffer() ? { jsValueName } .CopyArrayBuffer() : { jsValueName } .CopyTypedArray())";
12011217
1218+ if ( type is { IsArray : true , ElementType : not null } )
1219+ {
1220+ // Check if element is a [JSEnum]
1221+ if ( type . ItemTypeSymbol != null && type . ItemTypeSymbol . IsJSEnum ( ) )
1222+ {
1223+ var fullEnumType = type . ItemTypeSymbol . ToDisplayString ( SymbolDisplayFormat . FullyQualifiedFormat ) ;
1224+
1225+ if ( type . ItemTypeSymbol . IsJSEnumFlags ( ) )
1226+ {
1227+ return $ "{ jsValueName } .ToArray<int>().Select(x => ({ fullEnumType } )x).ToArray()";
1228+ }
1229+ else
1230+ {
1231+ return
1232+ $ "{ jsValueName } .ToArray<string>().Select(x => global::System.Enum.Parse<{ fullEnumType } >(x, ignoreCase: true)).ToArray()";
1233+ }
1234+ }
1235+ }
1236+
12021237 return $ "{ type . FullName } .FromJSValue({ contextVarName } , { jsValueName } )";
12031238 }
12041239
@@ -1368,8 +1403,8 @@ private static string GetMarshalCodeForPrimitive(TypeInfo type, string valueName
13681403 : $ "{ ctxName } .NewNumber((int){ valueName } )";
13691404
13701405 return type . IsNullable
1371- ? $ "({ valueName } == null ? { ctxName } .Null() : { ctxName } .NewString({ valueName } .ToString ()))"
1372- : $ "{ ctxName } .NewString({ valueName } .ToString ())";
1406+ ? $ "({ valueName } == null ? { ctxName } .Null() : { ctxName } .NewString({ valueName } .ToStringFast ()))"
1407+ : $ "{ ctxName } .NewString({ valueName } .ToStringFast ())";
13731408 }
13741409
13751410 if ( type . FullName == "global::System.Byte[]" )
@@ -1381,6 +1416,23 @@ private static string GetMarshalCodeForPrimitive(TypeInfo type, string valueName
13811416 {
13821417 var elementTypeName = type . ElementType . Replace ( "global::" , "" ) ;
13831418
1419+ // Check if element is a [JSEnum]
1420+ if ( type . ItemTypeSymbol != null && type . ItemTypeSymbol . IsJSEnum ( ) )
1421+ {
1422+ if ( type . ItemTypeSymbol . IsJSEnumFlags ( ) )
1423+ {
1424+ return type . IsNullable
1425+ ? $ "({ valueName } == null ? { ctxName } .Null() : { ctxName } .NewArray({ valueName } .Select(x => (int)x)))"
1426+ : $ "{ ctxName } .NewArray({ valueName } .Select(x => (int)x))";
1427+ }
1428+ else
1429+ {
1430+ return type . IsNullable
1431+ ? $ "({ valueName } == null ? { ctxName } .Null() : { ctxName } .NewArray({ valueName } .Select(x => x.ToStringFast())))"
1432+ : $ "{ ctxName } .NewArray({ valueName } .Select(x => x.ToStringFast()))";
1433+ }
1434+ }
1435+
13841436 if ( IsPrimitiveTypeName ( type . ElementType ) ||
13851437 elementTypeName is "System.Object" or "object" )
13861438 return type . IsNullable
0 commit comments