Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 14 additions & 11 deletions src/Controls/docs/Microsoft.Maui.Controls/ResourceDictionary.xml
Original file line number Diff line number Diff line change
Expand Up @@ -447,11 +447,11 @@
<remarks>To be added.</remarks>
</Docs>
</Member>
<Member MemberName="SetAndLoadSource">
<MemberSignature Language="C#" Value="public void SetAndLoadSource (Uri value, string resourcePath, System.Reflection.Assembly assembly, System.Xml.IXmlLineInfo lineInfo);" />
<MemberSignature Language="ILAsm" Value=".method public hidebysig instance void SetAndLoadSource(class System.Uri value, string resourcePath, class System.Reflection.Assembly assembly, class System.Xml.IXmlLineInfo lineInfo) cil managed" />
<MemberSignature Language="DocId" Value="M:Microsoft.Maui.Controls.ResourceDictionary.SetAndLoadSource(System.Uri,System.String,System.Reflection.Assembly,System.Xml.IXmlLineInfo)" />
<MemberSignature Language="F#" Value="member this.SetAndLoadSource : Uri * string * System.Reflection.Assembly * System.Xml.IXmlLineInfo -&gt; unit" Usage="resourceDictionary.SetAndLoadSource (value, resourcePath, assembly, lineInfo)" />
<Member MemberName="SetAndCreateSource&lt;T&gt;">
<MemberSignature Language="C#" Value="public void SetAndCreateSource&lt;T&gt; (Uri value);" />
<MemberSignature Language="ILAsm" Value=".method public hidebysig instance void SetAndCreateSource&lt;string&gt;(class System.Uri value) cil managed" />
<MemberSignature Language="DocId" Value="M:Microsoft.Maui.Controls.ResourceDictionary.SetAndCreateSource``1(System.Uri)" />
<MemberSignature Language="F#" Value="member this.SetAndCreateSource : Uri -&gt; unit" Usage="resourceDictionary.SetAndCreateSource (value)" />
<MemberType>Method</MemberType>
<AssemblyInfo>
<AssemblyName>Microsoft.Maui.Controls.Core</AssemblyName>
Expand All @@ -466,17 +466,20 @@
<ReturnValue>
<ReturnType>System.Void</ReturnType>
</ReturnValue>
<TypeParameters>
<TypeParameter Name="T">
<Constraints>
<BaseTypeName>Microsoft.Maui.Controls.ResourceDictionary</BaseTypeName>
<ParameterAttribute>DefaultConstructorConstraint</ParameterAttribute>
</Constraints>
</TypeParameter>
</TypeParameters>
<Parameters>
<Parameter Name="value" Type="System.Uri" />
<Parameter Name="resourcePath" Type="System.String" />
<Parameter Name="assembly" Type="System.Reflection.Assembly" />
<Parameter Name="lineInfo" Type="System.Xml.IXmlLineInfo" />
</Parameters>
<Docs>
<typeparam name="T">To be added.</typeparam>
<param name="value">To be added.</param>
<param name="resourcePath">To be added.</param>
<param name="assembly">To be added.</param>
<param name="lineInfo">To be added.</param>
<summary>For internal use by the Microsoft.Maui.Controls platform.</summary>
<remarks>To be added.</remarks>
</Docs>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,15 +45,22 @@ public IEnumerable<Instruction> ConvertFromString(string value, ILContext contex
var resourcePath = ResourceDictionary.RDSourceTypeConverter.GetResourcePath(uri, rootTargetPath);

//fail early
var resourceId = XamlCTask.GetResourceIdForPath(context.Cache, module, resourcePath);
if (resourceId == null)
var resourceType = XamlCTask.GetTypeForPath(context.Cache, module, resourcePath);
if (resourceType == null)
throw new BuildException(BuildExceptionCode.ResourceMissing, node, null, value);

// validate that the resourceType has a default ctor
var resourceTypeDef = resourceType.ResolveCached(context.Cache);
var defaultCtor = resourceTypeDef.Methods.FirstOrDefault(md => md.IsConstructor && !md.HasParameters);
if (defaultCtor == null)
throw new BuildException(BuildExceptionCode.ConstructorDefaultMissing, node, null, resourceTypeDef);

var resourceDictionaryType = ("Microsoft.Maui.Controls", "Microsoft.Maui.Controls", "ResourceDictionary");
var resourceDictionaryTypeDefinition = currentModule.GetTypeDefinition(context.Cache, resourceDictionaryType);

//abuse the converter, produce some side effect, but leave the stack untouched
//public void SetAndLoadSource(Uri value, string resourceID, Assembly assembly, System.Xml.IXmlLineInfo lineInfo)
foreach (var instruction in context.Variables[rdNode].LoadAs(context.Cache, currentModule.GetTypeDefinition(context.Cache, resourceDictionaryType), currentModule))
//public void SetAndCreateSource<TResourceType>(Uri value)
foreach (var instruction in context.Variables[rdNode].LoadAs(context.Cache, resourceDictionaryTypeDefinition, currentModule))
yield return instruction;
//reappend assembly= in all cases, see other RD converter
if (!string.IsNullOrEmpty(asmName))
Expand All @@ -65,28 +72,21 @@ public IEnumerable<Instruction> ConvertFromString(string value, ILContext contex

//keep the Uri for later
yield return Create(Dup);
var uriVarDef = new VariableDefinition(currentModule.ImportReference(context.Cache, ("System", "System", "Uri")));
var uriType = currentModule.ImportReference(context.Cache, ("System", "System", "Uri"));
var uriVarDef = new VariableDefinition(uriType);
body.Variables.Add(uriVarDef);
yield return Create(Stloc, uriVarDef);
yield return Create(Ldstr, resourcePath); //resourcePath

if (!string.IsNullOrEmpty(asmName))
{
yield return Create(Ldstr, asmName);
yield return Create(Call, currentModule.ImportMethodReference(context.Cache, ("mscorlib", "System.Reflection", "Assembly"), methodName: "Load", parameterTypes: new[] { ("mscorlib", "System", "String") }, isStatic: true));
}
else //we could use assembly.Load in the 'else' part too, but I don't want to change working code right now
{
yield return Create(Ldtoken, currentModule.ImportReference(((ILRootNode)rootNode).TypeReference));
yield return Create(Call, currentModule.ImportMethodReference(context.Cache, ("mscorlib", "System", "Type"), methodName: "GetTypeFromHandle", parameterTypes: new[] { ("mscorlib", "System", "RuntimeTypeHandle") }, isStatic: true));
yield return Create(Callvirt, currentModule.ImportPropertyGetterReference(context.Cache, ("mscorlib", "System", "Type"), propertyName: "Assembly", flatten: true));
}
foreach (var instruction in node.PushXmlLineInfo(context))
yield return instruction; //lineinfo
yield return Create(Callvirt, currentModule.ImportMethodReference(context.Cache,
resourceDictionaryType,
methodName: "SetAndLoadSource",
parameterTypes: new[] { ("System", "System", "Uri"), ("mscorlib", "System", "String"), ("mscorlib", "System.Reflection", "Assembly"), ("System.Xml.ReaderWriter", "System.Xml", "IXmlLineInfo") }));
var method = currentModule.ImportMethodReference(
context.Cache,
resourceDictionaryTypeDefinition,
methodName: "SetAndCreateSource",
parameterTypes: new[] { uriType });

var genericInstanceMethod = new GenericInstanceMethod(method);
genericInstanceMethod.GenericArguments.Add(resourceType);

yield return Create(Callvirt, genericInstanceMethod);
//ldloc the stored uri as return value
yield return Create(Ldloc, uriVarDef);
}
Expand Down
13 changes: 13 additions & 0 deletions src/Controls/src/Build.Tasks/XamlCTask.cs
Original file line number Diff line number Diff line change
Expand Up @@ -413,5 +413,18 @@ internal static string GetResourceIdForPath(XamlCache cache, ModuleDefinition mo
}
return null;
}

