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); }
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); }