コード例 #1
0
            public override string ToPresentation(CharacteristicObject obj)
            {
                var values = GetPresentableCharacteristics(obj)
                             .Select(c => c.Id + "=" + CharacteristicPresenter.ToPresentation(obj, c));

                return(string.Join(Separator, values));
            }
コード例 #2
0
        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);
                }
            }
        }
コード例 #3
0
        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)));
        }
コード例 #4
0
            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}");
            }
コード例 #5
0
        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}");
        }
コード例 #6
0
        private IEnumerable <Characteristic> GetCharacteristicsToApply(CharacteristicObject other)
        {
            var result = other.GetCharacteristicsToApply();

            if (GetType() != other.GetType() && !IsPropertyBag)
            {
                result = result.Intersect(this.GetAllCharacteristics());
            }

            return(result);
        }
コード例 #7
0
            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");
            }
コード例 #8
0
ファイル: Resolver.cs プロジェクト: aritryakumar/dotnet
        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}");
        }
コード例 #9
0
            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()
                       ?? "");
            }
コード例 #10
0
        private void SetOwnerCore(CharacteristicObject newOwner)
        {
            if (newOwner == null)
            {
                throw new ArgumentNullException(nameof(newOwner));
            }

            AssertNotFrozen();
            newOwner.AssertIsNonFrozenRoot();

            Owner        = newOwner;
            sharedValues = newOwner.sharedValues;
            frozen       = false;
        }
コード例 #11
0
        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);
        }
コード例 #12
0
        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);
        }
コード例 #13
0
        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}");
        }
コード例 #14
0
        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}");
        }
コード例 #15
0
            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));
            }
コード例 #16
0
        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);
        }
コード例 #17
0
            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));
            }
コード例 #18
0
        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);
        }
コード例 #19
0
        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);
            }
        }
コード例 #20
0
 public void Apply(CharacteristicObject other) => ApplyCore(other);
コード例 #21
0
 public abstract string ToPresentation(CharacteristicObject obj, Characteristic characteristic);
コード例 #22
0
 protected override IEnumerable <Characteristic> GetPresentableCharacteristics(CharacteristicObject obj, bool includeIgnoreOnApply = false)
 => base.GetPresentableCharacteristics(obj, includeIgnoreOnApply)
 .Where(characteristic => !NonExportableTypes.Contains(characteristic.CharacteristicType));
コード例 #23
0
 public override string ToPresentation(CharacteristicObject obj)
 => string.Join(Separator,
                GetPresentableCharacteristics(obj, includeIgnoreOnApply: true)
                .Select(c => CharacteristicPresenter.ToPresentation(obj, c)));
コード例 #24
0
 protected virtual IEnumerable <Characteristic> GetPresentableCharacteristics(CharacteristicObject obj, bool includeIgnoreOnApply = false) =>
 obj
 .GetCharacteristicsWithValues()
 .Where(c => c.IsPresentableCharacteristic(includeIgnoreOnApply));
コード例 #25
0
 public T ApplyAndFreeze(CharacteristicObject other) => Apply(other).Freeze();
コード例 #26
0
 public new T Apply(CharacteristicObject other) => (T)ApplyCore(other);
コード例 #27
0
 internal virtual object ResolveValueCore(CharacteristicObject obj, object currentValue) =>
 ReferenceEquals(currentValue, EmptyValue) ? FallbackValue : currentValue;
コード例 #28
0
 public new T this[CharacteristicObject obj]
 {
     get { return(obj.GetValue(this)); }
     set { obj.SetValue(this, value); }
 }
コード例 #29
0
 public override string ToPresentation(CharacteristicObject obj, Characteristic characteristic)
 {
     return(obj.HasValue(characteristic)
         ? FolderNameHelper.ToFolderName(characteristic[obj])
         : "Default");
 }
コード例 #30
0
 protected CharacteristicObject ApplyCore(CharacteristicObject other) =>
 ApplyCore(
     other,
     GetCharacteristicsToApply(other));