public PropTypedBase(PropNameType propertyName, bool typeIsSolid, IPropTemplate <T> template) { PropertyName = propertyName; TypeIsSolid = typeIsSolid; ValueIsDefined = false; _template = template; }
public PropTypedBase(PropNameType propertyName, T initalValue, bool typeIsSolid, IPropTemplate <T> template) { PropertyName = propertyName; _value = initalValue; TypeIsSolid = typeIsSolid; ValueIsDefined = true; _template = template; }
public IPropTemplate GetOrAdd(IPropTemplate propTemplate) { ReportCacheHit(propTemplate); IPropTemplate result = _cache.GetOrAdd(propTemplate); return(result); }
public PropNoStore(PropNameType propertyName, bool typeIsSolid, IPropTemplate <T> template) : base(propertyName, typeIsSolid, template) { if (template.StorageStrategy == PropStorageStrategyEnum.Internal) { throw new InvalidOperationException($"This implementation of IProp<T> does not support the {nameof(PropStorageStrategyEnum.Internal)} StorageStrategy."); } _haveFetchedValue = false; }
public CViewProp(PropNameType propertyName, IProvideAView viewProvider, IPropTemplate <ListCollectionView> template) : base(propertyName, typeIsSolid: true, template: template) { _viewProvider = viewProvider; if (_viewProvider != null) { // TODO: Make this a weak event subscription. _viewProvider.ViewSourceRefreshed += OurViewProviderGotRefreshed; } }
protected virtual IPropTemplate <T> GetPropTemplate <T> ( PropKindEnum propKindEnum, PropStorageStrategyEnum storageStrategy, Func <T, T, bool> comparer, bool comparerIsRefEquality, Func <string, T> getDefaultVal ) { // Supply a comparer, if one was not supplied by the caller. bool comparerIsDefault; if (comparer == null) { comparer = EqualityComparer <T> .Default.Equals; comparerIsDefault = true; } else { comparerIsDefault = false; } bool defaultValFuncIsDefault; // Use the Get Default Value function supplied or provided by this Prop Factory. if (getDefaultVal == null) { getDefaultVal = ValueConverter.GetDefaultValue <T>; defaultValFuncIsDefault = true; } else { defaultValFuncIsDefault = false; } IPropTemplate <T> propTemplateTyped = new PropTemplateTyped <T> ( propKindEnum, storageStrategy, this.GetType(), comparerIsDefault, comparerIsRefEquality, comparer, getDefaultVal, defaultValFuncIsDefault ); IPropTemplate <T> existingEntry = (IPropTemplate <T>)DelegateCacheProvider.PropTemplateCache.GetOrAdd(propTemplateTyped); return(existingEntry); }
private void ReportCacheHit(IPropTemplate propTemplate) { lock (_sync) { if (!_cache.ContainsKey(propTemplate)) { System.Diagnostics.Debug.WriteLine($"Adding a new PropTemplate for type = {propTemplate.Type}; kind = {propTemplate.PropKind}."); } else { System.Diagnostics.Debug.WriteLine($"Using existing PropTemplate for type = {propTemplate.Type}; kind = {propTemplate.PropKind}."); } } }
public override IProp <T> CreateWithNoValue <T> ( PropNameType propertyName, object extraInfo, PropStorageStrategyEnum storageStrategy, bool typeIsSolid, Func <T, T, bool> comparer, bool comparerIsRefEquality, Func <string, T> getDefaultValFunc ) { IPropTemplate <T> propTemplate = GetPropTemplate <T>(PropKindEnum.Prop, storageStrategy, comparer, comparerIsRefEquality, getDefaultValFunc); IProp <T> prop; switch (storageStrategy) { case PropStorageStrategyEnum.Internal: { // Regular Prop with Internal Storage -- Just don't have a value as yet. prop = new Prop <T>(propertyName, typeIsSolid, propTemplate); break; } case PropStorageStrategyEnum.External: { // Create a Prop that uses an external storage source. prop = new PropExternStore <T>(propertyName, extraInfo, typeIsSolid, propTemplate); break; } case PropStorageStrategyEnum.Virtual: { // This is a Prop that supplies a Virtual (aka Caclulated) value from an internal source or from LocalBindings // This implementation simply creates a Property that will always have the default value for type T. prop = new PropNoStore <T>(propertyName, typeIsSolid, propTemplate); break; } default: { throw new InvalidOperationException($"{storageStrategy} is not supported or is not recognized."); } } return(prop); }
public override ICProp <CT, T> CreateWithNoValue <CT, T> ( PropNameType propertyName, object extraInfo, PropStorageStrategyEnum storageStrategy, bool typeIsSolid, Func <CT, CT, bool> comparer ) { // TODO: Get a real value for comparerIsReqEquality bool comparerIsRefEquality = false; IPropTemplate <CT> propTemplate = GetPropTemplate <CT>(PropKindEnum.ObservableCollection, storageStrategy, comparer, comparerIsRefEquality, getDefaultVal: null); ICProp <CT, T> prop = new CProp <CT, T>(propertyName, typeIsSolid, propTemplate); return(prop); }
public bool Equals(IPropTemplate other) { if (other == null) { return(false); } if (PropKind == other.PropKind && EqualityComparer <Type> .Default.Equals(Type, other.Type) && StorageStrategy == other.StorageStrategy && DefaultValFuncIsDefault == other.DefaultValFuncIsDefault && ComparerIsDefault == other.ComparerIsDefault && ComparerIsRefEquality == other.ComparerIsRefEquality) { if (!DefaultValFuncIsDefault) { if (!ReferenceEquals(GetDefaultValFuncProxy, other.GetDefaultValFuncProxy)) { return(false); } } else { if (!EqualityComparer <Type> .Default.Equals(PropFactoryType, other.PropFactoryType)) { return(false); } } if (!ComparerIsDefault && !ComparerIsRefEquality) { return(ReferenceEquals(ComparerProxy, other.ComparerProxy)); } else { return(true); } } else { return(false); } }
public override IProp <T> Create <T> ( T initialValue, PropNameType propertyName, object extraInfo, PropStorageStrategyEnum storageStrategy, bool typeIsSolid, Func <T, T, bool> comparer, bool comparerIsRefEquality, Func <string, T> getDefaultValFunc ) { IPropTemplate <T> propTemplate = GetPropTemplate <T>(PropKindEnum.Prop, storageStrategy, comparer, comparerIsRefEquality, getDefaultValFunc); propTemplate.PropCreator = CookedScalarPropCreator <T>; IProp <T> prop = new Prop <T>(propertyName, initialValue, typeIsSolid, propTemplate); return(prop); }
public override IProp <T> CreateWithNoValue <T> ( PropNameType propertyName, object extraInfo, PropStorageStrategyEnum storageStrategy, bool typeIsSolid, Func <T, T, bool> comparer, bool comparerIsRefEquality, Func <string, T> getDefaultValFunc ) { IPropTemplate <T> propTemplate = GetPropTemplate <T>(PropKindEnum.Prop, storageStrategy, comparer, comparerIsRefEquality, getDefaultValFunc); if (storageStrategy == PropStorageStrategyEnum.Internal) { propTemplate.PropCreator = CookedScalarPropCreatorNoVal <T>; } else { propTemplate.PropCreator = CookedScalarPropCreatorNoStore <T>; } if (storageStrategy == PropStorageStrategyEnum.Internal) { // Regular Prop with Internal Storage -- Just don't have a value as yet. IProp <T> prop = new Prop <T>(propertyName, typeIsSolid, propTemplate); return(prop); } else { // Prop With External Store, or this is a Prop that supplies a Virtual (aka Caclulated) value from an internal source or from LocalBindings // This implementation simply creates a Property that will always have the default value for type T. IProp <T> prop = new PropNoStore <T>(propertyName, typeIsSolid, propTemplate); return(prop); } }
private static IProp CookedScalarPropCreatorNoStore <T>(string propertyName2, object initialValue2, bool typeIsSolid2, IPropTemplate propTemplate2) { // Prop With External Store, or this is a Prop that supplies a Virtual (aka Caclulated) value from an internal source or from LocalBindings // This implementation simply creates a Property that will always have the default value for type T. IProp <T> prop = new PropNoStore <T>(propertyName2, typeIsSolid2, (IPropTemplate <T>)propTemplate2); return(prop); }
private static IProp CookedScalarPropCreatorNoVal <T>(string propertyName2, object initialValue2, bool typeIsSolid2, IPropTemplate propTemplate2) { // Regular Prop with Internal Storage -- Just don't have a value as yet. IProp <T> prop = new Prop <T>(propertyName2, typeIsSolid2, (IPropTemplate <T>)propTemplate2); return(prop); }
private IPropTemplate Factory(IPropTemplate propTemplate) { return(propTemplate); }
private static IProp CookedCVPropCreator(string propertyName2, object initialValue2, bool typeIsSolid2, IPropTemplate propTemplate2) { CViewProp result2 = new CViewProp(propertyName2, (IProvideAView)initialValue2, (IPropTemplate <ListCollectionView>)propTemplate2); return(result2); }
public override IProp CreateCVSProp(PropNameType propertyName, IProvideAView viewProvider, IPropTemplate propTemplate) { IEqualityComparer <CollectionViewSource> comparer = RefEqualityComparer <CollectionViewSource> .Default; bool comparerIsRefEquality = true; if (propTemplate == null) { propTemplate = GetPropTemplate <CollectionViewSource>(PropKindEnum.CollectionViewSource, PropStorageStrategyEnum.Internal, comparer.Equals, comparerIsRefEquality, null); } propTemplate.PropCreator = CookedCVSPropCreator; ICViewSourceProp <CollectionViewSource> result = new CViewSourceProp(propertyName, viewProvider, (IPropTemplate <CollectionViewSource>)propTemplate); return(result); }
//[System.Diagnostics.Conditional("DEBUG")] //private void CheckGenerationRef(PropNodeCollectionInternalInterface key, PropNodeCollectionInternalInterface basePropItemSet, GenerationIdType generationId) //{ // if (generationId == 0) // { // System.Diagnostics.Debug.Assert(ReferenceEquals(key, basePropItemSet), "The GenerationId is 0, but the base is not the same as the key."); // } // else // { // System.Diagnostics.Debug.Assert(!ReferenceEquals(key, basePropItemSet), "The GenerationId is not 0, but the base *is* the same as the key."); // } //} #endregion #region PropTemplate Support public IPropTemplate GetOrAdd(IPropTemplate propTemplate) { IPropTemplate result = _propTemplateCache.GetOrAdd(propTemplate); return(result); }
public CViewSourceProp(PropNameType propertyName, IProvideAView viewProvider, IPropTemplate <CollectionViewSource> template) : base(propertyName, typeIsSolid: true, template: template) { if (_template.StorageStrategy != PropStorageStrategyEnum.Virtual) { throw new InvalidOperationException($"CViewSource PropItems only support {nameof(PropStorageStrategyEnum.Virtual)}."); } _viewProvider = viewProvider; }
public CProp(PropNameType propertyName, CT initalValue, bool typeIsSolid, IPropTemplate <CT> template) : base(propertyName, initalValue, typeIsSolid, template) { }
public virtual IProp CreateCVProp(PropNameType propertyName, IProvideAView viewProvider, IPropTemplate propTemplate) { throw new NotImplementedException($"This implementation of {nameof(IPropFactory)} cannot create CVProps (CollectionView PropItems), please use WPFPropfactory or similar."); }
public override IProp CreateCVProp(string propertyName, IProvideAView viewProvider, IPropTemplate propTemplate) { IEqualityComparer <ListCollectionView> comparer = RefEqualityComparer <ListCollectionView> .Default; bool comparerIsRefEquality = true; if (propTemplate == null) { propTemplate = GetPropTemplate <ListCollectionView>(PropKindEnum.CollectionView, PropStorageStrategyEnum.Internal, comparer.Equals, comparerIsRefEquality, null); } propTemplate.PropCreator = CookedCVPropCreator; CViewProp result = new CViewProp(propertyName, viewProvider, (IPropTemplate <ListCollectionView>)propTemplate); return(result); }
// No initial value. public Prop(PropNameType propertyName, bool typeIsSolid, IPropTemplate <T> template) : base(propertyName, typeIsSolid, template) { }
private static IProp CookedScalarPropCreator <T>(string propertyName2, object initialValue2, bool typeIsSolid2, IPropTemplate propTemplate2) { IProp <T> prop2 = new Prop <T>(propertyName2, (T)initialValue2, typeIsSolid2, (IPropTemplate <T>)propTemplate2); return(prop2); }
public PropExternStore(string propertyName, object extraInfo, bool typeIsSolid, IPropTemplate <T> template) : base(propertyName, typeIsSolid, template) { _extraInfo = extraInfo; Tag = Guid.NewGuid(); // tag; Getter = null; // getter; Setter = null; // setter; ValueIsDefined = Getter != null; }