Type Resolution
Assembly Type Resolver
// Add all types, which are derived from AvaloniaObject, in the Avalonia.Controls.dll
// to the type resolver.
var resolver = new GenericTypeResolver<Button>();Custom Type Resolver
// #1 Use Resolver.
public class CustomTypeResolver1 : Resolver
{
// Nothing to do.
}
// #2 Implement IResolver.
public class CustomTypeResolver2 : IResolver
{
protected Dictionary<string, Type> Types;
protected Resolver()
{
Types = new Dictionary<string, Type>();
}
public bool TryAddType(string name, Type type)
{
if (Types.ContainsKey(name))
{
return false;
}
Types.Add(name, type);
return true;
}
public bool TryAddType<T>(string name)
{
if (Types.ContainsKey(name))
{
return false;
}
Types.Add(name, typeof(T));
return true;
}
public bool TryGetType(string name, out Type? type)
{
return Types.TryGetValue(name, out type);
}
public IEnumerable<Type> GetAllTypes()
{
return Types.Values;
}
}Adding Types to the Resolver Service
Single Type
Registering a type parser to Managed Services
Registering types when building Avalonia services
Last updated