Adjust project structure
This commit is contained in:
1 parent
d38912f5da
commit
e3c436f939
2111 files changed
+14028
-47199
No files matched your search
@@ -0,0 +1,59 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Globalization;
|
||||
|
||||
namespace HandyControl.Expression.Media
|
||||
{
|
||||
public sealed class GeometryEffectConverter : TypeConverter
|
||||
{
|
||||
private static readonly Dictionary<string, GeometryEffect> RegisteredEffects;
|
||||
|
||||
static GeometryEffectConverter()
|
||||
{
|
||||
var dictionary = new Dictionary<string, GeometryEffect>
|
||||
{
|
||||
{
|
||||
"None",
|
||||
GeometryEffect.DefaultGeometryEffect
|
||||
},
|
||||
{
|
||||
"Sketch",
|
||||
new SketchGeometryEffect()
|
||||
}
|
||||
};
|
||||
RegisteredEffects = dictionary;
|
||||
}
|
||||
|
||||
public override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceType)
|
||||
{
|
||||
return typeof(string).IsAssignableFrom(sourceType);
|
||||
}
|
||||
|
||||
public override bool CanConvertTo(ITypeDescriptorContext context, Type destinationType)
|
||||
{
|
||||
return typeof(string).IsAssignableFrom(destinationType);
|
||||
}
|
||||
|
||||
public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value)
|
||||
{
|
||||
if (value is string key && RegisteredEffects.TryGetValue(key, out var effect))
|
||||
return effect.CloneCurrentValue();
|
||||
return null;
|
||||
}
|
||||
|
||||
public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value,
|
||||
Type destinationType)
|
||||
{
|
||||
if (typeof(string).IsAssignableFrom(destinationType))
|
||||
{
|
||||
if (value is string) return value;
|
||||
foreach (var pair in RegisteredEffects)
|
||||
if (pair.Value?.Equals(value as GeometryEffect) ?? value == null)
|
||||
return pair.Key;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user