コード例 #1
0
        public PersonVM(PropModelType pm, ViewModelFactoryInterface viewModelFactory,
                        IPropBagMapperService autoMapperService, IPropFactory propFactory, string fullClassName)
            : base(pm, viewModelFactory, autoMapperService, propFactory, fullClassName)
        {
            //System.Diagnostics.Debug.WriteLine("PersonVM is being created with a PropModel.");

            //////IList<string> pNamesFromOurProvider = TypeInspectorUtility.GetPropertyNames
            //////    (_typeDescriptionProvider.GetTypeDescriptor(this));

            ////ICustomTypeDescriptor ourCustomTypeDescriptor = _typeDescriptionProvider.GetTypeDescriptor(this);
            ////IList<string> pNamesFromOurProvider = TypeInspectorUtility.GetPropertyNames
            ////    (ourCustomTypeDescriptor);

            //IList<string> pNamesFromOurPropModel = TypeInspectorUtility.GetPropertyNames
            //    (pm.CustomTypeDescriptor);

            ////IList<string> pNamesFromAppDomain_WT = TypeInspectorUtility.GetPropertyNames
            ////    (typeof(PersonVM), this);

            ////IList<string> pNamesFromAppDomain_WT = TypeInspectorUtility.GetPropertyNames
            ////    (this.GetType(), this);

            //IList<string> pNamesFromAppDomain = TypeInspectorUtility.GetPropertyNames
            //    (this);
        }
コード例 #2
0
        // BaseType + PropModel (BaseType known at compile time.)
        public object GetNewViewModel <BT>(PropModelType propModel, ViewModelFactoryInterface viewModelFactory,
                                           object propBagAutoMapperService, IPropFactory propFactory = null, string fcnOverride = null) where BT : class, IPropBag
        {
            object result = GetNewViewModel(typeof(BT), propModel, viewModelFactory, propBagAutoMapperService, propFactory, fcnOverride);

            return(result);
        }
コード例 #3
0
        static public PerformanceModel Create(PropBagTypeSafetyMode safetyMode, ViewModelFactoryInterface viewModelFactory)
        {
            AutoMapperHelpers ourHelper      = new AutoMapperHelpers();
            IPropFactory      propFactory_V1 = ourHelper.GetNewPropFactory_V1();

            PropModelType propModel = new PropModel
                                      (
                "PerformanceModel",
                "PropBagLib.Tests",
                DeriveFromClassModeEnum.Custom,
                typeof(PerformanceModel),
                propFactory_V1,
                propFactoryType: null,
                propModelCache: null,
                typeSafetyMode: safetyMode,
                deferMethodRefResolution: true,
                requireExplicitInitialValue: true
                                      );

            long generationId = viewModelFactory.PropModelCache.Add(propModel);

            PerformanceModel pmViewModel = new PerformanceModel(propModel, viewModelFactory);

            pmViewModel.AddPropNoStore <int>("PropIntNoStore");
            pmViewModel.AddPropNoStore <string>("PropStringNoStore");
            pmViewModel.AddProp <int>("PropInt");
            pmViewModel.AddProp <string>("PropString");

            pmViewModel.FixProps();

            return(pmViewModel);
        }
コード例 #4
0
        public void Test1()
        {
            AutoMapperHelpers ourHelper      = new AutoMapperHelpers();
            IPropFactory      propFactory_V1 = ourHelper.GetNewPropFactory_V1();

            PropModel pm = new PropModel
                           (
                className: "CreateAtRunTimeModel",
                namespaceName: "PropBagLib.Tests",
                deriveFrom: DeriveFromClassModeEnum.PropBag,
                targetType: null,
                propFactory: propFactory_V1,
                propFactoryType: null,
                propModelCache: null,
                typeSafetyMode: PropBagTypeSafetyMode.AllPropsMustBeRegistered,
                deferMethodRefResolution: true,
                requireExplicitInitialValue: true);

            PropItemModel pi = new PropItemModel(typeof(string), "PropString",
                                                 PropStorageStrategyEnum.Internal, propKind: PropKindEnum.Prop, initialValueField: new PropInitialValueField("Initial Value"));

            pm.Add(pi.PropertyName, pi);


            ViewModelFactoryInterface viewModelFactory = ourHelper.ViewModelFactory;

            viewModelFactory.PropModelCache.Add(pm);

            mod1 = new CreateAtRunTimeModel(pm, viewModelFactory);

            Assert.That(mod1, Is.Not.EqualTo(null), "Expected the CreateAtRunTimeModel to have been created.");

            Assert.That(mod1.PropertyExists("PropString"), Is.True, "Expected the property with name = 'PropString' to have been create.");
        }
コード例 #5
0
        private static IPropBagMapperService GetAutoMapperProvider(ViewModelFactoryInterface viewModelFactory)
        {
            IAutoMapperBuilderProvider autoMapperBuilderProvider = new SimpleAutoMapperBuilderProvider();
            IAutoMapperCache           rawAutoMapperCache        = new SimpleAutoMapperCache();
            SimpleAutoMapperService    autoMapperService         = new SimpleAutoMapperService
                                                                   (
                autoMapperBuilderProvider: autoMapperBuilderProvider,
                autoMapperCache: rawAutoMapperCache,
                mapperConfigurationLookupService: null
                                                                   );

            IMapTypeDefinitionProvider mapTypeDefinitionProvider = new SimpleMapTypeDefinitionProvider();

            IPropBagMapperBuilderProvider propBagMapperBuilderProvider = new SimplePropBagMapperBuilderProvider();
            ICachePropBagMappers          mappersCachingService        = new SimplePropBagMapperCache(viewModelFactory);
            IPropBagMapperService         propBagMapperService         = new SimplePropBagMapperService
                                                                         (
                mapTypeDefinitionProvider: mapTypeDefinitionProvider,
                mapperBuilderProvider: propBagMapperBuilderProvider,
                mappersCachingService: mappersCachingService,
                autoMapperService: autoMapperService
                                                                         );

            return(propBagMapperService);
        }
コード例 #6
0
ファイル: DestinationModels.cs プロジェクト: drminor/propbag
 public DestinationModel1(PropModelType pm, ViewModelFactoryInterface viewModelFactory,
                          IPropBagMapperService autoMapperService, IPropFactory propFactory, string fullClassName)
     : base(pm, viewModelFactory, autoMapperService, propFactory, fullClassName)
 {
     TryOpenPropSet();
     AddProp <int>("NewAfterFixedProp", null, null, 0);
     TryFixPropSet();
 }
コード例 #7
0
        public MainWindowViewModel(PropModelType pm, ViewModelFactoryInterface viewModelFactory, IPropBagMapperService autoMapperService)
            : base(pm, viewModelFactory, autoMapperService)
        {
            //System.Diagnostics.Debug.WriteLine("Beginning to construct MainWindowViewModel -- From PropModel.");


            //System.Diagnostics.Debug.WriteLine("Completed Constructing MainWindowViewModel -- From PropModel.");
        }
コード例 #8
0
ファイル: MainViewModel.cs プロジェクト: drminor/propbag
        //private MainViewModel() { } // Shows that if no default constructor is available, the one that takes a single byte is use.

        // If it not desirable to provide a public, default, parameterless constructor,
        // a consructor that takes a single byte can be used instead.
        // NOTE: Neither of these constructors is required if an instance of this class already exists from the proerty
        // marked with the PropBagInstanceAttribute.
        // An instance of this class must be available so that we create an instance of a Action<T,T> delegate.
        //public MainViewModel(byte dummy) : base(dummy) {}

        /// <summary>
        /// Constructor used by View to create with properties
        /// </summary>
        /// <param name="pm"></param>
        public MainViewModel(PropModelType pm, ViewModelFactoryInterface viewModelFactory,
                             IPropBagMapperService propBagMapperService, IPropFactory propFactory, string fullClassName)
            : base(pm, viewModelFactory, propBagMapperService, propFactory, fullClassName)
        {
            this.PropFirstDidChange    = false;
            this.PropMyStringDidChange = false;
            this.PropMyPointDidChange  = false;
        }
コード例 #9
0
        //public DestinationModel3(PropBagTypeSafetyMode typeSafetyMode, PSAccessServiceCreatorInterface storeAccessCreator,
        //    string fullClassName, IPropFactory propFactory)
        //    : base(typeSafetyMode, storeAccessCreator, propFactory, fullClassName)
        //{
        //    AddProp<Guid>("ProductId", null, null, Guid.NewGuid());
        //    AddProp<int>("Amount", null, null, initialValue: 0);
        //    AddProp<double>("Size", null, null, 10.1);
        //    AddProp<MyModel4>("Deep", null, null, null);
        //}



        public DestinationModel3(PropModelType pm, ViewModelFactoryInterface viewModelFactory,
                                 IPropBagMapperService autoMapperService, IPropFactory propFactory, string fullClassName)
            : base(pm, viewModelFactory, autoMapperService, propFactory, fullClassName)
        {
            //AddProp<Guid>("ProductId", null, null, Guid.NewGuid());
            //AddProp<int>("Amount", null, null, initialValue: 0);
            //AddProp<double>("Size", null, null, 10.1);
            //AddProp<MyModel4>("Deep", null, null, null);
        }
コード例 #10
0
        public IPropBagMapper <TSource, TDestination> GeneratePropBagMapper
        (
            IPropBagMapperRequestKey <TSource, TDestination> mapperRequestKey,
            ViewModelFactoryInterface viewModelFactory
        )
        {
            var result = _propBagMapperBuilder.BuildPropBagMapper(mapperRequestKey, viewModelFactory);

            return(result);
        }
コード例 #11
0
 public IPropBagMapperService GetAutoMapperSetup_V1()
 {
     if (_autoMapperProvider_V1 == null)
     {
         ViewModelFactoryInterface viewModelFactory = ViewModelFactory;
         _autoMapperProvider_V1             = new AutoMapperHelpers().InitializeAutoMappers(viewModelFactory);
         ViewModelFactory.AutoMapperService = _autoMapperProvider_V1;
     }
     return(_autoMapperProvider_V1);
 }
コード例 #12
0
        public SimplePropBagMapperCache(ViewModelFactoryInterface viewModelFactory)
        {
            _viewModelFactory = viewModelFactory ?? throw new ArgumentNullException(nameof(viewModelFactory));

            _requests =
                new LockingConcurrentDictionary <IPropBagMapperRequestKeyGen, IPropBagMapperRequestKeyGen>(RequestFactory);

            _propBagMappers =
                new LockingConcurrentDictionary <IPropBagMapperRequestKeyGen, IPropBagMapperGen>(MapperFactory);
        }
コード例 #13
0
        public void Z_BindParent()
        {
            AutoMapperHelpers ourHelper = new AutoMapperHelpers();

            IPropBagMapperService autoMapperService = ourHelper.GetAutoMapperSetup_V1();

            IPropFactory        propFactory_V1     = ourHelper.GetNewPropFactory_V1();
            ICreateWrapperTypes wrapperTypeCreator = ourHelper.GetWrapperTypeCreator_V1();

            ViewModelFactoryInterface viewModelFactory = ourHelper.ViewModelFactory;

            //viewModelFactory.PropModelCache.Add(propModel5);
            _propModelCache = viewModelFactory.PropModelCache;


            Assert.That(ourHelper.StoreAccessCreator.AccessCounter == 0, "The Provider of PropStoreAccessServices has not had its Access Counter reset.");

            List <DestinationModel1> destinationList = new List <DestinationModel1>();



            PropModelHelpers pmHelpers = new PropModelHelpers();

            // Set up Child VM (Using Model 5)
            PropModelType propModel5 = pmHelpers.GetPropModelForModel5Dest(propFactory_V1, _propModelCache);


            DestinationModel5 testChildVM = new DestinationModel5(pm: propModel5, viewModelFactory: viewModelFactory, autoMapperService: autoMapperService, propFactory: propFactory_V1, fullClassName: "PropBagLib.Tests.PerformanceDb.DestinationModel5");

            Business b = new Business();

            testChildVM.SetIt(b, "Business");
            testChildVM.RegisterBinding <Business>("Business", "../Business");

            //List<Person> personList = b.Get().ToList();
            //ObservableCollection<Person> personList2 = new ObservableCollection<Person>(personList);
            //testChildVM.SetIt(personList2, "PersonCollection");


            // Set up MainVM (Using Model 6)
            PropModelType     propModel6 = pmHelpers.GetPropModelForModel6Dest(propFactory_V1, _propModelCache);
            DestinationModel6 testMainVM = new DestinationModel6(propModel6, viewModelFactory, autoMapperService, propFactory_V1, null);

            Business b2 = new Business();

            testMainVM.SetIt(b2, "Business");


            testMainVM.SetIt <DestinationModel5>(testChildVM, "ChildVM");
            testMainVM.RegisterBinding <Business>("Business", "./ChildVM/Business");

            b2 = new Business();
            testMainVM.SetIt(b2, "Business");
        }
コード例 #14
0
        public void SetupAutoMapperSupport_V1()
        {
            AutoMapperHelpers ourHelper = new AutoMapperHelpers();

            _propFactory_V1        = ourHelper.PropFactory_V1;
            _amp                   = ourHelper.GetAutoMapperSetup_V1();
            _wrapperTypeCreator_V1 = ourHelper.GetWrapperTypeCreator_V1();
            PropModelCacheInterface _propModelCache = ourHelper.GetPropModelCache_V1();

            _viewModelFactory = ourHelper.ViewModelFactory;
        }
コード例 #15
0
        public object GetNewViewModel(Type typeToCreate, PropModelType propModel, ViewModelFactoryInterface viewModelFactory,
                                      object propBagAutoMapperService, IPropFactory propFactory, string fcnOverride)
        {
            object[] parameters = new object[] { propModel, viewModelFactory, propBagAutoMapperService, propFactory, fcnOverride };

            //BindingFlags bFlags = BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.CreateInstance;
            //object result = Activator.CreateInstance(typeToCreate, bFlags, binder: null, args: parameters, culture: null);

            object result = Activator.CreateInstance(typeToCreate, args: parameters);

            return(result);
        }
コード例 #16
0
        public PersonVM(PropModelType pm, ViewModelFactoryInterface viewModelFactory,
                        IPropBagMapperService autoMapperService, IPropFactory propFactory, string fullClassName)
            : base(pm, viewModelFactory, autoMapperService, propFactory, fullClassName)
        {
            //PropBagTypeDescriptionProvider<PersonVM> tdp = RegisterTypeDescriptorProvider<PersonVM>(pm);
            //pm.TypeDescriptionProvider = tdp;
            //TypeDescriptor.AddProvider(tdp, this);

            //List<string> pNamesFromOurProvider = tdp.GetPropertyDescriptors(this).Select(x => x.Name).ToList();

            //List<string> pNamesFromOurPropModel = pm.PropertyDescriptors.Select(x => x.Name).ToList();

            //List<string> pNames = TypeInspectorUtility.GetPropertyNames(this);

            //System.Diagnostics.Debug.WriteLine("PersonVM is being created with a PropModel.");
        }
コード例 #17
0
        private IPropBagMapperGen BuildPropBagMapperGen
        (
            IPropBagMapperRequestKeyGen mapRequestGen,
            ViewModelFactoryInterface viewModelFactory
        )
        {
            IPropBagMapperRequestKey <TSource, TDestination> mapRequestTyped
                = mapRequestGen as IPropBagMapperRequestKey <TSource, TDestination>;

            if (mapRequestTyped == null)
            {
                throw new InvalidOperationException($"{nameof(mapRequestGen)} does not implement the correct typed {nameof(IPropBagMapperRequestKey<TSource, TDestination>)} interface.");
            }

            return(BuildPropBagMapper(mapRequestTyped, viewModelFactory));
        }
コード例 #18
0
        public void CanRegisterMod3ToDestinationMapper_Proxy()
        {
            IPropFactory propFactory = _propFactory_V1;
            ViewModelFactoryInterface viewModelFactory = _viewModelFactory;

            PropModel propModel         = GetPropModelForModel3Dest(propFactory);
            Type      typeToWrap        = typeof(PropBag);
            string    configPackageName = "Emit_Proxy";

            //IMapperRequest mr = new MapperRequest(typeof(MyModel3), propModel, configPackageName);

            IPropBagMapperRequestKeyGen mapperRequest =
                _amp.SubmitPropBagMapperRequest(propModel, typeof(MyModel3), configPackageName);


            Assert.That(mapperRequest, Is.Not.Null, "mapperRequest should be non-null.");
        }
コード例 #19
0
        public PersonEditorViewModel(PropModelType pm, ViewModelFactoryInterface viewModelFactory,
                                     IPropBagMapperService autoMapperService, IPropFactory propFactory, string fullClassName)
            : base(pm, viewModelFactory, autoMapperService, propFactory, fullClassName)
        {
            //PropBagTypeDescriptionProvider<PersonEditorViewModel> tdp = RegisterTypeDescriptorProvider<PersonEditorViewModel>(pm);
            //pm.TypeDescriptionProvider = tdp;
            //TypeDescriptor.AddProvider(tdp, this);

            //List<string> pNamesFromOurProvider = tdp.GetPropertyDescriptors(this).Select(x => x.Name).ToList();

            //List<string> pNamesFromOurPropModel = pm.PropertyDescriptors.Select(x => x.Name).ToList();

            //List<string> pNames = TypeInspectorUtility.GetPropertyNames(this);

            _commands = new List <RelayCommand>();

            System.Diagnostics.Debug.WriteLine("Constructing PersonEditorViewModel -- with PropModel.");
        }
コード例 #20
0
 public SimplePropBagMapper
 (
     PropModelType propModel,
     IMapper mapper,
     ViewModelFactoryInterface viewModelFactory,
     IPropBagMapperService propBagMapperService,
     IConfigureAMapper <TSource, TDestination> mappingConfiguration
 )
     : base
     (
         propModel,
         mapper,
         viewModelFactory,
         propBagMapperService,
         mappingConfiguration
     )
 {
 }
コード例 #21
0
        public PersonCollectionViewModel(PropModelType pm, ViewModelFactoryInterface viewModelFactory,
                                         IPropBagMapperService autoMapperService, IPropFactory propFactory, string fullClassName)
            : base(pm, viewModelFactory, autoMapperService, propFactory, fullClassName)
        {
            System.Diagnostics.Debug.WriteLine("Constructing PersonCollectionViewModel -- with PropModel.");

            //IList<string> pNamesFromOurProvider = TypeInspectorUtility.GetPropertyNames
            //    (_typeDescriptionProvider.GetTypeDescriptor(this));

            //IList<string> pNamesFromOurPropModel = TypeInspectorUtility.GetPropertyNames
            //    (pm.CustomTypeDescriptor);

            //IList<string> pNamesFromAppDomain_WT = TypeInspectorUtility.GetPropertyNames
            //    (typeof(PersonCollectionViewModel), this);

            //IList<string> pNamesFromAppDomain = TypeInspectorUtility.GetPropertyNames
            //    (this);
        }
コード例 #22
0
        // Regular Instantiation using the PropModel.
        //private TDestination GetNewDestination(Type destinationOrProxyType, PropModelType propModel, PSAccessServiceCreatorInterface storeAccessCreator, IProvideAutoMappers autoMapperService, ICreateWrapperTypes wrapperTypeCreator, IPropFactory propFactory, string fullClassName)

        private TDestination GetNewDestination(Type destinationOrProxyType, PropModelType propModel,
                                               ViewModelFactoryInterface viewModelFactory, IPropBagMapperService propBagMapperService,
                                               IPropFactory propFactory, string fullClassName)
        {
            ViewModelActivatorInterface vmActivator = viewModelFactory.ViewModelActivator;

            try
            {
                //var newViewModel =  _vmActivator.GetNewViewModel(destinationOrProxyType, propModel, viewModelFactory, propFactory, fullClassName);

                var newViewModel = vmActivator.GetNewViewModel(destinationOrProxyType, propModel, viewModelFactory, propBagMapperService, propFactory, fullClassName);

                return(newViewModel as TDestination);
            }
            catch (Exception e2)
            {
                //Type targetType = destinationOrProxyType ?? typeof(TDestination);
                throw new InvalidOperationException($"Cannot create an instance of {destinationOrProxyType} that takes a PropModel argument.", e2);
            }
        }
コード例 #23
0
        public Type TargetRunTimeType => DestinationType;  //=> RunTimeType;

        #endregion

        #region Constructor

        public AbstractPropBagMapper
        (
            PropModelType propModel,
            IMapper mapper,
            ViewModelFactoryInterface viewModelFactory,
            IPropBagMapperService propBagMapperService,
            IConfigureAMapper <TSource, TDestination> mappingConfiguration
        )
        {
            SourceType      = typeof(TSource);
            DestinationType = typeof(TDestination);

            PropModel = propModel;               //(PropModelType) mapRequest.DestinationTypeDef.UniqueRef;

            PropFactory = PropModel.PropFactory; // (IPropFactory)mapRequest.DestinationTypeDef.PropFactory;

            Mapper = mapper;

            _viewModelFactory     = viewModelFactory;
            _propBagMapperService = propBagMapperService;
            _mappingConfiguration = mappingConfiguration;

            SupportsMapFrom = true;

            _requiresWrappperTypeEmitServices = _mappingConfiguration.RequiresWrappperTypeEmitServices;

            CheckRequiresEmitted(_requiresWrappperTypeEmitServices, DestinationType);

            _mct.Measure();

            _destPropBagTemplate = GetDestinationTemplate(DestinationType);

            _mct.MeasureAndReport("GetNewDestination(PropModel, ... [In Constructor]", "AbstractPropBagMapper");

            // Working on see if we can get the SupportsMapFrom from the Mapper itself.
            //TypePair tp = new TypePair(SourceType, DestinationType);
            //IObjectMapper mpr = mapper.ConfigurationProvider.FindMapper(tp);

            return;
        }
コード例 #24
0
ファイル: BasicVMTests.cs プロジェクト: drminor/propbag
        protected override void Because_Of()
        {
            //mainWindowPropModel = PropModelCache.GetPropModel("MainWindowVM");

            string className = "MainWindowVM";
            string fcn       = GetFullClassName(DefaultNamespace, className, ConfigPackageNameSuffix);

            if (!PropModelCache.TryGetPropModel(fcn, out mainWindowPropModel))
            {
                throw new KeyNotFoundException($"Could not find a PropModel with Full Class Name = {fcn}.");
            }
            BaseMemTracker.CompactMeasureAndReport("After get mainWindow_PropModel.", "CreateVM_CreateMainWindowVM_Run1");


            ViewModelFactoryInterface viewModelFactory = ViewModelFactory;

            mainWindowViewModel = new MainWindowViewModel(mainWindowPropModel, viewModelFactory, PropBagMapperService);
            BaseMemTracker.CompactMeasureAndReport("After create the mainWindowViewModel.", "CreateVM_CreateMainWindowVM_Run1");

            mainWindowViewModel.Dispose();
            BaseMemTracker.CompactMeasureAndReport("After dispose of the mainWindowViewModel.", "CreateVM_CreateMainWindowVM_Run1");
        }
コード例 #25
0
        public MainWindowViewModel(PropModelType pm, ViewModelFactoryInterface viewModelFactory,
                                   IPropBagMapperService autoMapperService, IPropFactory propFactory, string fullClassName)
            : base(pm, viewModelFactory, autoMapperService, propFactory, fullClassName)
        {
            //System.Diagnostics.Debug.WriteLine("Beginning to construct MainWindowViewModel -- From PropModel.");

            //IHaveADbContext dBActivator = new DBActivator<PersonDB>(System.Environment.SpecialFolder.CommonApplicationData);
            //PersonDB personDb = (PersonDB)dBActivator.DbContext;
            //PersonDAL b = new PersonDAL(personDb);
            //SetIt(b, "Business");

            //PropBagTypeDescriptionProvider<MainWindowViewModel> tdp = RegisterTypeDescriptorProvider<MainWindowViewModel>(pm);
            //pm.TypeDescriptionProvider = tdp;
            //TypeDescriptor.AddProvider(tdp, this);

            //List<string> pNamesFromOurProvider = tdp.GetPropertyDescriptors(this).Select(x => x.Name).ToList();

            //List<string> pNamesFromOurPropModel = pm.PropertyDescriptors.Select(x => x.Name).ToList();

            //List<string> pNames = TypeInspectorUtility.GetPropertyNames(this);

            System.Diagnostics.Debug.WriteLine("Completed Constructing MainWindowViewModel -- From PropModel.");
        }
コード例 #26
0
        // Create a new PropBagMapper
        public IPropBagMapper <TSource, TDestination> BuildPropBagMapper
        (
            IPropBagMapperRequestKey <TSource, TDestination> mapperRequestKey,
            ViewModelFactoryInterface viewModelFactory
        )
        {
            CheckTypeToCreate("source", typeof(TSource), mapperRequestKey.SourceType);
            CheckTypeToCreate("destination", typeof(TDestination), mapperRequestKey.DestinationType);

            PropModelType propModel = mapperRequestKey.PropModel;
            IMapper       theMapper = mapperRequestKey.AutoMapper;

            IPropBagMapper <TSource, TDestination> result
                = new SimplePropBagMapper <TSource, TDestination>
                  (
                      propModel,
                      theMapper,
                      viewModelFactory,
                      _propBagMapperService,
                      mapperRequestKey.MappingConfiguration
                  );

            return(result);
        }
コード例 #27
0
        public void CanGetMapperForMod3ToDestination_Proxy()
        {
            IPropFactory propFactory = _propFactory_V1;
            ViewModelFactoryInterface viewModelFactory = _viewModelFactory;

            PropModel propModel = GetPropModelForModel3Dest(propFactory);

            viewModelFactory.PropModelCache.Add(propModel);

            Type   typeToWrap        = typeof(PropBag);
            string configPackageName = "Emit_Proxy";

            IMapperRequest mapperRequest = new MapperRequest(typeof(MyModel3), propModel, configPackageName);

            Type et = _wrapperTypeCreator_V1.GetWrapperType(propModel, typeToWrap);

            propModel.NewEmittedType = et;

            IPropBagMapperRequestKeyGen mapperKey = _amp.SubmitPropBagMapperRequest(mapperRequest.PropModel,
                                                                                    mapperRequest.SourceType, mapperRequest.ConfigPackageName);

            // Get the AutoMapper mapping function associated with the mapper request already submitted.
            IPropBagMapperGen genMapper = _amp.GetPropBagMapper(mapperKey);

            //IMapper genMapper = _amp.GetRawAutoMapper(mapperKey);

            Assert.That(mapperKey, Is.Not.Null, "mapperRequest should be non-null.");

            //IPropBagMapper<MyModel3, DestinationModel3> mapper = _amp.GetMapper<MyModel3, DestinationModel3>(mapperRequest);

            Assert.That(genMapper, Is.Not.Null, "mapper should be non-null");

            MyModel4 dp = new MyModel4
            {
                MyString = "This is a good thing."
            };

            MyModel3 testSource = new MyModel3
            {
                Amount    = 11,
                Size      = 22.22,
                ProductId = Guid.Empty,
                Deep      = dp
            };

            var testDest = genMapper.MapToDestination(testSource);

            //IPropBagMapperKey<MyModel3, DestinationModel3> mapperRequest2 =
            //    _amp.SubmitMapperRequest<MyModel3, DestinationModel3>
            //    (
            //        propModel: propModel,
            //        typeToWrap: typeToWrap,
            //        configPackageName: configPackageName
            //    );

            //IPropBagMapper<MyModel3, DestinationModel3> mapper2 = _amp.GetMapper<MyModel3, DestinationModel3>(mapperRequest2);

            IPropBagMapperRequestKeyGen mapperKey2 = _amp.SubmitPropBagMapperRequest(mapperRequest.PropModel,
                                                                                     mapperRequest.SourceType, mapperRequest.ConfigPackageName);

            // Get the AutoMapper mapping function associated with the mapper request already submitted.
            IPropBagMapperGen genMapper2 = _amp.GetPropBagMapper(mapperKey2);


            var testDest2 = genMapper2.MapToDestination(testSource);
        }
