Esempio n. 1
0
 public override bool IsSubsetOf(IEnumerable <T> other)
 {
     CommonExceptions.CheckArgumentNull(other, nameof(other));
     Contract.EndContractBlock();
     return(true);
 }
Esempio n. 2
0
 /// <summary>
 /// 从 <see cref="ArrayAdapter{T}"/> 中移除所有元素。此实现总是引发 <see cref="NotSupportedException"/>。
 /// </summary>
 /// <exception cref="NotSupportedException">总是引发。</exception>
 public override void Clear()
 {
     throw CommonExceptions.CollectionFixedSize();
 }
Esempio n. 3
0
 /// <summary>
 /// 返回指定对象的哈希代码。
 /// </summary>
 /// <param name="obj">将为其返回哈希代码。</param>
 /// <returns>指定对象的哈希代码。</returns>
 /// <exception cref="ArgumentNullException"><paramref name="obj"/> 为 <c>null</c>。</exception>
 /// <overloads>
 /// <summary>
 /// 返回指定对象的哈希代码。
 /// </summary>
 /// </overloads>
 public override int GetHashCode(BitList obj)
 {
     CommonExceptions.CheckArgumentNull(obj, "obj");
     Contract.EndContractBlock();
     return(obj.GetContentHashCode());
 }
Esempio n. 4
0
 /// <summary>
 /// 返回将指定的一个或多个范围合并的结果,忽略无效范围。
 /// </summary>
 /// <param name="fileName">源文件的名称。</param>
 /// <param name="ranges">要进行合并的范围集合。</param>
 /// <returns>合并后的结果。</returns>
 /// <overloads>
 /// <summary>
 /// 返回将指定的一个或多个范围合并的结果,忽略无效范围。
 /// </summary>
 /// </overloads>
 public static SourceFileRange Merge(string fileName, params ISourceLocatable[] ranges)
 {
     CommonExceptions.CheckArgumentNull(fileName, "fileName");
     Contract.EndContractBlock();
     return(Merge(fileName, ranges as IEnumerable <ISourceLocatable>));
 }
Esempio n. 5
0
 /// <summary>
 /// 将元素插入 <see cref="ArrayAdapter{T}"/> 的指定索引处。
 /// </summary>
 /// <param name="index">从零开始的索引,应在该位置插入 <paramref name="item"/>。</param>
 /// <param name="item">要插入的对象。</param>
 protected override void InsertItem(int index, T item)
 {
     throw CommonExceptions.CollectionFixedSize();
 }
Esempio n. 6
0
 /// <summary>
 /// 从 <see cref="ReadOnlyList{T}"/> 中移除所有元素。
 /// 此实现总是引发 <see cref="NotSupportedException"/>。
 /// </summary>
 /// <exception cref="NotSupportedException">总是引发。</exception>
 void ICollection <T> .Clear()
 {
     throw CommonExceptions.MethodNotSupported();
 }
Esempio n. 7
0
 /// <summary>
 /// 将指定的键和对象添加到缓存中,无论键是否存在。
 /// </summary>
 /// <param name="key">要添加的对象的键。</param>
 /// <param name="value">要添加的对象。</param>
 /// <exception cref="System.ArgumentNullException">
 /// <paramref name="key"/> 为 <c>null</c>。</exception>
 public void Add(TKey key, TValue value)
 {
     CommonExceptions.CheckArgumentNull(key, "key");
     this.AddInternal(key, new Lazy <TValue>(() => value, false), true);
 }
