-
Notifications
You must be signed in to change notification settings - Fork 1.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[X] Compiled Bindings to Array #15944
Conversation
emit ldelem opcodes for accessing arrays elements in compiled bindings
@@ -719,7 +737,7 @@ static IEnumerable<Instruction> CompiledBindingGetSetter(TypeReference tSourceRe | |||
setter.Body.InitLocals = true; | |||
|
|||
var il = setter.Body.GetILProcessor(); | |||
if (!properties.Any() || properties.Last().property.SetMethod == null) | |||
if (!properties.Any() || properties.Last().property == null || properties.Last().property.SetMethod == null) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You could simplify this to something like:
if (!properties.Any() || properties.Last().property == null || properties.Last().property.SetMethod == null) | |
if (properties.Last() is ThePropertyType p && p.property == null || p.property.SetMethod == null) |
Which could avoid calling Any()
and Last()
as many times.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you mean LastOrDefault ?
else | ||
throw new BuildException(BindingIndexerParse, lineInfo, null, indexArg, property.Name); | ||
{ | ||
var indexType = property.GetMethod.Parameters[0].ParameterType.ResolveGenericParameters(propDeclTypeRef); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This would be terrible to do in practice... But can you make C# indexers with multiple parameters?
public string this[string key1, string key2]
{
get => someTupleDictionary[(key1, key2)];
set => someTupleDictionary[(key1, key2)] = value;
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
well, this PR is about arrays, not indexers, but yeah, it doesn't cover multidimensional arrays 🙉🙉🙉
Description of Change
emit ldelem opcodes for accessing arrays elements in compiled bindings
Issues Fixed
Fixes #10396