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