Esempio n. 8
0
        /// <summary>
        /// 将栈顶数据作为索引,加载数组元素。
        /// </summary>
        /// <param name="il">IL 指令生成器。</param>
        /// <param name="elementType">要加载的数组元素类型。</param>
        /// <exception cref="ArgumentNullException"><paramref name="il"/> 为 <c>null</c>。</exception>
        /// <exception cref="ArgumentNullException"><paramref name="elementType"/> 为 <c>null</c>。</exception>
        public static void EmitLoadElement(this ILGenerator il, Type elementType)
        {
            if (il == null)
            {
                throw CommonExceptions.ArgumentNull("il");
            }
            if (elementType == null)
            {
                throw CommonExceptions.ArgumentNull("elementType");
            }
            Contract.EndContractBlock();
            if (!elementType.IsValueType)
            {
                il.Emit(OpCodes.Ldelem_Ref);
            }
            else if (elementType.IsEnum)
            {
                il.Emit(OpCodes.Ldelem, elementType);
            }
            else
            {
                switch (Type.GetTypeCode(elementType))
                {
                case TypeCode.Boolean:
                case TypeCode.SByte:
                    il.Emit(OpCodes.Ldelem_I1);
                    break;

                case TypeCode.Byte:
                    il.Emit(OpCodes.Ldelem_U1);
                    break;

                case TypeCode.Int16:
                    il.Emit(OpCodes.Ldelem_I2);
                    break;

                case TypeCode.Char:
                case TypeCode.UInt16:
                    il.Emit(OpCodes.Ldelem_U2);
                    break;

                case TypeCode.Int32:
                    il.Emit(OpCodes.Ldelem_I4);
                    break;

                case TypeCode.UInt32:
                    il.Emit(OpCodes.Ldelem_U4);
                    break;

                case TypeCode.Int64:
                case TypeCode.UInt64:
                    il.Emit(OpCodes.Ldelem_I8);
                    break;

                case TypeCode.Single:
                    il.Emit(OpCodes.Ldelem_R4);
                    break;

                case TypeCode.Double:
                    il.Emit(OpCodes.Ldelem_R8);
                    break;

                default:
                    il.Emit(OpCodes.Ldelem, elementType);
                    break;
                }
            }
        }
Esempio n. 9
0
 /// <summary>
 /// 合并种子 Hash 值和一系列对象。
 /// </summary>
 /// <typeparam name="T">要合并 Hash 值的对象的类型。</typeparam>
 /// <param name="seed">要合并的种子 Hash 值。</param>
 /// <param name="objs">要合并 Hash 值的对象集合。</param>
 /// <returns>结果 Hash 值。</returns>
 /// <exception cref="ArgumentNullException"><paramref name="objs"/> 为 <c>null</c>。</exception>
 /// <remarks>算法来自 boost::hash_range。</remarks>
 public static int Combine <T>(int seed, IEnumerable <T> objs)
 {
     CommonExceptions.CheckArgumentNull(objs, "objs");
     Contract.EndContractBlock();
     return(objs.Aggregate(seed, Combine));
 }
Esempio n. 10
0
 /// <summary>
 /// 修改当前集合,使该集合仅包含指定集合中也存在的元素。
 /// 此实现总是引发 <see cref="NotSupportedException"/>。
 /// </summary>
 /// <param name="other">要与当前集合进行比较的集合。</param>
 /// <exception cref="NotSupportedException">总是引发。</exception>
 void ISet <T> .IntersectWith(IEnumerable <T> other)
 {
     throw CommonExceptions.MethodNotSupported();
 }
Esempio n. 11
0
 /// <summary>
 /// 确定缓存中是否包含指定的键。
 /// </summary>
 /// <param name="key">要在缓存中查找的键。</param>
 /// <returns>如果缓存中包含具有指定键的元素,则为 <c>true</c>;否则为 <c>false</c>。</returns>
 /// <exception cref="ArgumentNullException"><paramref name="key"/> 为 <c>null</c>。</exception>
 public bool Contains(TKey key)
 {
     CommonExceptions.CheckArgumentNull(key, "key");
     Contract.EndContractBlock();
     return(cacheDict.ContainsKey(key));
 }
