我想在枚举时将enum序列化为int值。
所以我已经实施了ISolrFieldSerializer来执行此操作,正如建议here。但我似乎可以在Windsor容器中注册它,然后由SolrNet使用
这就是我所拥有的:
虽然它出现在容器组件列表中,但除了序列化程序没有使用之外,这种方法还可以。有什么想法吗?
container.Register(Component.For<ISolrFieldSerializer>().ImplementedBy<SolrEnumSerializer>());
Startup.Init<SearchBox>("http://10.10.10.10:0000/solr/boxes");
container.Register(Component.For<ISolrOperations<SearchBox>>()
.UsingFactoryMethod(k => ServiceLocator.Current.GetInstance<ISolrOperations<SearchBox>>()));
答案 0 :(得分:3)
我通过删除默认实现并将其替换为自定义实现来对此进行排序:
Startup.Container.Remove<ISolrFieldSerializer>();
var fieldSerializer = new CustomSerializer();
Startup.Container.Register<ISolrFieldSerializer>(c => fieldSerializer);
自定义Sertializer:
public class CustomSerializer : ISolrFieldSerializer
{
private readonly AggregateFieldSerializer _serializer;
public CustomSerializer()
{
_serializer = new AggregateFieldSerializer(new ISolrFieldSerializer[]
{
new MyCustom1Serializer(),
new MyCustom2Serializer(),
new CollectionFieldSerializer(this),
new GenericDictionaryFieldSerializer(this),
new NullableFieldSerializer(new BoolFieldSerializer()),
new NullableFieldSerializer(new DateTimeFieldSerializer()),
//new MoneyFieldSerializer(),
new FormattableFieldSerializer(),
new TypeConvertingFieldSerializer(),
});
}
public bool CanHandleType(Type t)
{
return _serializer.CanHandleType(t);
}
public IEnumerable<PropertyNode> Serialize(object obj)
{
return _serializer.Serialize(obj);
}
}