コード例 #1
0
            public override string ToPresentation(JobMode jobMode)
            {
                var values = GetPresentableCharacteristics(jobMode, withDontClone: true)
                             .Select(c => CharacteristicPresenter.ToPresentation(jobMode, c));

                return(string.Join(Separator, values));
            }
コード例 #2
0
            public override string ToPresentation(JobMode jobMode)
            {
                var values = GetPresentableCharacteristics(jobMode)
                             .Select(c => c.Id + EqualsSeparator + CharacteristicPresenter.ToPresentation(jobMode, c));

                return(string.Join(Separator, values));
            }
コード例 #3
0
            public override string ToPresentation(JobMode jobMode)
            {
                var values = GetPresentableCharacteristics(jobMode, includeIgnoreOnApply: true)
                             .Select(c => CharacteristicPresenter.ToPresentation(jobMode, c));

                return(string.Join(Separator, values));
            }
コード例 #4
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())
            {
                object value;
                if (oldValues.TryGetValue(characteristic, out value))
                {
                    oldValues.Remove(characteristic);
                    SetValueCore(characteristic, value);
                }
            }
        }
コード例 #5
0
            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}");
            }
コード例 #6
0
        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)));
        }
コード例 #7
0
        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}");
        }
コード例 #8
0
        private IEnumerable <Characteristic> GetCharacteristicsToApply(JobMode other)
        {
            var result = other.GetCharacteristicsToApply();

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

            return(result);
        }
コード例 #9
0
            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()
                       ?? "");
            }
コード例 #10
0
        private void SetOwnerCore(JobMode newOwnerJob)
        {
            if (newOwnerJob == null)
            {
                throw new ArgumentNullException(nameof(newOwnerJob));
            }

            AssertNotFrozen();
            newOwnerJob.AssertIsNonFrozenRoot();

            owner        = newOwnerJob;
            sharedValues = newOwnerJob.sharedValues;
            frozen       = false;
        }
コード例 #11
0
ファイル: Resolver.cs プロジェクト: runt18/BenchmarkDotNet
        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}");
        }
コード例 #12
0
        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);
        }
コード例 #13
0
        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);
        }
コード例 #14
0
        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);
        }
コード例 #15
0
        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);
            }
        }
コード例 #16
0
 public abstract string ToPresentation(JobMode jobMode, Characteristic characteristic);
コード例 #17
0
 public override string ToPresentation(JobMode jobMode, Characteristic characteristic)
 {
     return(jobMode.HasValue(characteristic)
         ? characteristic[jobMode]?.ToString() ?? ""
         : "Default");
 }
コード例 #18
0
 public abstract string ToPresentation(JobMode jobMode);
コード例 #19
0
 public static IReadOnlyList <Characteristic> GetAllCharacteristics(this JobMode obj) =>
 GetAllCharacteristics(obj.GetType());
コード例 #20
0
 internal virtual object ResolveValueCore(JobMode obj, object currentValue) =>
 ReferenceEquals(currentValue, EmptyValue) ? FallbackValue : currentValue;
コード例 #21
0
 public new T this[JobMode obj]
 {
     get { return(obj.GetValue(this)); }
     set { obj.SetValue(this, value); }
 }
コード例 #22
0
 protected virtual IEnumerable <Characteristic> GetPresentableCharacteristics(JobMode jobMode, bool withDontClone = false) =>
 jobMode
 .GetCharacteristicsWithValues()
 .Where(c => c.IsPresentableCharacteristic(withDontClone));
コード例 #23
0
 protected JobMode()
 {
     owner        = null;
     sharedValues = new Dictionary <Characteristic, object>();
 }
コード例 #24
0
 public CharacteristicSet(JobMode other)
 {
     Apply(other);
 }
コード例 #25
0
 protected JobMode ApplyCore(JobMode other) =>
 ApplyCore(
     other,
     GetCharacteristicsToApply(other));
コード例 #26
0
 public void Apply(JobMode other) => ApplyCore(other);
コード例 #27
0
 public override string ToPresentation(JobMode jobMode, Characteristic characteristic)
 {
     return(jobMode.HasValue(characteristic)
         ? FolderNameHelper.ToFolderName(characteristic[jobMode])
         : "Default");
 }
コード例 #28
0
 protected virtual IEnumerable <Characteristic> GetPresentableCharacteristics(JobMode jobMode, bool includeIgnoreOnApply = false) =>
 jobMode
 .GetCharacteristicsWithValues()
 .Where(c => c.IsPresentableCharacteristic(includeIgnoreOnApply));