Esempio n. 12
0
 /// <summary>
 /// 向当前集合内添加元素,并返回一个指示是否已成功添加元素的值。
 /// 此实现总是引发 <see cref="NotSupportedException"/>。
 /// </summary>
 /// <param name="item">要添加到集合内的元素。</param>
 /// <returns>如果该元素已添加到集合内,则为 <c>true</c>;
 /// 如果该元素已在集合内,则为 <c>false</c>。</returns>
 /// <exception cref="NotSupportedException">总是引发。</exception>
 bool ISet <T> .Add(T item)
 {
     throw CommonExceptions.MethodNotSupported();
 }
Esempio n. 13
0
 public override bool SetEquals(IEnumerable <T> other)
 {
     CommonExceptions.CheckArgumentNull(other, nameof(other));
     Contract.EndContractBlock();
     return(!other.Any());
 }
Esempio n. 14
0
 public override bool Overlaps(IEnumerable <T> other)
 {
     CommonExceptions.CheckArgumentNull(other, nameof(other));
     Contract.EndContractBlock();
     return(false);
 }
Esempio n. 15
0
 /// <summary>
 /// 移除 <see cref="ReadOnlyList{T}"/> 的指定索引处的元素。
 /// 此实现总是引发 <see cref="NotSupportedException"/>。
 /// </summary>
 /// <param name="index">要移除的元素的从零开始的索引。</param>
 /// <exception cref="ArgumentOutOfRangeException">
 /// <paramref name="index"/> 不是 <see cref="ReadOnlyList{T}"/> 中的有效索引。</exception>
 /// <exception cref="NotSupportedException">总是引发。</exception>
 void IList.RemoveAt(int index)
 {
     throw CommonExceptions.MethodNotSupported();
 }
Esempio n. 16
0
 /// <summary>
 /// 检查指定文件名是否包含无效的字符。
 /// </summary>
 /// <param name="fileName">要检查的文件名。</param>
 /// <returns>如果指定文件名中包含的字符全部是有效的,则为 <c>true</c>;
 /// 否则若包含无效的字符,则为 <c>false</c>。</returns>
 /// <exception cref="ArgumentNullException"><paramref name="fileName"/> 为 <c>null</c>。</exception>
 public static bool IsValidFileName(string fileName)
 {
     CommonExceptions.CheckArgumentNull(fileName, "fileName");
     Contract.EndContractBlock();
     return(fileName.All(t => !invalidFileNameChars.Contains(t)));
 }
Esempio n. 17
0
 /// <summary>
 /// 将指定对象添加到 <see cref="ReadOnlyList{T}"/> 中。
 /// 此实现总是引发 <see cref="NotSupportedException"/>。
 /// </summary>
 /// <param name="item">要添加到 <see cref="ReadOnlyList{T}"/> 中的对象。</param>
 /// <exception cref="NotSupportedException">总是引发。</exception>
 void ICollection <T> .Add(T item)
 {
     throw CommonExceptions.MethodNotSupported();
 }
Esempio n. 18
0
 /// <summary>
 /// 检查指定路径是否包含无效的字符。
 /// </summary>
 /// <param name="path">要检查的路径。</param>
 /// <returns>如果指定路径中包含的字符全部是有效的,则为 <c>true</c>;
 /// 否则若包含无效的字符,则为 <c>false</c>。</returns>
 /// <exception cref="ArgumentNullException"><paramref name="path"/> 为 <c>null</c>。</exception>
 public static bool IsValidPath(string path)
 {
     CommonExceptions.CheckArgumentNull(path, "path");
     Contract.EndContractBlock();
     return(path.All(t => !invalidPathChars.Contains(t)));
 }
