Browse Source
add support for CreateSourceInfo in design window loader (#21972 )
* feat: add support for CreateSourceInfo in design window loader
* Move XAML SourceInfo default to RuntimeXamlLoaderConfiguration
Applies to all designer/runtime load paths now; newer VS and VS Code designers do not use DesignWindowLoader.
---------
Co-authored-by: Kim Henrik <KimHenrik@outlook.de>
Co-authored-by: Julien Lebosquain <julien@lebosquain.net>
pull/22014/head
Unrealiter
2 months ago
committed by
GitHub
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with
29 additions and
2 deletions
src/Avalonia.Build.Tasks/XamlCompilerTaskExecutor.cs
src/Markup/Avalonia.Markup.Xaml/RuntimeXamlLoaderConfiguration.cs
@ -157,6 +157,12 @@ namespace Avalonia.Build.Tasks
var arg1 = new CustomAttributeArgument ( strType , "AvaloniaUseCompiledBindingsByDefault" ) ;
var arg2 = new CustomAttributeArgument ( strType , defaultCompileBindings . ToString ( ) ) ;
asm . CustomAttributes . Add ( new CustomAttribute ( ctor ) { ConstructorArguments = { arg1 , arg2 } } ) ;
if ( createSourceInfo )
{
var arg3 = new CustomAttributeArgument ( strType , "AvaloniaXamlCreateSourceInfo" ) ;
var arg4 = new CustomAttributeArgument ( strType , createSourceInfo . ToString ( ) ) ;
asm . CustomAttributes . Add ( new CustomAttribute ( ctor ) { ConstructorArguments = { arg3 , arg4 } } ) ;
}
}
TypeDefinition AddClass ( string name , TypeAttributes extraAttributes = 0 )
@ -1,10 +1,16 @@
using System ;
using System.Linq ;
using System.Reflection ;
namespace Avalonia.Markup.Xaml ;
public class RuntimeXamlLoaderConfiguration
{
/// <summary>
/// When enabled, the XAML compiler embeds SourceInfo metadata (file path, line, and column) into generated code.
/// </summary>
private bool? _ createSourceInfo = null ;
/// <summary>
/// Default assembly for clr-namespace:.
/// </summary>
@ -24,9 +30,24 @@ public class RuntimeXamlLoaderConfiguration
/// <summary>
/// When enabled, the XAML compiler embeds SourceInfo metadata (file path, line, and column) into generated code.
/// Default is 'false' .
/// When not explicitly set, the 'AvaloniaXamlCreateSourceInfo' from the LocalAssembly will be used to determine the value .
/// </summary>
public bool CreateSourceInfo { get ; set ; } = false ;
public bool CreateSourceInfo
{
get {
if ( _ createSourceInfo = = null )
{
if ( LocalAssembly is { } asm )
{
var createSourceInfo = asm . GetCustomAttributes < AssemblyMetadataAttribute > ( )
. FirstOrDefault ( a = > a . Key = = "AvaloniaXamlCreateSourceInfo" ) ? . Value ;
return bool . TryParse ( createSourceInfo , out var parsedCreateSourceInfo ) & & parsedCreateSourceInfo ;
}
}
return _ createSourceInfo ? ? false ;
}
set = > _ createSourceInfo = value ;
}
/// <summary>
/// XAML diagnostics handler.