4 using System.Collections.Generic;
7 using SharpDX.DirectWrite;
9 using SharpYaml.Serialization;
10 using SharpYaml.Serialization.Serializers;
12 using SiliconStudio.Assets.Serializers;
13 using SiliconStudio.Core.Reflection;
14 using SiliconStudio.Core.Yaml;
15 using SiliconStudio.Paradox.Assets.Effect;
16 using SiliconStudio.Paradox.Assets.Effect.ValueGenerators;
17 using SiliconStudio.Paradox.Effects;
21 namespace SiliconStudio.Paradox.Assets.Serializers
23 [YamlSerializerFactory]
26 public override IYamlSerializable TryCreate(SerializerContext context,
ITypeDescriptor typeDescriptor)
28 var type = typeDescriptor.Type;
29 return CanVisit(type) ?
this : null;
31 protected override KeyValuePair<object, object> ReadDictionaryItem(ref ObjectContext objectContext, KeyValuePair<Type, Type> keyValueType)
33 var readPair = base.ReadDictionaryItem(ref objectContext, keyValueType);
35 if (readPair.Value != null && readPair.Value.GetType() == typeof(List<object>))
39 var newValueType = typeof(EffectParameterValuesGenerator<>).MakeGenericType(key.PropertyType);
42 foreach (var item
in (List<object>)readPair.Value)
43 newList.AddValue(key, item);
45 readPair =
new KeyValuePair<object, object>(readPair.Key, newList);
51 protected override void WriteDictionaryItem(ref ObjectContext objectContext, KeyValuePair<object, object> keyValue, KeyValuePair<Type, Type> types)
54 if (key != null && keyValue.Value != null)
56 var valueType = keyValue.Value.GetType();
57 if (valueType != typeof(List<object>) && valueType.IsGenericType && valueType.GetGenericTypeDefinition() == typeof(EffectParameterValuesGenerator<>))
60 var newTypes =
new KeyValuePair<Type, Type>(types.Key, typeof(List<object>));
62 var newKeyValue =
new KeyValuePair<object, object>(keyValue.Key, newList);
63 base.WriteDictionaryItem(ref objectContext, newKeyValue, newTypes);
68 base.WriteDictionaryItem(ref objectContext, keyValue, types);
71 public bool CanVisit(Type type)
79 context.Visitor.VisitObject(context.Instance, context.Descriptor,
false);
Key of an effect parameter.
Default implementation for a IEffectParameterGenerator using a dictionary of ParameterKey associated ...
A custom visitor used by DataVisitorBase.
Provides access members of a type.
SharpYaml.Serialization.ITypeDescriptor ITypeDescriptor
Generates values for a specific key.