本文整理汇总了C#中IList.SingleOrDefault方法的典型用法代码示例。如果您正苦于以下问题:C# IList.SingleOrDefault方法的具体用法?C# IList.SingleOrDefault怎么用?C# IList.SingleOrDefault使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IList
的用法示例。
在下文中一共展示了IList.SingleOrDefault方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: SyncTestItemsIList
public void SyncTestItemsIList(ref IList<TestItem> source, ref IList<TestItem> destination)
{
foreach (var item in source)
{
var dest = destination.SingleOrDefault(d => d.Id == item.Id);
if (dest == null)
{
destination.Add(item);
}
else
{
if (dest.Sync < item.Sync)
{
destination[destination.IndexOf(dest)] = item.Clone();
}
}
}
foreach (var item in destination)
{
var sour = source.SingleOrDefault(s => s.Id == item.Id);
if (sour == null)
{
source.Add(item);
}
else
{
if (sour.Sync < item.Sync)
{
source[source.IndexOf(sour)] = item.Clone();
}
}
}
}
示例2: TableInfo
/// <summary>
/// Initialises a new instance of the <see cref="TableInfo"/> class.
/// </summary>
/// <param name="columns">The columns that are mapped for the table.</param>
/// <param name="identifierStrategy">The identifier strategy used by the table.</param>
/// <param name="name">The name of the table.</param>
/// <param name="schema">The database schema the table exists within (e.g. 'dbo'); otherwise null.</param>
/// <exception cref="ArgumentNullException">Thrown if columns or name are null.</exception>
/// <exception cref="MappingException">Thrown if no there is a problem with the column mappings.</exception>
public TableInfo(
IList<ColumnInfo> columns,
IdentifierStrategy identifierStrategy,
string name,
string schema)
{
if (columns == null)
{
throw new ArgumentNullException("columns");
}
if (name == null)
{
throw new ArgumentNullException("name");
}
this.columns = new ReadOnlyCollection<ColumnInfo>(columns);
this.identifierStrategy = identifierStrategy;
this.name = name;
this.schema = schema;
this.ValidateColumns();
this.identifierColumn = columns.SingleOrDefault(c => c.IsIdentifier);
this.insertColumnCount = columns.Count(c => c.AllowInsert);
this.updateColumnCount = columns.Count(c => c.AllowUpdate);
}
示例3: Render
/// <summary>
/// Generates SriptSharp files
/// </summary>
/// <param name="entries">List of jQueryUI entries.</param>
public void Render(IList<Entry> entries)
{
if (entries == null) {
return;
}
DirectoryInfo destination = new DirectoryInfo(DestinationPath);
if (destination.Exists) {
destination.Delete(true);
}
foreach (Entry entry in entries) {
Messages.WriteLine("Generating " + Path.Combine(DestinationPath, Utils.PascalCase(entry.Name)));
Entry baseEntry = null;
if (!string.IsNullOrEmpty(entry.Type)) {
// find the base entry
baseEntry = entries.SingleOrDefault(e => e.Name.ToLowerInvariant() == entry.Type.ToLowerInvariant());
}
RenderEntry(entry, baseEntry);
}
Messages.WriteLine("Generating jQueryUI base files.");
RenderEventHandler();
RenderBox();
RenderSize();
RenderEffectExtensionMethods(entries.Where(e => e.Category == "effects" && e.Name != "effect"));
RenderInteractionOrWidgetExtensionMethods("Interaction", entries.Where(e => e.Category == "interactions"));
RenderInteractionOrWidgetExtensionMethods("Widget", entries.Where(e => e.Category == "widgets" && e.Name != "widget"));
RenderPositionExtensionMethods(entries.Single(e => e.Name == "position"));
}
示例4: Execute
public void Execute(string[] args, IList<Directory> directoryies)
{
if(args.Length != 1)
throw new ArgumentException();
string[] fileinfos = args[0].Split('/');
if(fileinfos.Length != 2)
throw new ArgumentException();
var dirname = fileinfos[0];
var filename = fileinfos[1];
var targetdir = directoryies.SingleOrDefault(dir =>
{
return dir.Name.Equals(dirname);
});
if(targetdir == null)
throw new Exception("Directoryが存在しません");
if(targetdir.Contains(filename))
throw new Exception("Fileがすでに存在します");
targetdir.Add(new File(filename);
}
示例5: AddClaim
private async Task AddClaim(ApplicationUser user, IList<Claim> claims, string claim)
{
var roleType = "http://schemas.microsoft.com/ws/2008/06/identity/claims/role";
if (claims.SingleOrDefault(x => x.Type == roleType && x.Value == claim) == null)
await _userManager.AddClaimAsync(user, new Claim(roleType, claim, null));
}
示例6: Render
/// <summary>
/// Generates SriptSharp files
/// </summary>
/// <param name="entries">List of jQueryUI entries.</param>
public void Render(IList<Entry> entries)
{
if (entries == null) {
return;
}
DirectoryInfo destination = new DirectoryInfo(DestinationPath);
if (destination.Exists) {
destination.Delete(true);
}
foreach (Entry entry in entries) {
Messages.WriteLine("Generating " + Path.Combine(DestinationPath, Utils.PascalCase(entry.Name)));
Entry baseEntry = null;
if (!string.IsNullOrEmpty(entry.Type)) {
// find the base entry
baseEntry = entries.SingleOrDefault(e => e.Name.ToLower() == entry.Type.ToLower());
}
RenderEntry(entry, baseEntry);
}
RenderEventHandler();
RenderJQueryUI();
RenderWidgetType(entries);
}
示例7: RmDir
private void RmDir(string dirname, IList<Directory> directoryies)
{
var dirobj = directoryies.SingleOrDefault(dir => dir.Name.Equals(dirname));
if(dirobj == null)
new Exception("Directoryが存在しません");
directoryies.Remove(dirobj);
}
示例8: BuildBinaryInfo
private IBinaryInfo BuildBinaryInfo(IAddInfo addInfo, IList<IPackageEntry> fileInfos, IPackageEntry binaryFileInfo)
{
var binaryInfo = new BinaryInfo(addInfo);
binaryInfo.Name = Path.GetFileNameWithoutExtension(binaryFileInfo.FullPath);
binaryInfo.Type = Path.GetExtension(binaryFileInfo.FullPath).Substring(1);
binaryInfo.File = binaryFileInfo;
using (var stream = binaryFileInfo.Stream)
{
binaryInfo.Hash = binaryStoreManager.ReadBinaryHash(stream);
stream.Seek(0, SeekOrigin.Begin);
binaryInfo.SymbolHash = binaryStoreManager.ReadPdbHash(stream);
}
string symbolName = Path.ChangeExtension(binaryFileInfo.FullPath, "pdb");
var symbolFileInfo = fileInfos.SingleOrDefault(s => s.FullPath == symbolName);
if (symbolFileInfo != null)
{
var symbolInfo = new SymbolInfo(binaryInfo);
symbolInfo.Type = Path.GetExtension(symbolFileInfo.FullPath).Substring(1);
symbolInfo.File = symbolFileInfo;
using (var stream = symbolFileInfo.Stream)
{
symbolInfo.Hash = symbolStoreManager.ReadHash(stream);
}
symbolInfo.SourceInfos = sourceDiscover.FindSources(fileInfos, binaryInfo, symbolInfo).OrderBy(s => s.KeyPath).ToArray();
binaryInfo.SymbolInfo = symbolInfo;
}
string documentationName = Path.ChangeExtension(binaryFileInfo.FullPath, "xml");
var documentationFileInfo = fileInfos.SingleOrDefault(s => s.FullPath == documentationName);
if (documentationFileInfo != null)
{
var documentationInfo = new DocumentationInfo(binaryInfo);
documentationInfo.Type = Path.GetExtension(documentationFileInfo.FullPath).Substring(1);
documentationInfo.File = documentationFileInfo;
binaryInfo.DocumentationInfo = documentationInfo;
}
return binaryInfo;
}
示例9: ToApplicationRelativeUrl
internal static void ToApplicationRelativeUrl(IList<AttributeNode> attributes, string name)
{
var node = attributes.SingleOrDefault(x => x.Name == name);
if ((node != null) && (!node.Value.StartsWith("#")))
{
var newNode = AddMethodCallingToAttributeValue(node, Constants.TOAPPLICATIONRELATIVEURL);
attributes.Remove(node);
attributes.Add(newNode);
}
}
示例10: RmFile
private void RmFile(string dirname, string filename, IList<Directory> directoryies)
{
var dirobj = directoryies.SingleOrDefault(dir => dir.Name.Equals(dirname));
if(dirobj == null)
throw new Exception("Fileが存在しません");
if(!dirobj.Contains(filename))
throw new Exception("Fileが存在しません");
dirobj.Remove(filename);
}
示例11: AddApplyPathModifier
internal static void AddApplyPathModifier(IList<AttributeNode> attributes, string name)
{
//Response.ApplyAppPathModifier used not only to add cookie, it also resolves urls with ~.
var node = attributes.SingleOrDefault(x => x.Name == name);
if ((node != null)&&(!node.Value.StartsWith("#")))
{
var newNode = AddMethodCallingToAttributeValue(AddMethodCallingToAttributeValue(node,Constants.TOAPPLICATIONRELATIVEURL), Constants.APPLYAPPPATHMODIFIER);
attributes.Remove(node);
attributes.Add(newNode);
}
}
示例12: GetOrCreateSection
private ConfigSection GetOrCreateSection( IList<ConfigSection> sections, string sectionName )
{
var section = sections.SingleOrDefault( sec => sec.Name == sectionName );
if ( section == null )
{
section = new ConfigSection( sectionName );
sections.Add( section );
}
return section;
}
示例13: MvDir
private void MvDir(string dirname, string newdirname, IList<Directory> directoryies)
{
bool isExist = directoryies.Any(dir => dir.Name.Equals(newdirname));
if(isExist)
throw new Exception("移動先のDirectoryは存在します");
var dirobj = directoryies.SingleOrDefault(dir => dir.Name.Equals(dirname));
if(dirobj == null)
throw new Exception("移動元のDirectoryは存在します");
dirobj.Name = newdirname;
}
示例14: AddOrOverwrite
private void AddOrOverwrite( IList<ConfigSection> sections, ConfigSection section )
{
var existingSection = sections.SingleOrDefault( sec => sec.Name == section.Name );
if ( existingSection != null )
{
existingSection.Properties.Clear();
existingSection.Properties.AddRange( section.Properties );
}
else
{
sections.Add( section );
}
}
示例15: MvFile
private void MvFile(string dirname, string filename,
string newdirname, string newfilename, IList<Directory> directoryies)
{
var srcdir = directoryies.SingleOrDefault(dir => dir.Name.Equals(dirname));
if(srcdir == null)
throw new Exception("移動元Fileが存在しません");
if(!srcdir.Contains(filename))
throw new Exception("移動元Fileが存在しません");
var dstdir = directoryies.SingleOrDefault(dir => dir.Name.Equals(dirname));
if(dstdir == null)
throw new Exception("移動元Fileが存在しません");
if(!dstdir.Contains(filename))
throw new Exception("移動元Fileが存在しません");
var file = srcdir.Get(filename);
srcdir.Remove(filename);
file.Name = newfilename;
dstdir.Add(file);
}