コード例 #1
0
        /// <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));
            }
        }
コード例 #2
0
    /// <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);
        }
    }
コード例 #3
0
    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
    }
コード例 #4
0
ファイル: MapOptions.cs プロジェクト: jamietre/IQObjectMapper
 /// <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;
     }
 }
コード例 #5
0
ファイル: MapOptions.cs プロジェクト: jamietre/IQObjectMapper
 /// <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);
 }
コード例 #6
0
ファイル: MapOptions.cs プロジェクト: jamietre/IQObjectMapper
        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;
            }
        }
コード例 #7
0
ファイル: Dict2Poco.cs プロジェクト: jamietre/IQObjectMapper
 public Dict2Poco(IMapOptions options=null)
 {
     Options = MapOptions.From(options);
 }
コード例 #8
0
 public AdapterOptionsBuilder(IMapOptions mapOptions)
 {
     this.mapOptions = mapOptions;
 }
コード例 #9
0
ファイル: ClassInfoBuilder.cs プロジェクト: vebin/IQMap
 public ClassInfoBuilder(IMapOptions options, Type type)
     : base(options, type)
 {
 }