A cross-platform UI framework for .NET
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

45 lines
1.1 KiB

namespace Perspex.Xaml.MarkupExtensions
{
using System;
using Glass;
using OmniXaml;
using OmniXaml.Attributes;
using OmniXaml.Typing;
[ContentProperty("TargetType")]
public class TypeExtension : MarkupExtension
{
public Type Type { get; set; }
public TypeExtension()
{
}
public TypeExtension(Type type)
{
Type = type;
}
public string TypeName { get; set; }
private Type ResolveFromString(string typeLocator, IXamlTypeRepository typeRepository)
{
Guard.ThrowIfNull(typeLocator, nameof(typeLocator));
var prefixAndType = typeLocator.Dicotomize(':');
var xamlType = typeRepository.GetByPrefix(prefixAndType.Item1, prefixAndType.Item2);
return xamlType.UnderlyingType;
}
public override object ProvideValue(MarkupExtensionContext markupExtensionContext)
{
if (Type != null)
{
return Type;
}
return ResolveFromString(TypeName, markupExtensionContext.TypeRepository);
}
}
}