internal static TypeReference GetTypeForPath(XamlCache cache, ModuleDefinition module, string path)
{
foreach (var ca in module.GetCustomAttributes())
{
if (!TypeRefComparer.Default.Equals(ca.AttributeType, module.ImportReference(cache, ("Microsoft.Maui.Controls", "Microsoft.Maui.Controls.Xaml", "XamlResourceIdAttribute"))))
continue;
if (ca.ConstructorArguments[1].Value as string != path)
continue;
return ca.ConstructorArguments[2].Value as TypeReference;
}
return null;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -240,4 +240,6 @@ Microsoft.Maui.Controls.ContentPage.HideSoftInputOnTapped.set -> void
*REMOVED*Microsoft.Maui.Controls.Entry.SelectionLength.set -> void
Microsoft.Maui.Controls.Xaml.RequireServiceAttribute
~Microsoft.Maui.Controls.Xaml.RequireServiceAttribute.RequireServiceAttribute(System.Type[] serviceTypes) -> void
~Microsoft.Maui.Controls.Xaml.RequireServiceAttribute.ServiceTypes.get -> System.Type[]
~Microsoft.Maui.Controls.Xaml.RequireServiceAttribute.ServiceTypes.get -> System.Type[]
~Microsoft.Maui.Controls.ResourceDictionary.SetAndCreateSource<T>(System.Uri value) -> void
*REMOVED*~Microsoft.Maui.Controls.ResourceDictionary.SetAndLoadSource(System.Uri value, string resourcePath, System.Reflection.Assembly assembly, System.Xml.IXmlLineInfo lineInfo) -> void
Original file line number Diff line number Diff line change
Expand Up @@ -254,4 +254,6 @@ Microsoft.Maui.Controls.ContentPage.HideSoftInputOnTapped.set -> void
*REMOVED*Microsoft.Maui.Controls.Entry.SelectionLength.set -> void
Microsoft.Maui.Controls.Xaml.RequireServiceAttribute
~Microsoft.Maui.Controls.Xaml.RequireServiceAttribute.RequireServiceAttribute(System.Type[] serviceTypes) -> void
~Microsoft.Maui.Controls.Xaml.RequireServiceAttribute.ServiceTypes.get -> System.Type[]
~Microsoft.Maui.Controls.Xaml.RequireServiceAttribute.ServiceTypes.get -> System.Type[]
~Microsoft.Maui.Controls.ResourceDictionary.SetAndCreateSource<T>(System.Uri value) -> void
*REMOVED*~Microsoft.Maui.Controls.ResourceDictionary.SetAndLoadSource(System.Uri value, string resourcePath, System.Reflection.Assembly assembly, System.Xml.IXmlLineInfo lineInfo) -> void
Original file line number Diff line number Diff line change
Expand Up @@ -258,4 +258,6 @@ Microsoft.Maui.Controls.ContentPage.HideSoftInputOnTapped.set -> void

Microsoft.Maui.Controls.Xaml.RequireServiceAttribute
~Microsoft.Maui.Controls.Xaml.RequireServiceAttribute.RequireServiceAttribute(System.Type[] serviceTypes) -> void
~Microsoft.Maui.Controls.Xaml.RequireServiceAttribute.ServiceTypes.get -> System.Type[]
~Microsoft.Maui.Controls.Xaml.RequireServiceAttribute.ServiceTypes.get -> System.Type[]
~Microsoft.Maui.Controls.ResourceDictionary.SetAndCreateSource<T>(System.Uri value) -> void
*REMOVED*~Microsoft.Maui.Controls.ResourceDictionary.SetAndLoadSource(System.Uri value, string resourcePath, System.Reflection.Assembly assembly, System.Xml.IXmlLineInfo lineInfo) -> void
Original file line number Diff line number Diff line change
Expand Up @@ -215,4 +215,6 @@ Microsoft.Maui.Controls.ContentPage.HideSoftInputOnTapped.set -> void
*REMOVED*Microsoft.Maui.Controls.Entry.SelectionLength.set -> void
Microsoft.Maui.Controls.Xaml.RequireServiceAttribute
~Microsoft.Maui.Controls.Xaml.RequireServiceAttribute.RequireServiceAttribute(System.Type[] serviceTypes) -> void
~Microsoft.Maui.Controls.Xaml.RequireServiceAttribute.ServiceTypes.get -> System.Type[]
~Microsoft.Maui.Controls.Xaml.RequireServiceAttribute.ServiceTypes.get -> System.Type[]
~Microsoft.Maui.Controls.ResourceDictionary.SetAndCreateSource<T>(System.Uri value) -> void
*REMOVED*~Microsoft.Maui.Controls.ResourceDictionary.SetAndLoadSource(System.Uri value, string resourcePath, System.Reflection.Assembly assembly, System.Xml.IXmlLineInfo lineInfo) -> void
Original file line number Diff line number Diff line change
Expand Up @@ -244,4 +244,6 @@ Microsoft.Maui.Controls.ContentPage.HideSoftInputOnTapped.set -> void
*REMOVED*Microsoft.Maui.Controls.Entry.SelectionLength.set -> void
Microsoft.Maui.Controls.Xaml.RequireServiceAttribute
~Microsoft.Maui.Controls.Xaml.RequireServiceAttribute.RequireServiceAttribute(System.Type[] serviceTypes) -> void
~Microsoft.Maui.Controls.Xaml.RequireServiceAttribute.ServiceTypes.get -> System.Type[]
~Microsoft.Maui.Controls.Xaml.RequireServiceAttribute.ServiceTypes.get -> System.Type[]
~Microsoft.Maui.Controls.ResourceDictionary.SetAndCreateSource<T>(System.Uri value) -> void
*REMOVED*~Microsoft.Maui.Controls.ResourceDictionary.SetAndLoadSource(System.Uri value, string resourcePath, System.Reflection.Assembly assembly, System.Xml.IXmlLineInfo lineInfo) -> void
4 changes: 3 additions & 1 deletion src/Controls/src/Core/PublicAPI/net/PublicAPI.Unshipped.txt
Original file line number Diff line number Diff line change
Expand Up @@ -209,4 +209,6 @@ Microsoft.Maui.Controls.PlatformPointerEventArgs
*REMOVED*Microsoft.Maui.Controls.Entry.SelectionLength.set -> void
Microsoft.Maui.Controls.Xaml.RequireServiceAttribute
~Microsoft.Maui.Controls.Xaml.RequireServiceAttribute.RequireServiceAttribute(System.Type[] serviceTypes) -> void
~Microsoft.Maui.Controls.Xaml.RequireServiceAttribute.ServiceTypes.get -> System.Type[]
~Microsoft.Maui.Controls.Xaml.RequireServiceAttribute.ServiceTypes.get -> System.Type[]
~Microsoft.Maui.Controls.ResourceDictionary.SetAndCreateSource<T>(System.Uri value) -> void
*REMOVED*~Microsoft.Maui.Controls.ResourceDictionary.SetAndLoadSource(System.Uri value, string resourcePath, System.Reflection.Assembly assembly, System.Xml.IXmlLineInfo lineInfo) -> void
Original file line number Diff line number Diff line change
Expand Up @@ -214,3 +214,5 @@ Microsoft.Maui.Controls.ContentPage.HideSoftInputOnTapped.set -> void
*REMOVED*Microsoft.Maui.Controls.Entry.SelectionLength.get -> int
*REMOVED*Microsoft.Maui.Controls.Entry.SelectionLength.set -> void

~Microsoft.Maui.Controls.ResourceDictionary.SetAndCreateSource<T>(System.Uri value) -> void
*REMOVED*~Microsoft.Maui.Controls.ResourceDictionary.SetAndLoadSource(System.Uri value, string resourcePath, System.Reflection.Assembly assembly, System.Xml.IXmlLineInfo lineInfo) -> void
12 changes: 10 additions & 2 deletions src/Controls/src/Core/ResourceDictionary.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,17 @@ public Uri Source
}

//Used by the XamlC compiled converter
/// <include file="../../docs/Microsoft.Maui.Controls/ResourceDictionary.xml" path="//Member[@MemberName='SetAndLoadSource']/Docs/*" />
/// <include file="../../docs/Microsoft.Maui.Controls/ResourceDictionary.xml" path="//Member[@MemberName='SetAndCreateSource']/Docs/*" />
[EditorBrowsable(EditorBrowsableState.Never)]
public void SetAndLoadSource(Uri value, string resourcePath, Assembly assembly, global::System.Xml.IXmlLineInfo lineInfo)
public void SetAndCreateSource<T>(Uri value)
where T : ResourceDictionary, new()
{
_source = value;
_mergedInstance = s_instances.GetValue(typeof(T), _ => (ResourceDictionary)new T());
OnValuesChanged(_mergedInstance.ToArray());
}

internal void SetAndLoadSource(Uri value, string resourcePath, Assembly assembly, global::System.Xml.IXmlLineInfo lineInfo)
{
_source = value;

Expand Down