Closed humhei closed 6 years ago
Again, feel free to merge or let me know so I can merge/publish it
It seems that LiteDB (de)serialize directly with bson data and entity type(Also for properties) While we going through a json data middleware by jsonconverters
Maybe i only want to be able to use custom json converter(Inherited from FsharpJsonConverter
)
So i can do more custom convertions
@humhei I honestly wouldn't know why someone would want to customize the converter, we use JSON just as an internal layer to make the conversion easy to/from bson. In anycase, I will publish the new version asap
In my special case I use it for retrieve template datas.
I generate data from .fsx files and also sometime retrive from it I also sometimes retrieve data from database
I use this special converters to specfic The logic of retrieving where from or generating new datas
[<RequireQualifiedAccess>]
type RetrieveFrom =
| FromFsx = 0
| FromDB = 1
[<RequireQualifiedAccess>]
type Settable<'T> =
| Auto
| Manual of 'T
[<CustomEquality;NoComparison>]
type AutoSet<'T when 'T : equality> =
{
Kind: Settable<'T>
RetrieveFrom: RetrieveFrom
}
override x.Equals(y) =
match y with
| :? AutoSet<'T> as y ->
if x.RetrieveFrom = y.RetrieveFrom then
x.Kind = y.Kind
else
let fromFsx,fromDB =
match x.RetrieveFrom,y.RetrieveFrom with
| RetrieveFrom.FromFsx,RetrieveFrom.FromDB -> x,y
| RetrieveFrom.FromDB,RetrieveFrom.FromFsx -> y,x
| _, _ -> Logger.invalidToken()
match fromFsx.Kind,fromDB.Kind with
| Settable.Auto _, Settable.Auto -> false
| Settable.Manual _, Settable.Auto -> false
| Settable.Auto, Settable.Manual _ -> true
| Settable.Manual m1, Settable.Manual m2 -> m1 = m2
| _ -> false
override x.GetHashCode() =
Logger.notImplemented()
type AutoSetHangtagTemplate = AutoSet<HangtagTemplate option>
let converters =
let cv = new MyJsonConverter()
cv.RegisterType<AutoSetHangtagTemplate>(fun v ->
{v with RetrieveFrom = RetrieveFrom.FromDB}
)
cv
Maybe i am in wrong design patterns But i want to try it and make it flying for a while
Fixes #17