本文整理汇总了C#中ImmutableList.Add方法的典型用法代码示例。如果您正苦于以下问题:C# ImmutableList.Add方法的具体用法?C# ImmutableList.Add怎么用?C# ImmutableList.Add使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ImmutableList
的用法示例。
在下文中一共展示了ImmutableList.Add方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: RecoursiveCheckGraph
private static bool RecoursiveCheckGraph(Task root, ImmutableList<Guid> previousTasks)
{
Contract.Requires(root != null);
Contract.Requires(root.Inputs != null);
Contract.Requires(previousTasks != null);
if (previousTasks.Contains(root.Id))
{
Logger.Write(
LogCategories.Error(string.Format(
"{0} is cycled.", root),
LogCategories.TaskServices));
return false;
}
foreach (var task in root.Inputs)
{
if (previousTasks.Contains(task.Id))
{
Logger.Write(
LogCategories.Error(string.Format(
"{0} is cycled.", task),
LogCategories.TaskServices));
return false;
}
if (!RecoursiveCheckGraph(task, previousTasks.Add(root.Id)))
return false;
}
return true;
}
示例2: ImmutableListAndObject
public void ImmutableListAndObject()
{
var list = new ImmutableList<ImmutableObject>();
list.Add(new ImmutableObject(1)).Add(new ImmutableObject(2));
Assert.Equal(2, list.Count);
list[0].CalculateDummyValue();
Assert.Equal(1, list[0].CallCount);
}
示例3: Add_ReturnsNewListWithNewItemAppended
public void Add_ReturnsNewListWithNewItemAppended()
{
var subject = new ImmutableList<int>();
var result = subject.Add(12);
Assert.AreEqual(0, subject.Count);
Assert.AreEqual(1, result.Count);
}
示例4: RecoursiveCheckGraph
private static bool RecoursiveCheckGraph(TaskRequest root, ImmutableList<Guid> previousTasks)
{
if (previousTasks.Contains(root.Id))
return false;
foreach (var task in root.Dependencies)
{
if (previousTasks.Contains(task.Id))
return false;
if (!RecoursiveCheckGraph(task, previousTasks.Add(root.Id)))
return false;
}
return true;
}
示例5: RecoursiveCheckGraph
private static bool RecoursiveCheckGraph(Japi.Task root, ImmutableList<Japi.Task> previousTasks)
{
if(previousTasks.Contains(root))
{
Console.WriteLine("1: {0}", root);
return false;
}
foreach(var task in root.Dependencies)
{
if(previousTasks.Contains(task))
{
Console.WriteLine("2: {0}", root);
return false;
}
if(!RecoursiveCheckGraph(task, previousTasks.Add(root)))
return false;
}
return true;
}
示例6: ReferenceFinders
static ReferenceFinders()
{
DefaultRenameReferenceFinders = ImmutableList.Create(
Constructor,
Destructor,
Event,
ExplicitInterfaceMethod,
Field,
Label,
Local,
MethodTypeParameter,
NamedType,
Namespace,
Operator,
OrdinaryMethod,
Parameter,
Property,
PropertyAccessor,
RangeVariable,
TypeParameter);
DefaultReferenceFinders = DefaultRenameReferenceFinders.Add(ConstructorInitializer);
}
示例7: VerifyRootPrincipal
private IProperty VerifyRootPrincipal(
IProperty principalProperty,
Dictionary<IProperty, IProperty> verifiedProperties,
ImmutableList<IForeignKey> visitedForeignKeys,
out string errorMessage)
{
errorMessage = null;
IProperty rootPrincipal;
if (verifiedProperties.TryGetValue(principalProperty, out rootPrincipal))
{
return rootPrincipal;
}
var rootPrincipals = new Dictionary<IProperty, IForeignKey>();
foreach (var foreignKey in principalProperty.DeclaringEntityType.GetForeignKeys())
{
for (var index = 0; index < foreignKey.Properties.Count; index++)
{
if (principalProperty == foreignKey.Properties[index])
{
var nextPrincipalProperty = foreignKey.PrincipalKey.Properties[index];
if (visitedForeignKeys.Contains(foreignKey))
{
var cycleStart = visitedForeignKeys.IndexOf(foreignKey);
var cycle = visitedForeignKeys.GetRange(cycleStart, visitedForeignKeys.Count - cycleStart);
errorMessage = Strings.CircularDependency(cycle.Select(fk => fk.ToString()).Join());
continue;
}
rootPrincipal = VerifyRootPrincipal(nextPrincipalProperty, verifiedProperties, visitedForeignKeys.Add(foreignKey), out errorMessage);
if (rootPrincipal == null)
{
if (principalProperty.RequiresValueGenerator)
{
rootPrincipals[principalProperty] = foreignKey;
}
continue;
}
if (principalProperty.RequiresValueGenerator)
{
ShowError(Strings.ForeignKeyValueGenerationOnAdd(
principalProperty.Name,
principalProperty.DeclaringEntityType.DisplayName(),
Property.Format(foreignKey.Properties)));
return principalProperty;
}
rootPrincipals[rootPrincipal] = foreignKey;
}
}
}
if (rootPrincipals.Count == 0)
{
if (errorMessage != null)
{
return null;
}
if (!principalProperty.RequiresValueGenerator)
{
ShowError(Strings.PrincipalKeyNoValueGenerationOnAdd(principalProperty.Name, principalProperty.DeclaringEntityType.DisplayName()));
return null;
}
return principalProperty;
}
if (rootPrincipals.Count > 1)
{
var firstRoot = rootPrincipals.Keys.ElementAt(0);
var secondRoot = rootPrincipals.Keys.ElementAt(1);
ShowWarning(Strings.MultipleRootPrincipals(
rootPrincipals[firstRoot].DeclaringEntityType.DisplayName(),
Property.Format(rootPrincipals[firstRoot].Properties),
firstRoot.DeclaringEntityType.DisplayName(),
firstRoot.Name,
Property.Format(rootPrincipals[secondRoot].Properties),
secondRoot.DeclaringEntityType.DisplayName(),
secondRoot.Name));
return firstRoot;
}
errorMessage = null;
rootPrincipal = rootPrincipals.Keys.Single();
verifiedProperties[principalProperty] = rootPrincipal;
return rootPrincipal;
}
示例8: GuildBank
public GuildBank(Guild guild, bool isNew)
{
Guild = guild;
BankTabs = new ImmutableList<GuildBankTab>(5);
if (isNew)
{
var tab = new GuildBankTab(this)
{
BankSlot = 0,
Icon = "",
Name = "Slot 0",
Text = ""
};
BankTabs.Add(tab);
}
else
{
var tabs = GuildBankTab.FindAllByProperty("_guildId", (int) guild.Id);
foreach (var tab in tabs)
{
BankTabs.Add(tab);
}
}
}
示例9: FreeVariableNames
public override ImmutableList<char> FreeVariableNames(ImmutableList<Symbol> boundVariables)
{
return _body.FreeVariableNames(boundVariables.Add(_variable));
}
示例10: RollbackUtxo
//TODO with the rollback information that's now being stored, rollback could be down without needing the block
public void RollbackUtxo(IChainStateCursor chainStateCursor, Chain chain, ChainedHeader chainedHeader, IEnumerable<BlockTx> blockTxes, ImmutableList<UnmintedTx>.Builder unmintedTxes)
{
//TODO don't reverse here, storage should be read in reverse
foreach (var blockTx in blockTxes.Reverse())
{
var tx = blockTx.Decode().Transaction;
var txIndex = blockTx.Index;
// remove transaction's outputs from utxo, except for the genesis block and the duplicate coinbases
var isDupeCoinbase = IsDupeCoinbase(chainedHeader, tx);
if (chainedHeader.Height > 0 && !isDupeCoinbase)
{
this.Unmint(chainStateCursor, tx, chainedHeader);
// decrease unspent output count
chainStateCursor.UnspentOutputCount -= tx.Outputs.Length;
// decrement unspent tx count
chainStateCursor.UnspentTxCount--;
chainStateCursor.TotalTxCount--;
chainStateCursor.TotalInputCount -= tx.Inputs.Length;
chainStateCursor.TotalOutputCount -= tx.Outputs.Length;
}
var prevTxOutputs = ImmutableArray.CreateBuilder<PrevTxOutput>(!tx.IsCoinbase ? tx.Inputs.Length : 0);
if (!tx.IsCoinbase)
{
// remove inputs in reverse order
for (var inputIndex = tx.Inputs.Length - 1; inputIndex >= 0; inputIndex--)
{
var input = tx.Inputs[inputIndex];
var prevTxOutput = this.Unspend(chainStateCursor, input, chainedHeader);
// store rollback replay information
prevTxOutputs.Add(prevTxOutput);
}
}
// reverse output keys to match original input order, as the inputs were read in reverse here
prevTxOutputs.Reverse();
// store rollback replay information
unmintedTxes.Add(new UnmintedTx(tx.Hash, prevTxOutputs.MoveToImmutable()));
}
}