Esempio n. 19
0
 /// <summary>
 /// 从 <see cref="ReadOnlyList{T}"/> 中移除特定对象的第一个匹配项。
 /// 此实现总是引发 <see cref="NotSupportedException"/>。
 /// </summary>
 /// <param name="item">要从 <see cref="ReadOnlyList{T}"/> 中移除的对象。</param>
 /// <returns>如果已从 <see cref="ReadOnlyList{T}"/> 中成功移除 <paramref name="item"/>,
 /// 则为 <c>true</c>;否则为 <c>false</c>。如果在原始 <see cref="ReadOnlyList{T}"/>
 /// 中没有找到 <paramref name="item"/>,该方法也会返回 <c>false</c>。</returns>
 /// <exception cref="NotSupportedException">总是引发。</exception>
 bool ICollection <T> .Remove(T item)
 {
     throw CommonExceptions.MethodNotSupported();
 }
Esempio n. 20
0
 /// <summary>
 /// 将元素插入 <see cref="ReadOnlyList{T}"/> 的指定索引处。
 /// 此实现总是引发 <see cref="NotSupportedException"/>。
 /// </summary>
 /// <param name="index">从零开始的索引,应在该位置插入 <paramref name="item"/>。</param>
 /// <param name="item">要插入到 <see cref="ReadOnlyList{T}"/> 中的对象。</param>
 /// <exception cref="NotSupportedException">总是引发。</exception>
 void IList <T> .Insert(int index, T item)
 {
     throw CommonExceptions.MethodNotSupported();
 }
Esempio n. 21
0
 /// <summary>
 /// 返回指定的 <see cref="ISourceLocatable"/> 是否与当前范围存在重叠。
 /// </summary>
 /// <param name="locatable">要检查的范围。</param>
 /// <returns>如果指定的范围与当前范围存在重叠,则为 <c>true</c>;否则为 <c>false</c>。
 /// 对于未知的范围,也会返回 <c>false</c>。</returns>
 /// <exception cref="ArgumentNullException"><paramref name="locatable"/> 为 <c>null</c>。</exception>
 public bool OverlapsWith(ISourceLocatable locatable)
 {
     CommonExceptions.CheckArgumentNull(locatable, "locatable");
     Contract.EndContractBlock();
     return((!this.IsUnknown) && this.start <= locatable.End && this.end >= locatable.Start);
 }
Esempio n. 22
0
 /// <summary>
 /// 将指定对象添加到 <see cref="ReadOnlyList{T}"/> 中。
 /// 此实现总是引发 <see cref="NotSupportedException"/>。
 /// </summary>
 /// <param name="value">要添加到 <see cref="ReadOnlyList{T}"/> 中的对象。</param>
 /// <returns>新元素所插入到的位置,或为 <c>-1</c> 以指示未将该项插入到集合中。</returns>
 /// <exception cref="NotSupportedException">总是引发。</exception>
 int IList.Add(object value)
 {
     throw CommonExceptions.MethodNotSupported();
 }
Esempio n. 23
0
 /// <summary>
 /// 读取输入流中的下一个词法单元并提升输入流的字符位置。
 /// </summary>
 /// <returns>输入流中的下一个词法单元。</returns>
 protected override Token <T> InternalReadToken()
 {
     while (true)
     {
         if (this.Source.Peek() == -1)
         {
             // 到达了流的结尾。
             Action <ReaderController <T> > action = this.LexerRule.EofActions[context.Value];
             if (action != null)
             {
                 this.DoAction(action, EndOfFileIndex);
                 if (this.IsAccept)
                 {
                     return(new Token <T>(this.controller.Id, this.controller.Text,
                                          Source.StartPosition, Source.StartPosition, this.controller.Value));
                 }
             }
             return(Token <T> .GetEndOfFile(Source.StartPosition));
         }
         // 起始状态与当前上下文相关。
         int state = this.context.Value;
         if (this.lexerRule.ContainsBeginningOfLineHeader)
         {
             state *= 2;
             if (this.Source.StartPosition.Col == 1)
             {
                 // 行首规则。
                 state++;
             }
         }
         if (!this.IsMore)
         {
             this.Start = Source.StartPosition;
         }
         if (InternalReadToken(state))
         {
             if (!this.IsMore && !this.IsReject)
             {
                 this.Source.Drop();
             }
             if (this.IsAccept)
             {
                 return(new Token <T>(this.controller.Id, this.controller.Text,
                                      this.Start, this.Source.BeforeStartPosition, this.controller.Value));
             }
         }
         else
         {
             // 到达死状态。
             string text = this.Source.Accept();
             if (text.Length == 0)
             {
                 // 如果没有匹配任何字符,强制读入一个字符,可以防止死循环出现。
                 this.Source.Read();
                 text = this.Source.Accept();
             }
             throw CommonExceptions.UnrecognizedToken(text,
                                                      this.Start, this.Source.BeforeStartPosition);
         }
     }
 }
