本文整理汇总了C#中System.First方法的典型用法代码示例。如果您正苦于以下问题:C# System.First方法的具体用法?C# System.First怎么用?C# System.First使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System
的用法示例。
在下文中一共展示了System.First方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ArraysShouldBeRoundtrippable
public void ArraysShouldBeRoundtrippable()
{
new TestScheduler().With(sched =>
{
string path;
var input = new[] {new UserObject {Bio = "A totally cool cat!", Name = "octocat", Blog = "http://www.github.com"}, new UserObject {Bio = "zzz", Name = "sleepy", Blog = "http://example.com"}};
UserObject[] result;
using (Utility.WithEmptyDirectory(out path))
{
using (var fixture = CreateBlobCache(path))
{
fixture.InsertObject("key", input);
}
sched.Start();
using (var fixture = CreateBlobCache(path))
{
var action = fixture.GetObjectAsync<UserObject[]>("key");
sched.Start();
result = action.First();
}
}
Assert.Equal(input.First().Blog, result.First().Blog);
Assert.Equal(input.First().Bio, result.First().Bio);
Assert.Equal(input.First().Name, result.First().Name);
Assert.Equal(input.Last().Blog, result.Last().Blog);
Assert.Equal(input.Last().Bio, result.Last().Bio);
Assert.Equal(input.Last().Name, result.Last().Name);
});
}
示例2: ArraysShouldBeRoundtrippableUsingObjectFactory
public void ArraysShouldBeRoundtrippableUsingObjectFactory()
{
new TestScheduler().With(sched =>
{
string path;
var input = new[] {new UserModel(new UserObject()) {Age = 123, Name = "Old"}, new UserModel(new UserObject()) {Age = 123, Name = "Old"}};
UserModel[] result;
using (Utility.WithEmptyDirectory(out path))
{
using (var fixture = new TPersistentBlobCache(path))
{
fixture.InsertObject("key", input);
}
sched.Start();
using (var fixture = new TPersistentBlobCache(path))
{
var action = fixture.GetObjectAsync<UserModel[]>("key");
sched.Start();
result = action.First();
}
}
Assert.Equal(input.First().Age, result.First().Age);
Assert.Equal(input.First().Name, result.First().Name);
Assert.Equal(input.Last().Age, result.Last().Age);
Assert.Equal(input.Last().Name, result.Last().Name);
});
}
示例3: Main
public static void Main () {
var emptyInts = new int[0];
var ints = new[] { 1, 2, 3, 4 };
Console.WriteLine(emptyInts.FirstOrDefault());
Console.WriteLine(ints.FirstOrDefault());
Console.WriteLine(ints.First());
Console.WriteLine(emptyInts.FirstOrDefault((i) => i > 4));
Console.WriteLine(ints.FirstOrDefault((i) => i > 4));
Console.WriteLine(ints.First((i) => i > 2));
}
示例4: should_get_unmatched_nodes
public void should_get_unmatched_nodes(string name, StringComparison comparison, int count)
{
var results = new[] { new Node("oh"), new Node("hai") }
.GetUnmatchedNodes(new[] { new Node(name), new Node("crap") },
comparison);
results.ShouldTotal(count);
if (count == 1) results.First().Name.ShouldEqual("hai");
else
{
results.First().Name.ShouldEqual("oh");
results.Skip(1).First().Name.ShouldEqual("hai");
}
}
示例5: ExecuteWithResourceItems
public override void ExecuteWithResourceItems(System.Collections.Generic.IEnumerable<ResourceEditor.ViewModels.ResourceItem> resourceItems)
{
var firstSelectedItem = resourceItems.First();
if (firstSelectedItem != null) {
Clipboard.SetText(firstSelectedItem.Name);
}
}
示例6: Doit
public void Doit()
{
var c = new Customer
{
CustomerId = 3,
FirstName = "fn",
SecondName = "sn",
CustomerCountries =
new[] { new CustomerCountry { CountryId = 1 }, new CustomerCountry { CountryId = 2 } }
};
var countries = new[]
{
new Country {CountryId = 1, Name = "Moldova"},
new Country {CountryId = 2, Name = "Japan"}
};
var d = new CustomerDto();
d.InjectFrom(c);
Assert.AreEqual(c.CustomerId, d.CustomerId);
Assert.AreEqual(c.FirstName, d.FirstName);
Assert.AreEqual(c.SecondName, d.SecondName);
d.InjectFrom(new My(countries), c);
Assert.AreEqual(c.CustomerCountries.Count(), d.Countries.Count());
Assert.AreEqual(countries.First().Name, d.Countries.First().Name);
}
示例7: CreateMultiResolutionImage
public override object CreateMultiResolutionImage (System.Collections.Generic.IEnumerable<object> images)
{
var refImg = (WpfImage)images.First ();
var f = refImg.Frames[0];
var frames = images.Cast<WpfImage> ().Select (img => new WpfImage.ImageFrame (img.Frames[0].ImageSource, f.Width, f.Height));
return new WpfImage (frames);
}
示例8: Execute
public void Execute(string workingDirectory)
{
var possibleSqlCmdExePaths = new[]
{
Environment.ExpandEnvironmentVariables(@"%ProgramFiles%\Microsoft SQL Server\110\Tools\Binn\SQLCMD.EXE"),
Environment.ExpandEnvironmentVariables(@"%ProgramW6432%\Microsoft SQL Server\110\Tools\Binn\SQLCMD.EXE"),
Environment.ExpandEnvironmentVariables(@"%ProgramFiles%\Microsoft SQL Server\120\Tools\Binn\SQLCMD.EXE"),
Environment.ExpandEnvironmentVariables(@"%ProgramW6432%\Microsoft SQL Server\120\Tools\Binn\SQLCMD.EXE"),
};
var sqlCmdExePath = possibleSqlCmdExePaths.First(File.Exists);
var argumentStringBuilder = new StringBuilder();
foreach (var option in _options)
{
argumentStringBuilder.Append(string.Format("{0} {1} ", option.Key, option.Value));
}
var start = new ProcessStartInfo()
{
FileName = sqlCmdExePath,
WorkingDirectory = workingDirectory,
Arguments = argumentStringBuilder.ToString(),
UseShellExecute = false
};
Process.Start(start).WaitForExit();
}
示例9: ItShouldParsePathToProcessFromArgumentsArray
public void ItShouldParsePathToProcessFromArgumentsArray()
{
var args = new[] {"path/to/app.exe"};
var spec = GetSpecWithArgs(args);
Assert.That(spec.PathToProcess, Is.EqualTo(args.First()));
}
示例10: GetMemberUploadDataHandler_WithSeveralErrors_MappedCorrectly
public async Task GetMemberUploadDataHandler_WithSeveralErrors_MappedCorrectly()
{
var memberUploadsWithSeveralErrors = new[]
{
new MemberUpload(
pcsId,
"FAKE DATA",
new List<MemberUploadError>
{
new MemberUploadError(ErrorLevel.Warning, UploadErrorType.Schema, "FAKE WARNING"),
new MemberUploadError(ErrorLevel.Error, UploadErrorType.Business, "FAKE ERROR"),
new MemberUploadError(ErrorLevel.Error, UploadErrorType.Schema, "FAKE ERROR"),
new MemberUploadError(ErrorLevel.Fatal, UploadErrorType.Business, "FAKE FATAL"),
new MemberUploadError(ErrorLevel.Fatal, UploadErrorType.Schema, "FAKE FATAL"),
new MemberUploadError(ErrorLevel.Fatal, UploadErrorType.Business, "FAKE FATAL")
},
0,
2016,
A.Dummy<Scheme>(),
"File name")
};
var handler = GetPreparedHandler(memberUploadsWithSeveralErrors);
var memberUploadErrorDataList =
await handler.HandleAsync(new GetMemberUploadData(pcsId, memberUploadsWithSeveralErrors.First().Id));
Assert.True(memberUploadErrorDataList.Count(me => me.ErrorLevel == Core.Shared.ErrorLevel.Warning) == 1);
Assert.True(memberUploadErrorDataList.Count(me => me.ErrorLevel == Core.Shared.ErrorLevel.Error) == 2);
Assert.True(memberUploadErrorDataList.Count(me => me.ErrorLevel == Core.Shared.ErrorLevel.Fatal) == 3);
}
示例11: OldRequestIsThrownAwayIfNewOneArrives
public void OldRequestIsThrownAwayIfNewOneArrives()
{
var networkStatus = Substitute.For<INetworkStatus>();
networkStatus.IsAvailable.Returns(Observable.Return(true));
using (var library = Helpers.CreateLibrary())
{
new TestScheduler().With(scheduler =>
{
var songs = new[] { new YoutubeSong("http://blabla.com", TimeSpan.Zero) };
// Define that the old request takes longer than the new request
var firstReturn = Observable.Timer(TimeSpan.FromSeconds(2000), scheduler).Select(x => (IReadOnlyList<YoutubeSong>)new List<YoutubeSong>()).ToTask();
var secondReturn = Task.FromResult((IReadOnlyList<YoutubeSong>)new List<YoutubeSong>(songs));
var songFinder = Substitute.For<IYoutubeSongFinder>();
songFinder.GetSongsAsync(Arg.Any<string>()).Returns(firstReturn, secondReturn);
Guid token = library.LocalAccessControl.RegisterLocalAccessToken();
var vm = new YoutubeViewModel(library, new ViewSettings(), new CoreSettings(), token, networkStatus, songFinder);
vm.SearchText = "Request1";
scheduler.AdvanceByMs(501);
vm.SearchText = "Request2";
scheduler.AdvanceByMs(501);
scheduler.AdvanceByMs(2000);
Assert.Equal(songs.First().OriginalPath, vm.SelectableSongs.First().Path);
});
}
}
示例12: Start
public void Start()
{
var sp = Stopwatch.StartNew();
var reader = Task.Factory.StartNew(ReadFile);
var parser = Task.Factory.StartNew(ParseEntries);
var processer = Task.Factory.StartNew(ProcessDisks);
while (true)
{
var tasks = new[] { reader, parser, processer, Task.Delay(1000) };
var array = tasks
.Where(x => x.IsCompleted == false)
.ToArray();
if (tasks.Any(x => x.IsFaulted))
{
tasks.First(x => x.IsFaulted).Wait();
}
if (array.Length <= 1)
break;
Task.WaitAny(array);
Console.Write("\r{0,10:#,#} sec reads: {1,10:#,#} parsed: {2,10:#,#} written: {3,10:#,#}", sp.Elapsed.TotalSeconds, reads,
parsed, writtern);
}
Console.WriteLine();
Console.WriteLine("Total");
Console.WriteLine("{0,10:#,#} reads: {1:10:#,#} parsed: {2:10:#,#} written: {3:10:#,#}", sp.ElapsedMilliseconds, reads,
parsed, writtern);
}
示例13: ResolvePath
public virtual IEnumerable<INodeFactory> ResolvePath(IContext context, string path)
{
Regex re = new Regex(@"^[-_a-z0-9:]+:/?");
path = path.ToLowerInvariant().Replace('\\', '/');
path = re.Replace(path, "");
var factory = Root;
var nodeMonikers = path.Split(new char[] { '/' }, StringSplitOptions.RemoveEmptyEntries);
IEnumerable<INodeFactory> factories = new[] {factory};
foreach (var nodeMoniker in nodeMonikers )
{
factories = factory.Resolve(context, nodeMoniker);
if (null == factories || !factories.Any())
{
return null;
}
factory = factories.First();
}
return factories;
}
示例14: ResolvePath
public virtual IEnumerable<IPathNode> ResolvePath(IProviderContext providerContext, string path)
{
if (string.IsNullOrEmpty(path))
throw new ArgumentNullException(nameof(path));
Regex re = new Regex(@"^[-_a-z0-9:]+:/?");
path = path.ToLowerInvariant().Replace('\\', '/');
path = re.Replace(path, "");
var factory = Root;
var nodeMonikers = path.Split(new char[] { '/' }, StringSplitOptions.RemoveEmptyEntries);
IEnumerable<IPathNode> factories = new[] { factory };
foreach (var nodeMoniker in nodeMonikers)
{
factories = factory.Resolve(providerContext, nodeMoniker);
if (null == factories || !factories.Any())
{
return null;
}
factory = factories.First();
}
return factories;
}
示例15: PathEquals
public static void PathEquals(this Uri u, string pathAndQueryString)
{
var paths = (pathAndQueryString ?? "").Split(new[] { '?' }, 2);
string path = paths.First(), query = string.Empty;
if (paths.Length > 1)
query = paths.Last();
var expectedUri = new UriBuilder("http", "localhost", u.Port, path, "?" + query).Uri;
u.AbsolutePath.Should().Be(expectedUri.AbsolutePath);
u = new UriBuilder(u.Scheme, u.Host, u.Port, u.AbsolutePath, u.Query.Replace("pretty=true&", "").Replace("pretty=true", "")).Uri;
var queries = new[] { u.Query, expectedUri.Query };
if (queries.All(string.IsNullOrWhiteSpace)) return;
if (queries.Any(string.IsNullOrWhiteSpace))
{
queries.Last().Should().Be(queries.First());
return;
}
var clientKeyValues = u.Query.Substring(1).Split('&')
.Select(v => v.Split('='))
.Where(k => !string.IsNullOrWhiteSpace(k[0]))
.ToDictionary(k => k[0], v => v.Last());
var expectedKeyValues = expectedUri.Query.Substring(1).Split('&')
.Select(v => v.Split('='))
.Where(k => !string.IsNullOrWhiteSpace(k[0]))
.ToDictionary(k => k[0], v => v.Last());
clientKeyValues.Count.Should().Be(expectedKeyValues.Count);
clientKeyValues.Should().ContainKeys(expectedKeyValues.Keys.ToArray());
clientKeyValues.Should().Equal(expectedKeyValues);
}