-
Notifications
You must be signed in to change notification settings - Fork 1.9k
[XC] add IRootObjectProvider #28310
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
[XC] add IRootObjectProvider #28310
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,6 +3,7 @@ | |
| using Microsoft.Maui.Controls.XamlC; | ||
| using Mono.Cecil; | ||
| using Mono.Cecil.Cil; | ||
| using Mono.Cecil.Rocks; | ||
|
|
||
| namespace Microsoft.Maui.Controls.Build.Tasks; | ||
|
|
||
|
|
@@ -38,8 +39,13 @@ public TypeDefinition Resolve(TypeReference typeReference) => | |
| public FieldReference GetOrAddFieldReference((ModuleDefinition module, string fieldRefKey) key, Func<(ModuleDefinition module, string fieldRefKey), FieldReference> valueFactory) => | ||
| GetOrAdd(_fieldReferenceCache, key, valueFactory); | ||
|
|
||
| public TypeReference GetOrAddTypeReference(ModuleDefinition module, (string assemblyName, string clrNamespace, string typeName) type) => | ||
| GetOrAdd(_typeReferenceCache, (module, type.ToString()), x => x.module.ImportReference(x.module.GetTypeDefinition(this, type))); | ||
| public TypeReference GetOrAddTypeReference(ModuleDefinition module, (string assemblyName, string clrNamespace, string typeName) type) => GetOrAdd(_typeReferenceCache, (module, type.ToString()), x => | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this allows specifying [] in the string tuple for type, so we can pick a methodreference with the right parameters if some of them are arrays |
||
| { | ||
| if (type.typeName.EndsWith("[]", StringComparison.InvariantCultureIgnoreCase)) | ||
| return x.module.GetTypeDefinition(this, (type.assemblyName, type.clrNamespace, type.typeName.Substring(0, type.typeName.Length-2))).MakeArrayType(); | ||
| else | ||
| return x.module.ImportReference(x.module.GetTypeDefinition(this, type)); | ||
| }); | ||
|
|
||
| public TypeReference GetOrAddTypeReference(ModuleDefinition module, string typeKey, Func<(ModuleDefinition module, string typeKey), TypeReference> valueFactory) => | ||
| GetOrAdd(_typeReferenceCache, (module, typeKey), valueFactory); | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -8,3 +8,5 @@ Microsoft.Maui.Controls.Embedding.EmbeddingExtensions | |
| Microsoft.Maui.Controls.Xaml.Internals.ValueTargetProvider | ||
| Microsoft.Maui.Controls.Xaml.Internals.ValueTargetProvider.ValueTargetProvider(object! targetObject, object! targetProperty) -> void | ||
| Microsoft.Maui.Controls.Xaml.ResourceDictionaryHelpers | ||
| ~Microsoft.Maui.Controls.Xaml.Internals.SimpleValueTargetProvider.RootObject.get -> object | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is not modifying the publicAPI shipped files, so, is fine to include it in a SR? |
||
| ~Microsoft.Maui.Controls.Xaml.Internals.SimpleValueTargetProvider.SimpleValueTargetProvider(object[] objectAndParents, object targetProperty, Microsoft.Maui.Controls.Internals.INameScope[] scopes, object rootObject) -> void | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -135,10 +135,11 @@ public ValueTargetProvider(object targetObject, object targetProperty) | |
| } | ||
| #nullable restore | ||
|
|
||
| public class SimpleValueTargetProvider : IProvideParentValues, IProvideValueTarget, IReferenceProvider | ||
| public class SimpleValueTargetProvider : IProvideParentValues, IProvideValueTarget, IReferenceProvider, IRootObjectProvider | ||
|
||
| { | ||
| readonly object[] objectAndParents; | ||
| readonly object targetProperty; | ||
| readonly object rootObject; | ||
| readonly INameScope[] scopes; | ||
|
|
||
| [Obsolete("Use the other ctor")] | ||
|
|
@@ -147,7 +148,13 @@ public SimpleValueTargetProvider(object[] objectAndParents, object targetPropert | |
| { | ||
| } | ||
|
|
||
| [Obsolete("Use the other ctor")] | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we need to keep this around, like the other one, to make code compiled with a previous version of XamlC to keep working
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just try to add more details about the suggested alternative:
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this is only used by generated code, so the obsolete message should never show up |
||
| public SimpleValueTargetProvider(object[] objectAndParents, object targetProperty, INameScope[] scopes, bool notused) | ||
| : this(objectAndParents, targetProperty, scopes, null) | ||
| { | ||
| } | ||
|
|
||
| public SimpleValueTargetProvider(object[] objectAndParents, object targetProperty, INameScope[] scopes, object rootObject) | ||
| { | ||
| if (objectAndParents == null) | ||
| throw new ArgumentNullException(nameof(objectAndParents)); | ||
|
|
@@ -157,8 +164,10 @@ public SimpleValueTargetProvider(object[] objectAndParents, object targetPropert | |
| this.objectAndParents = objectAndParents; | ||
| this.targetProperty = targetProperty; | ||
| this.scopes = scopes; | ||
| this.rootObject = rootObject ?? objectAndParents[objectAndParents.Length - 1]; | ||
| } | ||
|
|
||
| public object RootObject => rootObject; | ||
| IEnumerable<object> IProvideParentValues.ParentObjects => objectAndParents; | ||
| object IProvideValueTarget.TargetObject => objectAndParents[0]; | ||
| object IProvideValueTarget.TargetProperty => targetProperty; | ||
|
|
||
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.
the runtime cost of passing an extra parameter that doesn't need to be evaluated is negligible