public override string ToPresentation(JobMode jobMode) { var values = GetPresentableCharacteristics(jobMode, withDontClone: true) .Select(c => CharacteristicPresenter.ToPresentation(jobMode, c)); return(string.Join(Separator, values)); }
public override string ToPresentation(JobMode jobMode) { var values = GetPresentableCharacteristics(jobMode) .Select(c => c.Id + EqualsSeparator + CharacteristicPresenter.ToPresentation(jobMode, c)); return(string.Join(Separator, values)); }
public override string ToPresentation(JobMode jobMode) { var values = GetPresentableCharacteristics(jobMode, includeIgnoreOnApply: true) .Select(c => CharacteristicPresenter.ToPresentation(jobMode, c)); return(string.Join(Separator, values)); }
private void DetachFromOwner(Characteristic thisCharacteristic) { AssertNotFrozen(); if (IsPropertyBag) { throw new InvalidOperationException("The property bag has no owner."); } if (Owner == null) { return; } var oldValues = sharedValues; owner = null; sharedValues = new Dictionary <Characteristic, object>(); frozen = false; oldValues.Remove(thisCharacteristic); foreach (var characteristic in GetCharacteristicsToApply()) { object value; if (oldValues.TryGetValue(characteristic, out value)) { oldValues.Remove(characteristic); SetValueCore(characteristic, value); } } }
public override string ToPresentation(JobMode jobMode, Characteristic characteristic) { // TODO: DO NOT hardcode Characteristic suffix var id = characteristic.Id; var type = characteristic.DeclaringType.FullName; var value = SourceCodeHelper.ToSourceCode(characteristic[jobMode]); return($"{type}.{id}Characteristic[job] = {value}"); }
internal override object ResolveValueCore(JobMode obj, object currentValue) { if (Resolver == null) { return((T)base.ResolveValueCore(obj, currentValue)); } return(Resolver(obj, (T)base.ResolveValueCore(obj, currentValue))); }
public T Resolve <T>(JobMode jobMode, Characteristic <T> characteristic) { var resolver = resolvers.FirstOrDefault(r => r.CanResolve(characteristic)); if (resolver != null) { return(resolver.Resolve(jobMode, characteristic)); } throw new InvalidOperationException($"There is no default resolver for {characteristic.FullId}"); }
private IEnumerable <Characteristic> GetCharacteristicsToApply(JobMode other) { var result = other.GetCharacteristicsToApply(); if (GetType() != other.GetType() && !IsPropertyBag) { result = result.Intersect(this.GetAllCharacteristics()); } return(result); }
public override string ToPresentation(JobMode jobMode, Characteristic characteristic) { if (!jobMode.HasValue(characteristic)) { return("Default"); } var value = characteristic[jobMode]; return((value as IFormattable)?.ToString(null, HostEnvironmentInfo.MainCultureInfo) ?? value?.ToString() ?? ""); }
private void SetOwnerCore(JobMode newOwnerJob) { if (newOwnerJob == null) { throw new ArgumentNullException(nameof(newOwnerJob)); } AssertNotFrozen(); newOwnerJob.AssertIsNonFrozenRoot(); owner = newOwnerJob; sharedValues = newOwnerJob.sharedValues; frozen = false; }
public T Resolve <T>(JobMode jobMode, Characteristic <T> characteristic) { if (jobMode.HasValue(characteristic)) { return(characteristic[jobMode]); } Func <object> resolver; if (resolvers.TryGetValue(characteristic, out resolver)) { return((T)resolver()); } throw new InvalidOperationException($"There is no default resolver for {characteristic.FullId}"); }
protected static string ResolveId(JobMode obj, string actual) { if (!string.IsNullOrEmpty(actual) && actual != IdCharacteristic.FallbackValue) { return(actual); } var result = CharacteristicSetPresenter.Display.ToPresentation(obj); if (result.Length == 0) { result = IdCharacteristic.FallbackValue; } return(result); }
private JobMode ApplyCore( [CanBeNull] JobMode other, [NotNull] IEnumerable <Characteristic> characteristicsToApply) { AssertNotFrozen(); if (other == null) { return(this); } foreach (var characteristic in characteristicsToApply) { object value; if (!other.sharedValues.TryGetValue(characteristic, out value)) { continue; } if (characteristic.HasChildCharacteristics) { if (!HasValue(characteristic)) { var jobMode = (JobMode)ResolveCore(characteristic, value); if (jobMode != null) { value = Activator.CreateInstance(jobMode.GetType()); } SetValueCore(characteristic, value); } } else { SetValueCore(characteristic, value); } } return(this); }
private JobMode ApplyCore( JobMode other, IEnumerable <Characteristic> characteristicsToApply) { if (other == null) { throw new ArgumentNullException(nameof(other)); } AssertNotFrozen(); foreach (var characteristic in characteristicsToApply) { object value; if (!other.sharedValues.TryGetValue(characteristic, out value)) { continue; } if (characteristic.HasChildCharacteristics) { if (!HasValue(characteristic)) { var jobMode = (JobMode)ResolveCore(characteristic, value); if (jobMode != null) { value = Activator.CreateInstance(jobMode.GetType()); } SetValueCore(characteristic, value); } } else if (!characteristic.DontClone) { SetValueCore(characteristic, value); } } return(this); }
private void AttachToOwner(JobMode newOwnerJob, Characteristic thisCharacteristic) { if (newOwnerJob == null) { throw new ArgumentNullException(nameof(newOwnerJob)); } if (IsPropertyBag) { throw new InvalidOperationException( $"The property bag {this} cannot be used as characteristic's value."); } AssertIsNonFrozenRoot(); newOwnerJob.AssertIsNonFrozenRoot(); var oldValues = sharedValues; newOwnerJob.SetValueOnAttach(thisCharacteristic, this); foreach (var pair in oldValues) { newOwnerJob.SetValueOnAttach(pair.Key, pair.Value); } }
public abstract string ToPresentation(JobMode jobMode, Characteristic characteristic);
public override string ToPresentation(JobMode jobMode, Characteristic characteristic) { return(jobMode.HasValue(characteristic) ? characteristic[jobMode]?.ToString() ?? "" : "Default"); }
public abstract string ToPresentation(JobMode jobMode);
public static IReadOnlyList <Characteristic> GetAllCharacteristics(this JobMode obj) => GetAllCharacteristics(obj.GetType());
internal virtual object ResolveValueCore(JobMode obj, object currentValue) => ReferenceEquals(currentValue, EmptyValue) ? FallbackValue : currentValue;
public new T this[JobMode obj] { get { return(obj.GetValue(this)); } set { obj.SetValue(this, value); } }
protected virtual IEnumerable <Characteristic> GetPresentableCharacteristics(JobMode jobMode, bool withDontClone = false) => jobMode .GetCharacteristicsWithValues() .Where(c => c.IsPresentableCharacteristic(withDontClone));
protected JobMode() { owner = null; sharedValues = new Dictionary <Characteristic, object>(); }
public CharacteristicSet(JobMode other) { Apply(other); }
protected JobMode ApplyCore(JobMode other) => ApplyCore( other, GetCharacteristicsToApply(other));
public void Apply(JobMode other) => ApplyCore(other);
public override string ToPresentation(JobMode jobMode, Characteristic characteristic) { return(jobMode.HasValue(characteristic) ? FolderNameHelper.ToFolderName(characteristic[jobMode]) : "Default"); }
protected virtual IEnumerable <Characteristic> GetPresentableCharacteristics(JobMode jobMode, bool includeIgnoreOnApply = false) => jobMode .GetCharacteristicsWithValues() .Where(c => c.IsPresentableCharacteristic(includeIgnoreOnApply));