Zero reflection usage
See original GitHub issueReflection is bad because:
- it’s really, really slow
- it bloats the code size for AOT-only scenarios
- it adds the need to add hints/configuration for IL linker in AOT scenarios
I’d like to completely remove reflection usage from Avalonia. We should be able to run with CoreRT without additional .rd.xml
files and with these compatibility flags disabled.
Right now our users of reflection are:
- Portable.Xaml (will be fixed by XamlIl)
- Bindings (we have compiled bindings now)
- Style selector parsers (will be fixed by XamlIl)
- Weak event managers
- StyleInclude/ResourceInclude
- DBus
- AssetsLoader
- Anything else?
There are two problems with bindings that we need to solve:
- If we want to have them compiled, we need to know the type of
DataContext
in advance. So we might need to add some kind of XAML directive (e. g.DataContextType="{x:Type myNs:MyType}"
) for specifying the data context type when it can’t be determined fromDataType
or from binding from the parentDataContext
. That would be most likely required for top-level XAML element only. - We have
IStreamPlugin
extension point which isn’t strongly typed and is resolved in runtime. We need to make it to somehow work at compile time.
While we are working on these, new features get added, so when adding a new feature that needs type information, provide a way for it to work at compile time.
Issue Analytics
- State:
- Created 5 years ago
- Reactions:30
- Comments:11 (10 by maintainers)
Top Results From Across the Web
reflect.Zero() Function in Golang with Examples
The reflect.Zero() Function in Golang is used to get the Value representing the zero value for the specified type. To access this function,...
Read more >reflect package
The typical use is to take a value with static type interface{} and ... Zero takes a Type and returns a Value representing...
Read more >java - What is reflection and why is it useful?
The name reflection is used to describe code which is able to inspect other code in the same system (or itself). For example,...
Read more >Reflection in Go: Everything you need to know to use it ...
Reflection in Go allows you to examine and manipulate variables and types while your program is running. This means that you can check...
Read more >Is it a bad habit to (over)use reflection?
Basically, avoid reflection in general code if at all possible; look for an improved design. Share.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@Mrxx99 we aren’t planning to drop F# support. Source generators will be used for generating fields for
x:Name
, however.I think implementing compile-time bindings would be great. I had some experience lately with
x:Bind
in UWP and while it has its issues, it’s very appealing. It also significantly reduces the need for converters, as the binding expression is converted to a C# method, and so can include method calls, casts, etc.The data context problem was solved by changing the binding context to the class the XAML file is attached to, and you’d usually have one or more strongly-typed properties in it (e.g.
ViewModel
), instead of theDataContext
. ForDataTemplates
, theDataType
is used.Code is generated at design/compile time. I’m not sure if MS intends on open-sourcing the
x:Bind
implementation (it’s a part of the XAML MSBuild tasks, but only in UWP.) Perhaps it’s worth asking.