Esempio n. 24
0
 /// <summary>
 /// 从 <see cref="ReadOnlyList{T}"/> 中移除所有元素。
 /// 此实现总是引发 <see cref="NotSupportedException"/>。
 /// </summary>
 /// <exception cref="NotSupportedException">总是引发。</exception>
 void IList.Clear()
 {
     throw CommonExceptions.MethodNotSupported();
 }
Esempio n. 25
0
 /// <summary>
 /// 移除 <see cref="ArrayAdapter{T}"/> 的指定索引处的元素。
 /// </summary>
 /// <param name="index">要移除的元素的从零开始的索引。</param>
 protected override void RemoveItem(int index)
 {
     throw CommonExceptions.CollectionFixedSize();
 }
Esempio n. 26
0
 /// <summary>
 /// 将对象插入 <see cref="ReadOnlyList{T}"/> 的指定索引处。
 /// 此实现总是引发 <see cref="NotSupportedException"/>。
 /// </summary>
 /// <param name="index">从零开始的索引,应在该位置插入 <paramref name="value"/>。</param>
 /// <param name="value">要插入到 <see cref="ReadOnlyList{T}"/> 中的对象。</param>
 /// <exception cref="ArgumentOutOfRangeException">
 /// <paramref name="index"/> 不是 <see cref="ReadOnlyList{T}"/> 中的有效索引。</exception>
 /// <exception cref="NotSupportedException">总是引发。</exception>
 void IList.Insert(int index, object value)
 {
     throw CommonExceptions.MethodNotSupported();
 }
