本文整理汇总了C#中System.Collections.Generic类的典型用法代码示例。如果您正苦于以下问题:C# System.Collections.Generic类的具体用法?C# System.Collections.Generic怎么用?C# System.Collections.Generic使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
System.Collections.Generic类属于命名空间,在下文中一共展示了System.Collections.Generic类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetHelp
public static IEnumerable<string> GetHelp(ScriptSession session, string command)
{
Collection<PSParseError> errors;
var tokens = PSParser.Tokenize(command, out errors);
var lastPsToken = tokens.LastOrDefault(t => t.Type == PSTokenType.Command);
if (lastPsToken != null)
{
session.Output.Clear();
var lastToken = lastPsToken.Content;
session.SetVariable("helpFor", lastToken);
var platformmodule = ModuleManager.GetModule("Platform");
var scriptItem = Database.GetDatabase(platformmodule.Database)
.GetItem(platformmodule.Path + "/Internal/Context Help/Command Help");
if (scriptItem == null)
{
scriptItem = Factory.GetDatabase(ApplicationSettings.ScriptLibraryDb)
.GetItem(ApplicationSettings.ScriptLibraryPath + "Internal/Context Help/Command Help");
}
session.ExecuteScriptPart(scriptItem[ScriptItemFieldNames.Script], true, true);
var sb = new StringBuilder("<div id=\"HelpClose\">X</div>");
if (session.Output.Count == 0 || session.Output[0].LineType == OutputLineType.Error)
{
return new[]
{
"<div class='ps-help-command-name'> </div><div class='ps-help-header' align='center'>No Command in line or help information found</div><div class='ps-help-parameter' align='center'>Cannot provide help in this context.</div>"
};
}
session.Output.ForEach(l => sb.Append(l.Text));
session.Output.Clear();
var result = new[] {sb.ToString()};
return result;
}
return new[] {"No Command in line found - cannot provide help in this context."};
}
示例2: Index
public ActionResult Index()
{
var themes = new List<dynamic>();
var dirbase = new DirectoryInfo(HttpContext.Server.MapPath(string.Format("~/Content/js/easyui/{0}/themes", AppSettings.EasyuiVersion)));
DirectoryInfo[] dirs = dirbase.GetDirectories();
foreach (var dir in dirs)
if (dir.Name != "icons")
themes.Add(new {text=dir.Name,value=dir.Name });
var navigations = new List<dynamic>();
navigations.Add(new { text = "手风琴-2级(默认)", value = "accordion" });
//navigations.Add(new { text = "手风琴大图标-2级", value = "accordionbigicon" });
navigations.Add(new { text = "手风琴树", value = "accordiontree" });
navigations.Add(new { text = "横向菜单", value = "menubutton" });
navigations.Add(new { text = "树形结构", value = "tree" });
var model = new {
dataSource = new{
themes=themes,
navigations=navigations
},
form= new sys_userService().GetCurrentUserSettings()
};
return View(model);
}
示例3: Search
public ActionResult Search(string query)
{
ViewData["Message"] = "query : " + query;
var searcher = new IndexSearcher(
new Lucene.Net.Store.SimpleFSDirectory(new DirectoryInfo(Configuration.IndexDirectory)),
readOnly: true);
var fieldsToSearchIn = new[] {Configuration.Fields.Name, Configuration.Fields.Description};
var queryanalizer = new MultiFieldQueryParser(Version.LUCENE_CURRENT,
fieldsToSearchIn,
new BrazilianAnalyzer());
var numberOfResults = 10;
var top10Results = searcher.Search(queryanalizer.Parse(query), numberOfResults);
var docs = new List<DocumentViewModel>();
foreach (var scoreDoc in top10Results.scoreDocs)
{
var document = searcher.Doc(scoreDoc.doc);
var name = document.GetField(Configuration.Fields.Name).StringValue();
var description = document.GetField(Configuration.Fields.Description).StringValue();
var link = document.GetField(Configuration.Fields.Link).StringValue();
docs.Add(new DocumentViewModel(name, description, link));
}
return View(new SearchViewModel(docs));
}
示例4: TestNotReusedOnAssemblyDiffersAsync
internal static async Task TestNotReusedOnAssemblyDiffersAsync(string projectLanguage)
{
var metadataSources = new[]
{
@"[assembly: System.Reflection.AssemblyVersion(""1.0.0.0"")] public class D {}",
@"[assembly: System.Reflection.AssemblyVersion(""2.0.0.0"")] public class D {}"
};
using (var context = await TestContext.CreateAsync(projectLanguage))
{
var projectId = ProjectId.CreateNewId();
var metadataProject = context.CurrentSolution
.AddProject(projectId, "Metadata", "Metadata", LanguageNames.CSharp).GetProject(projectId)
.AddMetadataReference(TestReferences.NetFx.v4_0_30319.mscorlib)
.WithCompilationOptions(new CSharpCompilationOptions(OutputKind.DynamicallyLinkedLibrary, optimizationLevel: OptimizationLevel.Release));
var references = new List<MetadataReference>();
foreach (var source in metadataSources)
{
var newDoc = metadataProject.AddDocument("MetadataSource", source);
metadataProject = newDoc.Project;
references.Add(MetadataReference.CreateFromImage((await metadataProject.GetCompilationAsync()).EmitToArray()));
metadataProject = metadataProject.RemoveDocument(newDoc.Id);
}
var project = context.DefaultProject.AddMetadataReference(references[0]);
var a = await context.GenerateSourceAsync("D", project);
project = project.RemoveMetadataReference(references[0]).AddMetadataReference(references[1]);
var b = await context.GenerateSourceAsync("D", project);
context.VerifyDocumentNotReused(a, b);
}
}
示例5: MapToTokenModelTest
public void MapToTokenModelTest()
{
const string email = "[email protected]";
const int id = 1;
const string hash = "HashToken";
IEnumerable<string> roles = new[] {"Admin", "Student", "Teacher"};
Mock<ITokenValidation> token = new Mock<ITokenValidation>();
UserToTokenMapper mapper = new UserToTokenMapper(token.Object);
var initial = new UserWithPasswordModel()
{
Email = email,
Id = id,
HashToken = hash,
Roles = roles
};
var expected = new TokenModel()
{
EmailAndIdToken = email,
RolesToken = roles.ToString(),
HashToken = hash
};
token.Setup(x => x.EncodeEmailAndIdToken(id.ToString() + ' ' + email.ToLower()))
.Returns(email);
token.Setup(x => x.EncodeRoleToken(roles))
.Returns(roles.ToString);
var action = mapper.MapToTokenModel(initial);
Assert.IsNotNull(action);
Assert.AreEqual(action.EmailAndIdToken, expected.EmailAndIdToken);
Assert.AreEqual(action.HashToken, expected.HashToken);
Assert.AreEqual(action.RolesToken, expected.RolesToken);
}
示例6: TestLowerCaseComlicatedNamespaceAsync
public async Task TestLowerCaseComlicatedNamespaceAsync()
{
var testCode = @"namespace test.foo.bar
{
}";
var fixedCode = @"namespace Test.Foo.Bar
{
}";
DiagnosticResult[] expected = new[]
{
this.CSharpDiagnostic().WithArguments("test").WithLocation(1, 11),
this.CSharpDiagnostic().WithArguments("test").WithLocation(1, 11),
this.CSharpDiagnostic().WithArguments("test").WithLocation(1, 11),
this.CSharpDiagnostic().WithArguments("foo").WithLocation(1, 16),
this.CSharpDiagnostic().WithArguments("foo").WithLocation(1, 16),
this.CSharpDiagnostic().WithArguments("foo").WithLocation(1, 16),
this.CSharpDiagnostic().WithArguments("bar").WithLocation(1, 20),
this.CSharpDiagnostic().WithArguments("bar").WithLocation(1, 20),
this.CSharpDiagnostic().WithArguments("bar").WithLocation(1, 20)
};
await this.VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None).ConfigureAwait(false);
await this.VerifyCSharpDiagnosticAsync(fixedCode, EmptyDiagnosticResults, CancellationToken.None).ConfigureAwait(false);
await this.VerifyCSharpFixAsync(testCode, fixedCode).ConfigureAwait(false);
}
示例7: WriteNodes
private void WriteNodes(XElement nodes)
{
foreach (NodeInfo nodeInfo in _snapshot.Nodes)
{
var labelComponents = new[] {nodeInfo.NodeType.ToString(), nodeInfo.Details}
.Union(nodeInfo.Conditions)
.Union(nodeInfo.Expressions)
.Where(x => !string.IsNullOrEmpty(x));
string label = string.Join("\n", labelComponents);
var node = new XElement(Name("Node"),
new XAttribute("Id", Id(nodeInfo)),
new XAttribute("Category", nodeInfo.NodeType),
new XAttribute("Label", label));
if (nodeInfo.Items.Length > 0)
{
node.Add(new XAttribute("Group", "Collapsed"));
}
nodes.Add(node);
for (int i = 0; i < nodeInfo.Items.Length; i++)
{
var itemNode = new XElement(Name("Node"),
new XAttribute("Id", SubNodeId(nodeInfo, i)),
new XAttribute("Label", nodeInfo.Items[i]),
new XAttribute("Style", "Plain"));
nodes.Add(itemNode);
}
}
}
示例8: GetLogGridItems
public ActionResult GetLogGridItems(GridSettings gridSettings)
{
var logGridItems = _logRepository.GetLogItems(gridSettings);
var totalLogGridItems = _logRepository.CountLogItems(gridSettings);
var pageIndex = gridSettings.PageIndex;
var pageSize = gridSettings.PageSize;
var jsonData = new
{
total = (totalLogGridItems / pageSize) + ((totalLogGridItems % pageSize > 0) ? 1 : 0),
page = pageIndex,
records = totalLogGridItems,
rows = (from logItem in logGridItems
select new Dictionary<string, string>
{
{ "Id", logItem.Id.ToString() },
{ "Created", logItem.Created.ToString() },
{ "Level", logItem.Level },
{ "Username", logItem.Username },
{ "Message", logItem.Message}
}).ToArray()
};
return Json(jsonData, JsonRequestBehavior.AllowGet);
}
示例9: SortListOfInts
public void SortListOfInts()
{
var unsorted = new[] { 5, 2, 3, -1, 8 };
var sorted = new[] { -1, 2, 3, 5, 8 };
Assert.That(InsertionSortIEnumerable(unsorted), Is.EqualTo(sorted));
}
示例10: AssertInequalities
private static void AssertInequalities(string[] subject)
{
var reference = new[] { "foo", "bar", "baz" };
IComparer<IEnumerable<string>> comparer = new EnumerableComparer<string>();
Assert.AreEqual(-1, comparer.Compare(reference, subject));
Assert.AreEqual(1, comparer.Compare(subject, reference));
}
示例11: FiltersForLineItemType
public void FiltersForLineItemType()
{
// Arrange
var sw = new StringWriter();
using (var csv = new CsvWriter(sw))
{
var lineItems = new[]
{
new LineItem {RecordType = "Dummy"},
new LineItem {RecordType = "LineItem", RecordId = "Hoojey"}
};
csv.WriteHeader<LineItem>();
csv.WriteRecords(lineItems);
}
// Act
List<LineItem> parsedItems;
using (var reader = new StringReader(sw.ToString()))
{
using (var parser = new LineItemCsvParser(reader))
{
parsedItems = parser.GetLineItems().ToList();
}
}
// Assert
parsedItems.Count.Should().Be(1);
parsedItems[0].RecordId.Should().Be("Hoojey");
}
示例12: ByViewAndVectorAnalysisData_ValidArgs
public void ByViewAndVectorAnalysisData_ValidArgs()
{
var samplePoints = new[]
{
Point.ByCoordinates(0, 2, 4),
Point.ByCoordinates(0, 7, 4),
Point.ByCoordinates(0, 19, 4)
};
var sampleValues = new[]
{
Vector.ByCoordinates(0, 2, 4),
Vector.ByCoordinates(0, 7, 4),
Vector.ByCoordinates(0, 19, 4)
};
var data = VectorAnalysisData.ByPointsAndResults(
samplePoints,
new List<string>() { "Test vector data." },
new List<IList<Vector>>() { sampleValues });
var doc = Document.Current;
var grid = VectorAnalysisDisplay.ByViewAndVectorAnalysisData(doc.ActiveView, new []{data});
Assert.NotNull(grid);
}
示例13: GetLibrariesScript
private static string[] GetLibrariesScript()
{
string[] libraries = new[]
{
"~/Scripts/jquery-1.9.1.js",
"~/Scripts/jquery.address.js",
"~/Scripts/jquery-ui.js",
"~/Scripts/jquery-timePicker/jquery.timepicker.js",
"~/Scripts/shortcut.js",
"~/Scripts/colorbox/jquery.colorbox.js",
"~/Scripts/jqueryNumber/jquery.number.js",
"~/Scripts/date.js",
"~/Scripts/chartjs/Chart.min.js",
"~/Scripts/chartjs/legend.js",
"~/Scripts/notify-combined.min.js",
"~/Scripts/semantic-ui/semantic.js",
"~/Scripts/jquery.signalR.js",
"~/Scripts/vakata-jstree/dist/jstree.min.js",
"~/Scripts/momentjs/moment-with-locales.js",
"~/Scripts/underscore/underscore-min.js",
"~/Scripts/angular/angular.min.js",
"~/Scripts/linq.js/linq.js"
};
libraries = libraries.Concat(GetMixERPCoreScript()).ToArray();
return libraries;
}
示例14: TestCtor
public async Task TestCtor()
{
var blocks = new[] {
new TransformBlock<int, string>(i => i.ToString()),
new TransformBlock<int, string>(i => i.ToString(), new ExecutionDataflowBlockOptions { MaxMessagesPerTask = 1 }),
new TransformBlock<int, string>(i => Task.Run(() => i.ToString()), new ExecutionDataflowBlockOptions { MaxMessagesPerTask = 1 })
};
foreach (var block in blocks)
{
Assert.Equal(expected: 0, actual: block.InputCount);
Assert.Equal(expected: 0, actual: block.OutputCount);
Assert.False(block.Completion.IsCompleted);
}
blocks = new[] {
new TransformBlock<int, string>(i => i.ToString(),
new ExecutionDataflowBlockOptions { CancellationToken = new CancellationToken(true) }),
new TransformBlock<int, string>(i => Task.Run(() => i.ToString()),
new ExecutionDataflowBlockOptions { CancellationToken = new CancellationToken(true) })
};
foreach (var block in blocks)
{
Assert.Equal(expected: 0, actual: block.InputCount);
Assert.Equal(expected: 0, actual: block.OutputCount);
await Assert.ThrowsAnyAsync<OperationCanceledException>(() => block.Completion);
}
}
示例15: FindPath
public override IEnumerable<OperatorElement> FindPath(Element target)
{
var pathHere = new[] {this};
if (ReferenceEquals(Elements.Lhs, target) || ReferenceEquals(Elements.Rhs, target)) return pathHere;
var pathFromHere = Elements.Lhs.FindPath(target) ?? Elements.Rhs.FindPath(target);
return pathFromHere != null ? pathHere.Concat(pathFromHere) : null;
}