当前位置: 首页>>代码示例>>C#>>正文


C# System.Collections.Generic.List.AsReadOnly方法代码示例

本文整理汇总了C#中System.Collections.Generic.List.AsReadOnly方法的典型用法代码示例。如果您正苦于以下问题:C# System.Collections.Generic.List.AsReadOnly方法的具体用法?C# System.Collections.Generic.List.AsReadOnly怎么用?C# System.Collections.Generic.List.AsReadOnly使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Collections.Generic.List的用法示例。


在下文中一共展示了System.Collections.Generic.List.AsReadOnly方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: DomainEnumPropertyDescriptor

        public DomainEnumPropertyDescriptor(ElementTypeDescriptor owner, ModelElement modelElement, DomainPropertyInfo domainProperty, DomainEnumeration domainEnum, Attribute[] attributes)
            : base(owner, modelElement, domainProperty, attributes)
        {
            this.domainEnum = domainEnum;

            System.Collections.Generic.List<string> list = new System.Collections.Generic.List<string>();
            foreach(EnumerationLiteral enumerationLiteral in this.domainEnum.Literals)
                list.Add(enumerationLiteral.Name);
            
            enumFields = list.AsReadOnly();
        }
开发者ID:apoorv-vijay-joshi,项目名称:FSE-2011-PDE,代码行数:11,代码来源:DomainEnumPropertyDescriptor.cs

示例2: SelectFiles

        /// <summary>
        /// Returns the names of the files in the specified directory that fit the selection
        /// criteria specified in the FileSelector, optionally recursing through subdirectories.
        /// </summary>
        ///
        /// <remarks>
        /// This method applies the file selection criteria contained in the FileSelector to the
        /// files contained in the given directory, and returns the names of files that
        /// conform to the criteria.
        /// </remarks>
        ///
        /// <param name="directory">
        /// The name of the directory over which to apply the FileSelector criteria.
        /// </param>
        ///
        /// <param name="recurseDirectories">
        /// Whether to recurse through subdirectories when applying the file selection criteria.
        /// </param>
        ///
        /// <returns>
        /// An collection of strings containing fully-qualified pathnames of files
        /// that match the criteria specified in the FileSelector instance.
        /// </returns>
        public System.Collections.ObjectModel.ReadOnlyCollection<String> SelectFiles(String directory, bool recurseDirectories)
        {
            if (_Criterion == null)
                throw new ArgumentException("SelectionCriteria has not been set");

            var list = new System.Collections.Generic.List<String>();
            try
            {
                if (Directory.Exists(directory))
                {
                    String[] filenames = System.IO.Directory.GetFiles(directory);

                    // add the files:
                    foreach (String filename in filenames)
                    {
                        if (Evaluate(filename))
                            list.Add(filename);
                    }

                    if (recurseDirectories)
                    {
                        // add the subdirectories:
                        String[] dirnames = System.IO.Directory.GetDirectories(directory);
                        foreach (String dir in dirnames)
                        {
                            if (this.TraverseReparsePoints ||
                              //TODO isn't this a bug? Shouldn't this be Directory.GetAttributes anyway?
                                ((File.GetAttributes(dir) & FileAttributes.ReparsePoint) == 0))
                            {
                                // workitem 10191
                                if (Evaluate(dir)) list.Add(dir);
                                list.AddRange(this.SelectFiles(dir, recurseDirectories));
                            }
                        }
                    }
                }
            }
            // can get System.UnauthorizedAccessException here
            catch (System.UnauthorizedAccessException)
            {
            }
            catch (System.IO.IOException)
            {
            }

            return list.AsReadOnly();
        }
开发者ID:RainsSoft,项目名称:UJad-AI-VFS,代码行数:70,代码来源:FileSelector.cs


注:本文中的System.Collections.Generic.List.AsReadOnly方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。