Esempio n. 27
0
        /// <summary>
        /// 基于提供的参数,从给定的方法集中选择要调用的方法。
        /// </summary>
        /// <param name="bindingAttr"><see cref="BindingFlags"/> 值的按位组合。</param>
        /// <param name="match">用于匹配的候选方法集。</param>
        /// <param name="args">传入的参数。</param>
        /// <param name="modifiers">使绑定能够处理在其中修改了类型的参数签名的参数修饰符数组。</param>
        /// <param name="culture">一个 <see cref="CultureInfo"/> 实例,
        /// 用于在强制类型的联编程序实现中控制数据类型强制。</param>
        /// <param name="names">参数名(如果匹配时要考虑参数名)或 <c>null</c>(如果要将变量视为纯位置)。</param>
        /// <param name="state">方法返回之后,<paramref name="state"/> 包含一个联编程序提供的对象,
        /// 用于跟踪参数的重新排序。</param>
        /// <returns>匹配的方法。</returns>
        /// <exception cref="ArgumentNullException"><paramref name="match"/> 为 <c>null</c>。</exception>
        /// <exception cref="ArgumentNullException"><paramref name="args"/> 为 <c>null</c>。</exception>
        /// <exception cref="ArgumentException"><paramref name="match"/> 为空数组。</exception>
        /// <exception cref="ArgumentException"><paramref name="match"/> 中包含为 <c>null</c> 的元素。</exception>
        /// <exception cref="AmbiguousMatchException"><paramref name="match"/> 包含多个与 <paramref name="args"/>
        /// 匹配程度相同的方法。</exception>
        /// <exception cref="MissingFieldException"><paramref name="bindingAttr"/> 包含
        /// <see cref="BindingFlags.SetField"/>,且 <paramref name="match"/> 不包含任何可接受 <paramref name="args"/>
        /// 的方法。</exception>
        public override MethodBase BindToMethod(BindingFlags bindingAttr, MethodBase[] match, ref object[] args,
                                                ParameterModifier[] modifiers, CultureInfo culture, string[] names, out object state)
        {
            CommonExceptions.CheckCollectionItemNull(match, "match");
            CommonExceptions.CheckArgumentNull(args, "args");
            if (names != null && names.Length > args.Length)
            {
                throw CommonExceptions.NamedParamTooBig("names");
            }
            Contract.EndContractBlock();
            // 检查参数名称数组,不能出现名称相同的参数。
            if (names != null && !names.IsDistinct(StringComparer.Ordinal))
            {
                throw CommonExceptions.DuplicateName("names");
            }
            MethodArgumentsOption options = MethodArgumentsOption.None;

            if (isExplicit)
            {
                options |= MethodArgumentsOption.Explicit;
            }
            if (bindingAttr.HasFlag(BindingFlags.OptionalParamBinding))
            {
                options |= MethodArgumentsOption.OptionalParamBinding;
            }
            int typesLen = args.Length;

            Type[] types = new Type[typesLen];
            for (int i = 0; i < typesLen; i++)
            {
                object arg = args[i];
                types[i] = arg == null ? null : arg.GetType();
            }
            MethodMatchInfo[] infos = new MethodMatchInfo[match.Length];
            MethodMatchInfo   info;
            int length = 0;

            for (int i = 0; i < match.Length; i++)
            {
                int[] paramOrder = null;
                if (names != null)
                {
                    paramOrder = CreateParamOrder(match[i], names, typesLen);
                    if (paramOrder == null)
                    {
                        continue;
                    }
                }
                info = MethodMatchInfo.GetMatchInfo(match[i], types, paramOrder, options);
                if (info != null)
                {
                    infos[length++] = info;
                }
            }
            if (length == 0)
            {
                // 没有可匹配的方法。
                state = null;
                throw CommonExceptions.MissingMethod();
            }
            info = SelectMethod(infos, length, types);
            if (info == null)
            {
                state = null;
                throw CommonExceptions.AmbiguousMatchMethod();
            }
            UpdateArgs(info, ref args, out state);
            return(info.Method);
        }
Esempio n. 28
0
 /// <summary>
 /// 从 <see cref="ReadOnlyList{T}"/> 中移除特定对象的第一个匹配项。
 /// 此实现总是引发 <see cref="NotSupportedException"/>。
 /// </summary>
 /// <param name="value">要从 <see cref="ReadOnlyList{T}"/> 中移除的对象。</param>
 /// <exception cref="NotSupportedException">总是引发。</exception>
 void IList.Remove(object value)
 {
     throw CommonExceptions.MethodNotSupported();
 }
Esempio n. 29
0
 /// <summary>
 /// 使用要扫描的源文件初始化 <see cref="TokenReader{T}"/> 类的新实例。
 /// </summary>
 /// <param name="reader">要使用的源文件读取器。</param>
 /// <exception cref="ArgumentNullException"><paramref name="reader"/> 为 <c>null</c>。</exception>
 protected TokenReader(SourceReader reader)
 {
     CommonExceptions.CheckArgumentNull(reader, "reader");
     Contract.EndContractBlock();
     this.Source = reader;
 }
Esempio n. 30
0
 /// <summary>
 /// 修改当前集合,使该集合仅包含当前集合或指定集合中存在的元素(但不可包含两者共有的元素)。
 /// 此实现总是引发 <see cref="NotSupportedException"/>。
 /// </summary>
 /// <param name="other">要与当前集合进行比较的集合。</param>
 /// <exception cref="NotSupportedException">总是引发。</exception>
 void ISet <T> .SymmetricExceptWith(IEnumerable <T> other)
 {
     throw CommonExceptions.MethodNotSupported();
 }