Type Resolution
The service for type resolution is called ITypeResolverManager. It manages multiple Acss built-in and user-registered type resolvers (ITypeResolver).
In addition to the built-in type parsing of Acss, you need to register all the used types into AcssContext by yourself. Unregistered types will not be recognised and will be skipped. We provide several ways to register types for parsing.
NOTE
Currently we don't do namespace mapping, so there is a higher chance of type renaming. If this is the case, please manage your own aliases for the renamed types to avoid conflicts.
Assembly Type Resolver
We provide a very handy assembly type resolver GenericTypeResolver. It can add all the subclasses of the AvaloniaObject type in its assembly to the resolver by the anchored type. For example:
Custom Type Resolver
Users can inherit from the default implementation class Resolver, or implement the type parser interface IResolver to define a type parser. Example:
Adding Types to the Resolver Service
Once you have a type parser, you can add types to that parser.
Single Type
In the current version, we don't support simple registration of individual types, you have to use ITypeResolver, and we'll consider providing a simpler type registration API later.
Registering a type parser to Managed Services
As shown in the code below.
Registering types when building Avalonia services
As shown in the code, after adding the default AcssContext, you can add a type parser directly against the assembly.
Last updated
Was this helpful?