本文整理汇总了C#中ReadOnlyList类的典型用法代码示例。如果您正苦于以下问题:C# ReadOnlyList类的具体用法?C# ReadOnlyList怎么用?C# ReadOnlyList使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ReadOnlyList类属于命名空间,在下文中一共展示了ReadOnlyList类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Test
public void Test()
{
List<string> strings = new List<string>(new string[] { "a", "b", "c" });
ReadOnlyList<String> read = new ReadOnlyList<string>(strings);
strings.Add("d");
Assert.AreEqual(3, read.Count);
Assert.IsTrue(read.Contains("a"));
Assert.AreEqual(0, read.IndexOf("a"));
Assert.IsTrue(read.Contains("b"));
Assert.AreEqual(1, read.IndexOf("b"));
Assert.IsTrue(read.Contains("c"));
Assert.AreEqual(2, read.IndexOf("c"));
Assert.IsFalse(read.Contains("d"));
Assert.AreEqual(-1, read.IndexOf("d"));
Assert.AreEqual("a,b,c", String.Join(",", read.ToArray()));
Assert.AreEqual("a,b,c", String.Join(",", new List<String>(read).ToArray()));
string[] arcopy = new string[3];
read.CopyTo(arcopy, 0);
Assert.AreEqual("a,b,c", String.Join(",", arcopy));
System.Collections.IEnumerator en = ((System.Collections.IEnumerable)read).GetEnumerator();
Assert.IsTrue(en.MoveNext());
Assert.AreEqual("a", en.Current);
Assert.IsTrue(en.MoveNext());
Assert.AreEqual("b", en.Current);
Assert.IsTrue(en.MoveNext());
Assert.AreEqual("c", en.Current);
Assert.IsFalse(en.MoveNext());
}
示例2: Production
public Production(INonTerminal leftHandSide, params ISymbol[] rightHandSide)
{
Assert.IsNotNull(leftHandSide, "leftHandSide");
Assert.IsNotNull(rightHandSide, "rightHandSide");
LeftHandSide = leftHandSide;
_rightHandSide = new ReadOnlyList<ISymbol>(new List<ISymbol>(rightHandSide));
}
示例3: GetCommands
ReadOnlyList<Command> GetCommands(String filepath)
{
if (filepath == null) throw new ArgumentNullException("filepath");
if (m_commandcache.ContainsKey(filepath) == true) return m_commandcache[filepath];
List<Command> commands = new List<Command>();
TextFile textfile = GetSubSystem<IO.FileSystem>().OpenTextFile(filepath);
foreach (TextSection textsection in textfile)
{
if (String.Equals("Command", textsection.Title, StringComparison.OrdinalIgnoreCase) == true)
{
String name = textsection.GetAttribute<String>("name");
String text = textsection.GetAttribute<String>("command");
Int32 time = textsection.GetAttribute<Int32>("time", 15);
Int32 buffertime = textsection.GetAttribute<Int32>("Buffer.time", 1);
commands.Add(BuildCommand(name, text, time, buffertime));
}
}
if (m_internalcommands != null)
{
commands.AddRange(m_internalcommands);
}
ReadOnlyList<Command> list = new ReadOnlyList<Command>(commands);
m_commandcache.Add(filepath, list);
return list;
}
示例4: HitAttribute
public HitAttribute(AttackStateType height, ReadOnlyList<HitType> attackdata)
{
if (attackdata == null) throw new ArgumentNullException("attackdata");
m_attackheight = height;
m_attackdata = attackdata;
}
示例5: MissionObjectives
public MissionObjectives(World world, MissionObjectivesInfo moInfo)
{
info = moInfo;
Objectives = new ReadOnlyList<MissionObjective>(objectives);
world.ObserveAfterWinOrLose = !info.EarlyGameOver;
}
示例6: TaskAreaCommandGroupViewModel
public TaskAreaCommandGroupViewModel(string displayName, params TaskAreaCommandViewModel[] commands)
: base(displayName)
{
_commands = new ReadOnlyList<TaskAreaCommandViewModel>(commands);
if (_commands.Count > 0)
_selectedCommand = _commands[0];
}
示例7: DefaultLayer
/// <summary>
/// Public constructor.
/// </summary>
/// <param name="depth">The depth.</param>
/// <param name="matcher">The matcher.</param>
public DefaultLayer(float depth, Func<IRenderable, bool> matcher)
{
Depth = depth;
Matcher = matcher;
_readOnlyRenderableList = new ReadOnlyList<IRenderable>(_renderableList);
}
示例8: HGeneratorIterable
public HGeneratorIterable(IEnvironment environment, ReadOnlyList<GeneratorStep> steps, ReadOnlyList<string> variableDeclarations, ILexicalEnvironment scope)
: base(environment)
{
Steps = steps;
VariableDeclarations = variableDeclarations;
Scope = scope;
}
示例9: VisitSelect
protected override Expression VisitSelect(SqlSelectExpression selectExpression)
{
if (selectExpression.Skip != null)
{
var rowNumber = new SqlFunctionCallExpression(typeof(int), "ROW_NUMBER");
var over = new SqlOverExpression(rowNumber, selectExpression.OrderBy ?? new ReadOnlyList<Expression>(new [] { new SqlOrderByExpression(OrderType.Ascending, selectExpression.Columns[0].Expression) }));
var additionalColumn = new SqlColumnDeclaration(RowColumnName, over);
var newAlias = selectExpression.Alias + "INNER";
var innerColumns = new ReadOnlyList<SqlColumnDeclaration>(selectExpression.Columns.Select(c => c).Concat(new[] { additionalColumn }));
var innerSelect = new SqlSelectExpression(selectExpression.Type, newAlias, innerColumns, selectExpression.From, selectExpression.Where, null, selectExpression.GroupBy, selectExpression.Distinct, null, null, selectExpression.ForUpdate);
var outerColumns = selectExpression.Columns.Select(c => new SqlColumnDeclaration(c.Name, new SqlColumnExpression(c.Expression.Type, newAlias, c.Name)));
Expression rowPredicate = Expression.GreaterThan(new SqlColumnExpression(typeof(int), newAlias, additionalColumn.Name), selectExpression.Skip);
if (selectExpression.Take != null && !(selectExpression.Take is SqlTakeAllValueExpression))
{
rowPredicate = Expression.And
(
rowPredicate,
Expression.LessThanOrEqual(new SqlColumnExpression(typeof(int), newAlias, additionalColumn.Name), Expression.Add(selectExpression.Skip, selectExpression.Take))
);
}
return new SqlSelectExpression(selectExpression.Type, selectExpression.Alias, outerColumns, innerSelect, rowPredicate, null, selectExpression.ForUpdate);
}
return base.VisitSelect(selectExpression);
}
示例10: EditRegionViewModel
public EditRegionViewModel(IEnumerable<Variety> varieties, Variety variety, GeographicRegion region)
{
_title = "Edit Region";
_varieties = new ReadOnlyList<VarietyViewModel>(varieties.Select(v => new VarietyViewModel(v)).OrderBy(vm => vm.Name).ToArray());
_selectedVariety = _varieties.First(vm => vm.DomainVariety == variety);
_description = region.Description;
}
示例11: MultipleWordAlignerResult
public MultipleWordAlignerResult(IWordAligner wordAligner, IPairwiseAlignmentScorer<Word, ShapeNode> scorer, IEnumerable<Word> words)
: base(wordAligner)
{
_words = new ReadOnlyList<Word>(words.ToArray());
_algorithm = new MultipleAlignmentAlgorithm<Word, ShapeNode>(scorer, _words, GetNodes);
_algorithm.Compute();
}
示例12: TestContains
public void TestContains() {
int[] integers = new int[] { 1234, 6789 };
ReadOnlyList<int> testList = new ReadOnlyList<int>(integers);
Assert.IsTrue(testList.Contains(1234));
Assert.IsFalse(testList.Contains(4321));
}
示例13: HGeneratorIterator
public HGeneratorIterator(IEnvironment environment, Generator generator, ReadOnlyList<string> variableDeclarations, ILexicalEnvironment scope)
: base(environment)
{
Generator = generator;
VariableDeclarations = variableDeclarations;
Scope = scope;
}
示例14: TextTable
public TextTable()
{
columns = new List<TextTableColumn>();
rows = new List<TextTableRowBase>();
Columns = new ReadOnlyList<TextTableColumn>(columns);
Rows = new ReadOnlyList<TextTableRowBase>(rows);
}
示例15: ComponentOptionsViewModel
protected ComponentOptionsViewModel(string displayName, string optionDisplayName, params ComponentSettingsViewModelBase[] options)
: base(displayName)
{
_optionDisplayName = optionDisplayName;
_options = new ReadOnlyList<ComponentSettingsViewModelBase>(options);
foreach (ComponentSettingsViewModelBase option in _options)
option.PropertyChanged += ChildPropertyChanged;
}