本文整理汇总了C#中System.Linq.All方法的典型用法代码示例。如果您正苦于以下问题:C# System.Linq.All方法的具体用法?C# System.Linq.All怎么用?C# System.Linq.All使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Linq
的用法示例。
在下文中一共展示了System.Linq.All方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Execute
public void Execute()
{
//
// All拡張メソッドは、シーケンスの全要素が指定された条件に合致しているか否かを判別するメソッドである。
//
// 引数には条件としてpredicateを指定する。
// このメソッドは、対象シーケンス内の全要素が条件に合致している場合のみTrueを返す。
// (逆にAny拡張メソッドは、一つでも合致するものが存在した時点でTrueとなる。)
//
var names = new[] {"gsf_zero1", "gsf_zero2", "gsf_zero3", "2222"};
Output.WriteLine("Allメソッドの結果 = {0}", names.All(item => char.IsDigit(item.Last())));
Output.WriteLine("Allメソッドの結果 = {0}", names.All(item => item.StartsWith("g")));
Output.WriteLine("Allメソッドの結果 = {0}", names.All(item => !string.IsNullOrEmpty(item)));
}
示例2: TextTypeTests
public void TextTypeTests()
{
// Text
var formats = new[] { "css", "csv", "txt", "xml" };
Assert.True(formats.All(format => Mime.FromFormat(format).Type == MediaType.Text));
}
示例3: UpdateAppBar
private void UpdateAppBar()
{
var pool = ( (EventPoolViewModel) DataContext ).Pool;
if ( pool == null )
{
return;
}
var commandButtons = new[] { CategoriesButton, TagsButton, ScanCodeButton, RequestFavoriteEmailButton };
foreach ( var button in commandButtons )
{
button.Visibility = button.Command.CanExecute( null ) ? Visibility.Visible : Visibility.Collapsed;
}
SettingsButton.Visibility = pool.Id == EventPool.RootId ? Visibility.Visible : Visibility.Collapsed;
if ( commandButtons.All( b => b.Visibility == Visibility.Collapsed ) && SettingsButton.Visibility == Visibility.Collapsed )
{
BottomAppBar.Visibility = Visibility.Collapsed;
}
else
{
BottomAppBar.Visibility = Visibility.Visible;
}
}
示例4: VideoTypeTests
public void VideoTypeTests()
{
Assert.Equal(MediaType.Video, Mime.FromPath("DemoReel_01.10.13-HD for Apple Devices.m4v").Type);
Assert.Equal("mp4", Mime.FromPath("DemoReel_01.10.13-HD for Apple Devices.m4v").Format);
var formats = new[] { "avi", "f4v", "flv", "m4v", "mp4", "mpg", "mpeg", "qt", "webm", "wmv" };
Assert.True(formats.All(format => Mime.FromFormat(format).Type == MediaType.Video));
}
示例5: EachExecutesActionOnEachEnumeratedElement
public void EachExecutesActionOnEachEnumeratedElement()
{
var elements = new[]
{
new IntContainer(),
new IntContainer(),
new IntContainer()
};
elements.Each( x => x.Number++ );
Assert.IsTrue( elements.All( x=>x.Number == 1 ) );
}
示例6: BuildContainer_ContainerHasAllExpectedServices
public void BuildContainer_ContainerHasAllExpectedServices(
ContainerBuilder builder,
RepositoryModule sut)
{
// Given
var expectedServices = new[] { typeof(IUnitOfWork), typeof(IRepository<>) };
// When
builder.RegisterModule(sut);
var container = builder.Build();
// Then
Assert.True(expectedServices.All(container.IsRegistered));
}
示例7: IsValueValid
public override bool IsValueValid(string value, ApiHttpClient apiClient)
{
if (value.HasValue() && !File.Exists(value))
{
Program.WriteWarning("The file '" + value + "' in column '" + Header + "' does not exist or is not accessible.");
return false;
}
var extension = (Path.GetExtension(value) ?? "").Trim('.').ToLowerInvariant();
var allowedExtensions = new[] { "jpg", "jpeg", "png", "bmp" };
if (allowedExtensions.All(x => x != extension))
{
Program.WriteWarning("The file '" + value + "' in column '" + Header + "' does not have a valid file extension for a photo.");
return false;
}
return true;
}
示例8: Does_resolve_nested_files_and_folders
public void Does_resolve_nested_files_and_folders()
{
var pathProvider = GetPathProvider();
var allFilePaths = new[] {
"testfile.txt",
"a/testfile-a1.txt",
"a/testfile-a2.txt",
"a/b/testfile-ab1.txt",
"a/b/testfile-ab2.txt",
"a/b/c/testfile-abc1.txt",
"a/b/c/testfile-abc2.txt",
"a/d/testfile-ad1.txt",
"e/testfile-e1.txt",
};
allFilePaths.Each(x => pathProvider.WriteFile(x, x.SplitOnLast('.').First().SplitOnLast('/').Last()));
Assert.That(allFilePaths.All(x => pathProvider.IsFile(x)));
Assert.That(new[] { "a", "a/b", "a/b/c", "a/d", "e" }.All(x => pathProvider.IsDirectory(x)));
Assert.That(!pathProvider.IsFile("notfound.txt"));
Assert.That(!pathProvider.IsFile("a/notfound.txt"));
Assert.That(!pathProvider.IsDirectory("f"));
Assert.That(!pathProvider.IsDirectory("a/f"));
Assert.That(!pathProvider.IsDirectory("testfile.txt"));
Assert.That(!pathProvider.IsDirectory("a/testfile-a1.txt"));
AssertContents(pathProvider.RootDirectory, new[] {
"testfile.txt",
}, new[] {
"a",
"e"
});
AssertContents(pathProvider.GetDirectory("a"), new[] {
"a/testfile-a1.txt",
"a/testfile-a2.txt",
}, new[] {
"a/b",
"a/d"
});
AssertContents(pathProvider.GetDirectory("a/b"), new[] {
"a/b/testfile-ab1.txt",
"a/b/testfile-ab2.txt",
}, new[] {
"a/b/c"
});
AssertContents(pathProvider.GetDirectory("a").GetDirectory("b"), new[] {
"a/b/testfile-ab1.txt",
"a/b/testfile-ab2.txt",
}, new[] {
"a/b/c"
});
AssertContents(pathProvider.GetDirectory("a/b/c"), new[] {
"a/b/c/testfile-abc1.txt",
"a/b/c/testfile-abc2.txt",
}, new string[0]);
AssertContents(pathProvider.GetDirectory("a/d"), new[] {
"a/d/testfile-ad1.txt",
}, new string[0]);
AssertContents(pathProvider.GetDirectory("e"), new[] {
"e/testfile-e1.txt",
}, new string[0]);
Assert.That(pathProvider.GetFile("a/b/c/testfile-abc1.txt").ReadAllText(), Is.EqualTo("testfile-abc1"));
Assert.That(pathProvider.GetDirectory("a").GetFile("b/c/testfile-abc1.txt").ReadAllText(), Is.EqualTo("testfile-abc1"));
Assert.That(pathProvider.GetDirectory("a/b").GetFile("c/testfile-abc1.txt").ReadAllText(), Is.EqualTo("testfile-abc1"));
Assert.That(pathProvider.GetDirectory("a").GetDirectory("b").GetDirectory("c").GetFile("testfile-abc1.txt").ReadAllText(), Is.EqualTo("testfile-abc1"));
var dirs = pathProvider.RootDirectory.Directories.Map(x => x.VirtualPath);
Assert.That(dirs, Is.EquivalentTo(new[] { "a", "e" }));
var rootDirFiles = pathProvider.RootDirectory.GetAllMatchingFiles("*", 1).Map(x => x.VirtualPath);
Assert.That(rootDirFiles, Is.EquivalentTo(new[] { "testfile.txt" }));
var allFiles = pathProvider.GetAllMatchingFiles("*").Map(x => x.VirtualPath);
Assert.That(allFiles, Is.EquivalentTo(allFilePaths));
allFiles = pathProvider.GetAllFiles().Map(x => x.VirtualPath);
Assert.That(allFiles, Is.EquivalentTo(allFilePaths));
pathProvider.DeleteFile("testfile.txt");
pathProvider.DeleteFolder("a");
pathProvider.DeleteFolder("e");
Assert.That(pathProvider.GetAllFiles().ToList().Count, Is.EqualTo(0));
}
示例9: Then_only_connected_node_should_be_visited_01
public void Then_only_connected_node_should_be_visited_01()
{
var startingNode = _graph.Nodes.Single(n => n.Label == 1);
_bfs.Execute(startingNode);
var visited = new[] { 1, 3, 5, 7, 9 };
visited.All(v => _graph.Nodes.Single(n => n.Label == v).Visited).ShouldBeTrue();
_graph.Nodes.Where(n => !visited.Contains(n.Label)).All(n => n.Visited).ShouldBeFalse();
}
示例10: ImageTypeTests
public void ImageTypeTests()
{
var formats = new[] { "bmp", "gif", "ico", "jpg", "jpeg", "jxr", "png", "tif", "tiff", "webp" };
Assert.True(formats.All(format => Mime.FromFormat(format).Type == MediaType.Image));
}
示例11: AudioTypeTests
public void AudioTypeTests()
{
var formats = new[] { "aiff", "aif", "aac", "mp3", "m4a", "opus", "ra", "wav", "wma" };
Assert.True(formats.All(format => Mime.FromFormat(format).Type == MediaType.Audio));
}
示例12: ApplicationTypeTests
public void ApplicationTypeTests()
{
var formats = new[] { "js", "json", "swf", "xap", "zip" };
Assert.True(formats.All(format => Mime.FromFormat(format).Type == MediaType.Application));
}