public TypeAdapterSetter When(Func <PreCompileArgument, bool> canMap) { var rule = new TypeAdapterRule { Priority = arg => canMap(arg) ? (int?)25 : null, Settings = new TypeAdapterSettings(), }; this.Rules.LockAdd(rule); return(new TypeAdapterSetter(rule.Settings, this)); }
public TypeAdapterSetter When(Func <Type, Type, MapType, bool> canMap) { var rule = new TypeAdapterRule { Priority = arg => canMap(arg.SourceType, arg.DestinationType, arg.MapType) ? (int?)25 : null, Settings = new TypeAdapterSettings(), }; this.Rules.LockAdd(rule); return(new TypeAdapterSetter(rule.Settings, this)); }
public TypeAdapterSetter When(Func <Type, Type, MapType, bool> canMap) { var rule = new TypeAdapterRule { Priority = (srcType, destType, mapType) => canMap(srcType, destType, mapType) ? (int?)25 : null, Settings = new TypeAdapterSettings(), }; this.Rules.Add(rule); return(new TypeAdapterSetter(rule.Settings, this)); }
public TypeAdapterSetter <TSource, TDestination> ForType <TSource, TDestination>() { var key = new TypeTuple(typeof(TSource), typeof(TDestination)); TypeAdapterRule rule; if (!this.Dict.TryGetValue(key, out rule)) { lock (this.Dict) { if (!this.Dict.TryGetValue(key, out rule)) { rule = new TypeAdapterRule { Priority = (sourceType, destinationType, mapType) => { var score1 = GetSubclassDistance(destinationType, typeof(TDestination), this.AllowImplicitDestinationInheritance); if (score1 == null) { return(null); } var score2 = GetSubclassDistance(sourceType, typeof(TSource), true); if (score2 == null) { return(null); } return(score1.Value + score2.Value); }, Settings = new TypeAdapterSettings { DestinationType = typeof(TDestination) }, }; this.Rules.Add(rule); this.Dict.Add(key, rule); } } } return(new TypeAdapterSetter <TSource, TDestination>(rule.Settings, this)); }