/// <summary> /// Will map the View, ViewModel to a key /// </summary> protected virtual void NavigationMap <View, ViewModel>(string key, IMapOptions options = null) where View : IView where ViewModel : IViewModel { lock (_viewsByKey) { var noHistory = options == null ? false : options.NoHistory; var cacheView = options == null ? false : options.CacheView; var platform = options == null ? null : options.Platform; // Map Key with View if (!string.IsNullOrEmpty(key)) { var definition = new TypeDefinition() { Type = typeof(View), NoHistory = noHistory, CacheView = cacheView, Platform = platform }; var tupleKey = Abstraction.Tuple.Create(key, platform); if (_viewsByKey.ContainsKey(tupleKey)) { _viewsByKey[tupleKey] = definition; } else { _viewsByKey.Add(tupleKey, definition); } } // Map View and ViewModel _viewService.Map(typeof(View), typeof(ViewModel)); } }
/// <summary> /// Automatic resolve the property map. /// </summary> /// <param name="sourceProperty"></param> /// <param name="to"></param> /// <param name="options"></param> /// <exception cref="NotImplementedException"></exception> private void ResolvePropertyMap(FromSourceProperty sourceProperty, Type to, IMapOptions options) { try { var propertyOptions = options.GetOrCreatePropertyOptions(sourceProperty.Property); propertyOptions.TargetProperty = to.SelectProperty(sourceProperty.Property.Name); ResolveMapAction(propertyOptions); sourceProperty.UseOptions(propertyOptions); } catch (Exception ex) { throw new UnmappablePropertyException(sourceProperty.Property, to, ex); } }
public void TryResolve(Type from, Type to, IMapOptions options) // here, the options must exists for the key FromType, ToType and Adapter Kind !!! { var fromSourceProperties = FromSourceProperty.FromType(from); foreach (var sourceProperty in fromSourceProperties) { var propertyOptions = options.GetPropertyOptions(sourceProperty.Property); if (propertyOptions is not null && propertyOptions.TargetProperty != null) { if (propertyOptions.Action == PropertyMapAction.Undefined) { ResolveMapAction(propertyOptions); } sourceProperty.UseOptions(propertyOptions); } ResolvePropertyMap(sourceProperty, to, options); } // every source property is resolved now, // so, it is time to create the expressions }
/// <summary> /// Create a new options object based on another object implementing IGlobalOptions /// </summary> /// <param name="options"></param> /// <returns></returns> public static MapOptions From(IMapOptions options) { if (options is MapOptions && !ReferenceEquals(options, ObjectMapper.DefaultOptions)) { // just pass through the object if it's a concrete instance, and not the default object. return (MapOptions)options; } else { var opts = new MapOptions(); Copy(options, opts, true); return opts; } }
/// <summary> /// Copy the default options to any object implementing one of the options interfaces. Objects that do not implement /// any of the interfaces will be unchanged. /// </summary> /// <param name="options"></param> /// <returns></returns> public static void DefaultsTo(IMapOptions target) { Copy(null, target,true); }
public static void Copy(IMapOptions source, IMapOptions target, bool withDefaults=true) { if (source == null) { return; } MapOptions defaults = ObjectMapper.DefaultOptions; IReflectionOptions moSource = source as IReflectionOptions ?? defaults; IReflectionOptions moTarget = target as IReflectionOptions; if (moTarget!=null) { moTarget.IncludeFields = moSource.IncludeFields; moTarget.IncludePrivate = moSource.IncludePrivate; moTarget.IncludeProperties = moSource.IncludeProperties; moTarget.DeclaredOnly = moSource.DeclaredOnly; moTarget.CaseSensitive = moSource.CaseSensitive; } IGlobalOptions goSource = source as IGlobalOptions ?? defaults; IGlobalOptions goTarget = target as IGlobalOptions; if (goTarget!=null) { goTarget.FailOnMismatchedTypes = goSource.FailOnMismatchedTypes; goTarget.DynamicObjectType = goSource.DynamicObjectType; goTarget.ParseValues = goSource.ParseValues; goTarget.UndefinedValue = goSource.UndefinedValue; } IDictionaryOptions doSource = source as IDictionaryOptions ?? defaults; IDictionaryOptions doTarget = target as IDictionaryOptions; if (doTarget!=null) { doTarget.UpdateSource = doSource.UpdateSource; doTarget.CanAlterProperties = doSource.CanAlterProperties; doTarget.IsReadOnly = doSource.IsReadOnly; doTarget.CanAccessMissingProperties = doSource.CanAccessMissingProperties; } }
public Dict2Poco(IMapOptions options=null) { Options = MapOptions.From(options); }
public AdapterOptionsBuilder(IMapOptions mapOptions) { this.mapOptions = mapOptions; }
public ClassInfoBuilder(IMapOptions options, Type type) : base(options, type) { }