Created
July 22, 2011 14:34
-
-
Save DerAlbertCom/1099574 to your computer and use it in GitHub Desktop.
Private Property Setter Serialization with RavenDb.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using Raven.Client; | |
using Raven.Client.Document; | |
namespace Aperea.Infrastructure.Data | |
{ | |
public class DocumentSessionFactory : IDocumentSessionFactory | |
{ | |
readonly DocumentStore _documentStore; | |
public DocumentSessionFactory() | |
{ | |
_documentStore = new DocumentStore(); | |
_documentStore.ConnectionStringName = "RavenDb"; | |
_documentStore.Conventions.JsonContractResolver = new PrivateSetterContractResolver(true); | |
_documentStore.Initialize(); | |
} | |
public IDocumentSession CreateDocumentSession() | |
{ | |
return _documentStore.OpenSession("Foobar"); | |
} | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.Linq; | |
using System.Reflection; | |
using Newtonsoft.Json.Serialization; | |
namespace Aperea.Infrastructure.Data | |
{ | |
public class PrivateSetterContractResolver : DefaultContractResolver | |
{ | |
public PrivateSetterContractResolver(bool shareCache):base(shareCache) | |
{ | |
DefaultMembersSearchFlags = BindingFlags.Public | BindingFlags.Instance | BindingFlags.NonPublic; | |
} | |
protected override System.Collections.Generic.List<MemberInfo> GetSerializableMembers(System.Type objectType) | |
{ | |
return base.GetSerializableMembers(objectType).Where(m => m.MemberType == MemberTypes.Property).ToList(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment