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."); }
private PropModel GetPropModelForModel3Dest(IPropFactory propFactory) { PropModel result = new PropModel ( className: "DestinationModel3", namespaceName: "PropBagLib.Tests.AutoMapperSupport", deriveFrom: DeriveFromClassModeEnum.Custom, targetType: typeof(DestinationModel3), propFactory: propFactory, propFactoryType: null, propModelCache: null, typeSafetyMode: PropBagTypeSafetyMode.Tight, deferMethodRefResolution: true, requireExplicitInitialValue: true ); //result.Namespaces.Add("System"); result.Namespaces.Add("DRM.PropBag"); result.Namespaces.Add("DRM.TypeSafePropertyBag"); // ProductId (Guid - default) IPropInitialValueField pivf = PropInitialValueField.UseDefault; PropItemModel propItem = new PropItemModel(type: typeof(Guid), name: "ProductId", storageStrategy: PropStorageStrategyEnum.Internal, propKind: PropKindEnum.Prop, initialValueField: pivf); result.Add(propItem.PropertyName, propItem); // Amount (int - default) propItem = new PropItemModel(type: typeof(int), name: "Amount", storageStrategy: PropStorageStrategyEnum.Internal, propKind: PropKindEnum.Prop, initialValueField: pivf); result.Add(propItem.PropertyName, propItem); // Size (double - default) propItem = new PropItemModel(type: typeof(double), name: "Size", storageStrategy: PropStorageStrategyEnum.Internal, propKind: PropKindEnum.Prop, initialValueField: pivf); result.Add(propItem.PropertyName, propItem); // Deep (MyModel4 - null) pivf = PropInitialValueField.UseNull; propItem = new PropItemModel(type: typeof(MyModel4), name: "Deep", storageStrategy: PropStorageStrategyEnum.Internal, propKind: PropKindEnum.Prop, initialValueField: pivf); result.Add(propItem.PropertyName, propItem); return(result); }
public PropModelType GetPropModelForModel5Dest(IPropFactory propFactory, PropModelCacheInterface propModelCache) { PropModelType result = new PropModel ( className: "DestinationModel5", namespaceName: "PropBagLib.Tests.PerformanceDb", deriveFrom: DeriveFromClassModeEnum.Custom, targetType: typeof(DestinationModel5), propFactory: propFactory, propFactoryType: null, propModelCache: null, typeSafetyMode: PropBagTypeSafetyMode.Tight, deferMethodRefResolution: true, requireExplicitInitialValue: true ); result.Namespaces.Add("System"); result.Namespaces.Add("DRM.PropBag"); result.Namespaces.Add("DRM.TypeSafePropertyBag"); // ProductId (Guid - default) IPropInitialValueField pivf = PropInitialValueField.UseDefault; PropItemModel propItem = new PropItemModel(type: typeof(Guid), name: "ProductId", storageStrategy: PropStorageStrategyEnum.Internal, propKind: PropKindEnum.Prop, initialValueField: pivf); result.Add(propItem.PropertyName, propItem); // Business (Business - null) pivf = PropInitialValueField.UseNull; propItem = new PropItemModel(type: typeof(Business), name: "Business", storageStrategy: PropStorageStrategyEnum.Internal, propKind: PropKindEnum.Prop, initialValueField: pivf); result.Add(propItem.PropertyName, propItem); // PersonCollection (ObservableCollection<Person> - null) propItem = new PropItemModel(type: typeof(ObservableCollection <Person>), name: "PersonCollection", storageStrategy: PropStorageStrategyEnum.Internal, propKind: PropKindEnum.ObservableCollection, initialValueField: pivf, itemType: typeof(Person)); result.Add(propItem.PropertyName, propItem); result.Open(); propModelCache.Add(result); return(result); }
public PropModelType GetPropModelForModel1Dest(IPropFactory propFactory, PropModelCacheInterface propModelCache) { PropModelType result = new PropModel ( className: "DestinationModel1", namespaceName: "PropBagLib.Tests.PerformanceDb", deriveFrom: DeriveFromClassModeEnum.Custom, targetType: typeof(DestinationModel1), propFactory: propFactory, propFactoryType: null, propModelCache: null, //propModelCache, typeSafetyMode: PropBagTypeSafetyMode.Tight, deferMethodRefResolution: true, requireExplicitInitialValue: true ); result.Namespaces.Add("System"); result.Namespaces.Add("DRM.PropBag"); result.Namespaces.Add("DRM.TypeSafePropertyBag"); // Id (Int - 0) IPropInitialValueField pivf = new PropInitialValueField(initialValue: "0"); PropItemModel propItem = new PropItemModel(type: typeof(int), name: "Id", storageStrategy: PropStorageStrategyEnum.Internal, propKind: PropKindEnum.Prop, initialValueField: pivf); result.Add(propItem.PropertyName, propItem); pivf = PropInitialValueField.UseNull; // First Name (string - null) propItem = new PropItemModel(type: typeof(string), name: "FirstName", storageStrategy: PropStorageStrategyEnum.Internal, propKind: PropKindEnum.Prop, initialValueField: pivf); result.Add(propItem.PropertyName, propItem); // Last Name (string - null) propItem = new PropItemModel(type: typeof(string), name: "LastName", storageStrategy: PropStorageStrategyEnum.Internal, propKind: PropKindEnum.Prop, initialValueField: pivf); result.Add(propItem.PropertyName, propItem); // City Of Residence (string - null) propItem = new PropItemModel(type: typeof(string), name: "CityOfResidence", storageStrategy: PropStorageStrategyEnum.Internal, propKind: PropKindEnum.Prop, initialValueField: pivf); result.Add(propItem.PropertyName, propItem); pivf = PropInitialValueField.UseDefault; // Profession propItem = new PropItemModel(type: typeof(Profession), name: "Profession", storageStrategy: PropStorageStrategyEnum.Internal, propKind: PropKindEnum.Prop, initialValueField: pivf); result.Add(propItem.PropertyName, propItem); result.Open(); propModelCache.Add(result); return(result); }
public PropModelType GetPropModelForModel6Dest(IPropFactory propFactory, PropModelCacheInterface propModelCache) { PropModelType result = new PropModel ( className: "DestinationModel6", namespaceName: "PropBagLib.Tests.PerformanceDb", deriveFrom: DeriveFromClassModeEnum.Custom, targetType: typeof(DestinationModel6), propFactory: propFactory, propFactoryType: null, propModelCache: null, typeSafetyMode: PropBagTypeSafetyMode.Tight, deferMethodRefResolution: true, requireExplicitInitialValue: true ); result.Namespaces.Add("System"); result.Namespaces.Add("DRM.PropBag"); result.Namespaces.Add("DRM.TypeSafePropertyBag"); // Business (Business - null) IPropInitialValueField pivf = PropInitialValueField.UseNull; PropItemModel propItem = new PropItemModel(type: typeof(Business), name: "Business", storageStrategy: PropStorageStrategyEnum.Internal, propKind: PropKindEnum.Prop, initialValueField: pivf); result.Add(propItem.PropertyName, propItem); //// PersonCollection (ObservableCollection<Person> - null) //pivf = new PropInitialValueField(initialValue: null, // setToDefault: false, setToUndefined: false, setToNull: true, setToEmptyString: false); //propItem = new PropItem(type: typeof(ObservableCollection<Person>), name: "PersonCollection", // hasStore: true, propKind: PropKindEnum.Collection, // propTypeInfoField: null, // initialValueField: pivf, // doWhenChanged: null, extraInfo: null, comparer: null, itemType: typeof(Person)); //result.Props.Add(propItem); // ChildVM (DestinationModel5 - null) propItem = new PropItemModel(type: typeof(DestinationModel5), name: "ChildVM", storageStrategy: PropStorageStrategyEnum.Internal, propKind: PropKindEnum.Prop, initialValueField: pivf); result.Add(propItem.PropertyName, propItem); // SelectedPerson (Business - null) propItem = new PropItemModel(type: typeof(Person), name: "SelectedPerson", storageStrategy: PropStorageStrategyEnum.Internal, propKind: PropKindEnum.Prop, initialValueField: pivf); result.Add(propItem.PropertyName, propItem); // WMessage (String - null) propItem = new PropItemModel(type: typeof(string), name: "WMessage", storageStrategy: PropStorageStrategyEnum.Internal, propKind: PropKindEnum.Prop, initialValueField: pivf); result.Add(propItem.PropertyName, propItem); result.Open(); propModelCache.Add(result); return(result); }
private IPropItemModel ProcessProp(IPropTemplateItem pi, DoWhenChangedHelper doWhenChangedHelper) { PropStorageStrategyEnum storageStrategy = pi.StorageStrategy; bool typeIsSolid = pi.TypeIsSolid; string extraInfo = pi.ExtraInfo; IPropItemModel rpi = new PropItemModel ( type: pi.PropertyType, name: pi.PropertyName, storageStrategy: storageStrategy, typeIsSolid: typeIsSolid, propKind: pi.PropKind, propTypeInfoField: null, initialValueField: null, extraInfo: extraInfo, comparer: null, itemType: null, binderField: null, mapperRequest: null, propCreator: null ); bool isCProp = pi.PropKind.IsCollection(); bool foundTypeInfoField = false; ItemCollection items = ((PropItem)pi).Items; foreach (Control uc in items) { // ToDo: Find and process this field first, and then enter the enclosing foreach loop. // because one day, some of the other processing may depend on the PropertyType. // Type Info Field if (uc is DRM.PropBagControlsWPF.TypeInfoField tif) { foundTypeInfoField = true; Type propertyType = GetTypeFromInfoField(tif, pi.PropKind, pi.PropertyType, out Type itemType); if (isCProp) { rpi.CollectionType = propertyType; rpi.ItemType = itemType; } else { rpi.PropertyType = propertyType; rpi.ItemType = null; } } // Initial Value Field else if (uc is InitialValueField ivf) { IPropInitialValueField rivf; // TODO: Add error handling here. if (ivf.PropBagFullClassName != null) { rivf = PropInitialValueField.FromPropBagFCN(ivf.PropBagFullClassName); } else if (ivf.CreateNew) { rivf = PropInitialValueField.UseCreateNew; } else { rivf = new PropInitialValueField(ivf.InitialValue, ivf.SetToDefault, ivf.SetToUndefined, ivf.SetToNull, ivf.SetToEmptyString); } rpi.InitialValueField = rivf; } // Do When Changed Field else if (uc is DRM.PropBagControlsWPF.PropDoWhenChangedField dwc) { MethodInfo mi = doWhenChangedHelper.GetMethodAndSubKind(dwc, rpi.PropertyType, rpi.PropertyName, out SubscriptionKind subscriptionKind); SubscriptionPriorityGroup priorityGroup = dwc?.DoAfterNotify ?? false ? SubscriptionPriorityGroup.Last : SubscriptionPriorityGroup.Standard; IPropDoWhenChangedField rdwc = new DRM.PropBag.PropDoWhenChangedField ( target: null, method: mi, subscriptionKind: subscriptionKind, priorityGroup: priorityGroup, methodIsLocal: true, declaringType: null, fullClassName: null, instanceKey: null ); rpi.DoWhenChangedField = rdwc; } // Comparer Field else if (uc is DRM.PropBagControlsWPF.PropComparerField pcf) { IPropComparerField rpcf = new PropBag.PropComparerField(pcf.ComparerFunc.Comparer, pcf.UseRefEquality); rpi.ComparerField = rpcf; } // Local Binder Field else if (uc is DRM.PropBagControlsWPF.PropBinderField binderField) { IPropBinderField rBinderField = new PropBag.PropBinderField(binderField.Path); rpi.BinderField = rBinderField; rpi.MapperRequestResourceKey = binderField.MapperRequestResourceKey; } } if (!foundTypeInfoField) { if (isCProp) { Type propertyType = GetTypeFromInfoField(null, pi.PropKind, pi.PropertyType, out Type itemType); rpi.CollectionType = propertyType; rpi.ItemType = itemType; } else if (pi.PropKind == PropKindEnum.CollectionView) { rpi.PropertyType = typeof(ListCollectionView); rpi.CollectionType = rpi.PropertyType; rpi.ItemType = pi.PropertyType; } else { // TODO: Check other PropKinds. // Do Nothing. } } return(rpi); }