コード例 #28
0
        public void CanGetMapperForMod3ToDestination_Extra()
        {
            IPropFactory propFactory = _propFactory_V1;
            ViewModelFactoryInterface viewModelFactory = _viewModelFactory;

            PropModel propModel = GetPropModelForModel3Dest(propFactory);

            viewModelFactory.PropModelCache.Add(propModel);

            Type   typeToWrap        = typeof(DestinationModel3); // typeof(PropBag);
            string configPackageName = "Extra_Members";           // "Emit_Proxy";


            IMapperRequest mr = new MapperRequest(typeof(MyModel3), propModel, configPackageName);

            //IMapper rawAutoMapper = AutoMapperHelpers.GetAutoMapper<MyModel3, DestinationModel3>
            //    (
            //    mr,
            //    _amp,
            //    out IPropBagMapperKey<MyModel3, DestinationModel3> propBagMapperKey
            //    );

            //IPropBagMapper<MyModel3, DestinationModel3> cookedAutoMapper = new SimplePropBagMapper<MyModel3, DestinationModel3>
            //    (
            //    propBagMapperKey,
            //    rawAutoMapper,
            //    viewModelFactory,
            //    _amp
            //    );

            IPropBagMapper <MyModel3, DestinationModel3> propBagMapper = AutoMapperHelpers.GetAutoMapper <MyModel3, DestinationModel3>
                                                                         (
                mr,
                _amp,
                out IPropBagMapperRequestKey <MyModel3, DestinationModel3> propBagMapperKey
                                                                         );


            //IPropBagMapperKey<MyModel3, DestinationModel3> mapperRequest =
            //    _amp.SubmitMapperRequest<MyModel3, DestinationModel3>
            //    (
            //        propModel: propModel,
            //        viewModelFactory: viewModelFactory,
            //        typeToWrap: typeToWrap,
            //        configPackageName: configPackageName
            //    );

            Assert.That(propBagMapperKey, Is.Not.Null, "mapperRequest should be non-null.");

            //IPropBagMapper<MyModel3, DestinationModel3> mapper = _amp.GetMapper<MyModel3, DestinationModel3>(mapperRequest);

            Assert.That(propBagMapper, Is.Not.Null, "mapper should be non-null");

            MyModel4 dp = new MyModel4
            {
                MyString = "This is a good thing."
            };

            MyModel3 testSource = new MyModel3
            {
                Amount    = 11,
                Size      = 22.22,
                ProductId = Guid.Empty,
                Deep      = dp
            };


            DestinationModel3 testDest = propBagMapper.MapToDestination(testSource);

            //IPropBagMapperKey<MyModel3, DestinationModel3> mapperRequest2 =
            //    _amp.SubmitMapperRequest<MyModel3, DestinationModel3>
            //    (
            //        propModel: propModel,
            //        viewModelFactory: viewModelFactory,
            //        typeToWrap: typeToWrap,
            //        configPackageName: configPackageName
            //    );

            //IPropBagMapper<MyModel3, DestinationModel3> mapper2 = _amp.GetMapper<MyModel3, DestinationModel3>(mapperRequest2);


            IPropBagMapper <MyModel3, DestinationModel3> propBagMapper2 = AutoMapperHelpers.GetAutoMapper <MyModel3, DestinationModel3>
                                                                          (
                mr,
                _amp,
                out IPropBagMapperRequestKey <MyModel3, DestinationModel3> propBagMapperKey2
                                                                          );

            //IPropBagMapper<MyModel3, DestinationModel3> cookedAutoMapper2 = new SimplePropBagMapper<MyModel3, DestinationModel3>
            //    (
            //    propBagMapperKey,
            //    rawAutoMapper,
            //    viewModelFactory,
            //    _amp
            //    );

            DestinationModel3 testDest2 = propBagMapper2.MapToDestination(testSource);
        }
コード例 #29
0
        //public CreateAtRunTimeModel(PropBagTypeSafetyMode typeSafetyMode, PSAccessServiceCreatorInterface storeAccessCreator,
        //    IPropFactory propFactory, string fullClassName)
        //    : base(typeSafetyMode, storeAccessCreator, propFactory, fullClassName)
        //{
        //}

        public CreateAtRunTimeModel(PropModel pm, ViewModelFactoryInterface viewModelFactory)
            : base(pm, viewModelFactory, null, propFactory: null, fullClassName: "PropBagLib.Tests.CreateAtRunTimeModel")
        {
        }
コード例 #30
0
 public PubPropBag(PropModel pm, ViewModelFactoryInterface viewModelFactory, IPropBagMapperService propBagMapperService, IPropFactory propFactory, string fullClassName)
     : base(pm, viewModelFactory, propBagMapperService, propFactory, fullClassName)
 {
 }