Exemplo n.º 1
0
        /// <summary>
        /// Checks if a <see cref="VariableSubPolicy{T}"/> instance has sound data.
        /// Should be called inside every constructor at the end.
        /// </summary>
        /// <remarks>
        /// This only checks if any pair of <see cref="SpannedSubPolicy{T}"/>s overlap with
        /// each other to ensure that there is no ambiguity on selecting the binding argument
        /// when <see cref="Getter"/> is called with an index.
        /// </remarks>
        private void Validate()
        {
            SpannedSubPolicy <T> prev = null;

            foreach (SpannedSubPolicy <T> next in SpannedSubPolicies)
            {
                if (prev is SpannedSubPolicy <T> _prev)
                {
                    if (_prev.EndIndex is long prevEndIndex)
                    {
                        if (prevEndIndex >= next.StartIndex)
                        {
                            throw new ArgumentOutOfRangeException(
                                      paramName: nameof(prevEndIndex),
                                      actualValue: prevEndIndex,
                                      message: $"Previous {nameof(SpannedSubPolicy<T>)} overlaps with " +
                                      $"next {nameof(SpannedSubPolicy<T>)}");
                        }
                    }
                    else
                    {
                        throw new ArgumentOutOfRangeException(
                                  $"Previous {nameof(SpannedSubPolicy<T>)} overlaps with " +
                                  $"next {nameof(SpannedSubPolicy<T>)}.");
                    }
                }

                prev = next;
            }
        }
Exemplo n.º 2
0
        protected VariableSubPolicy(
            VariableSubPolicy <T> variableSubPolicy, SpannedSubPolicy <T> spannedSubPolicy)
        {
            if (variableSubPolicy is null || spannedSubPolicy is null)
            {
                throw new NullReferenceException(
                          $"Both arguments {nameof(variableSubPolicy)} and {nameof(spannedSubPolicy)} " +
                          "must not be null.");
            }

            List <SpannedSubPolicy <T> > spannedSubPolicies =
                variableSubPolicy.SpannedSubPolicies.ToList();

            if (spannedSubPolicies.Count > 0)
            {
                SpannedSubPolicy <T> lastSpannedSubPolicy =
                    spannedSubPolicies[spannedSubPolicies.Count - 1];

                // If spannedSubPolicies.StartIndex <= lastSpannedSubPolicy.StartIndex
                // an exception will be automatically thrown when trying to create
                // a new SpannedSubPolicy<T> below.
                if (!(lastSpannedSubPolicy.EndIndex is long endIndex) ||
                    endIndex >= spannedSubPolicy.StartIndex)
                {
                    lastSpannedSubPolicy = new SpannedSubPolicy <T>(
                        lastSpannedSubPolicy.StartIndex,
                        spannedSubPolicy.StartIndex - 1,
                        lastSpannedSubPolicy.Filter,
                        lastSpannedSubPolicy.Value);
                    spannedSubPolicies[spannedSubPolicies.Count - 1] = lastSpannedSubPolicy;
                }
            }

            spannedSubPolicies.Add(spannedSubPolicy);

            DefaultValue       = variableSubPolicy.DefaultValue;
            SpannedSubPolicies = spannedSubPolicies.ToImmutableList();
            Getter             = ToGetter();

            Validate();
        }
Exemplo n.º 3
0
 public IVariableSubPolicy <T> Add(SpannedSubPolicy <T> spannedSubPolicy)
 {
     try
     {
         return((VariableSubPolicy <T>)Activator.CreateInstance(
                    this.GetType(),
                    BindingFlags.Instance | BindingFlags.NonPublic,
                    null,
                    new object[] { this, spannedSubPolicy },
                    null));
     }
     catch (TargetInvocationException tie)
     {
         if (tie.InnerException is ArgumentOutOfRangeException aoore)
         {
             throw aoore;
         }
         else
         {
             throw;
         }
     }
 }
Exemplo n.º 4
0
 private MaxBlockBytesPolicy(
     MaxBlockBytesPolicy maxBlockBytesPolicy,
     SpannedSubPolicy <long> spannedSubPolicy)
     : base(maxBlockBytesPolicy, spannedSubPolicy)
 {
 }
Exemplo n.º 5
0
 private AuthorizedMinersPolicy(
     AuthorizedMinersPolicy authorizedMinersPolicy,
     SpannedSubPolicy <ImmutableHashSet <Address> > spannedSubPolicy)
     : base(authorizedMinersPolicy, spannedSubPolicy)
 {
 }
Exemplo n.º 6
0
 private HashAlgorithmTypePolicy(
     HashAlgorithmTypePolicy hashAlgorithmTypePolicy,
     SpannedSubPolicy <HashAlgorithmType> spannedSubPolicy)
     : base(hashAlgorithmTypePolicy, spannedSubPolicy)
 {
 }
Exemplo n.º 7
0
 private PermissionedMinersPolicy(
     PermissionedMinersPolicy permissionedMinersPolicy,
     SpannedSubPolicy <ImmutableHashSet <Address> > spannedSubPolicy)
     : base(permissionedMinersPolicy, spannedSubPolicy)
 {
 }