/// <summary>Gets a value for the property from the container</summary> /// <param name="container">container</param> /// <param name="lazyDefaultFactory">default value factory delegate to create the default value if the value is not yet present as an extended property</param> /// <returns>Value retrieved from the property or default value created by <paramref name="lazyDefaultFactory"/> if it wasn't found</returns> /// <remarks>If the value didn't exist a new value created by calling with <paramref name="lazyDefaultFactory"/> is added to the container</remarks> public T GetValueFrom([ValidatedNotNull] IExtensiblePropertyContainer container, Func <T> lazyDefaultFactory) { container.ValidateNotNull(nameof(container)); lazyDefaultFactory.ValidateNotNull(nameof(lazyDefaultFactory)); if (container.TryGetExtendedPropertyValue(Name, out T retVal)) { return(retVal); } retVal = lazyDefaultFactory( ); container.AddExtendedPropertyValue(Name, retVal); return(retVal); }
public T GetValueFrom([ValidatedNotNull] IExtensiblePropertyContainer container, LazyDefaultFactory lazyDefaultFactory) { container.ValidateNotNull(nameof(container)); lazyDefaultFactory.ValidateNotNull(nameof(lazyDefaultFactory)); if (container.TryGetExtendedPropertyValue(Name, out T existingValue)) { return(existingValue); } var defaultValue = lazyDefaultFactory( ); container.AddExtendedPropertyValue(Name, defaultValue); return(defaultValue); }
/// <summary>Sets the value of an extended property in a container</summary> /// <param name="container">Container to set the value in</param> /// <param name="value">value of the property</param> public void SetValueIn([ValidatedNotNull] IExtensiblePropertyContainer container, T value) { container.ValidateNotNull(nameof(container)); container.AddExtendedPropertyValue(Name, value); }