本文整理汇总了C#中HashSet.Except方法的典型用法代码示例。如果您正苦于以下问题:C# HashSet.Except方法的具体用法?C# HashSet.Except怎么用?C# HashSet.Except使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类HashSet
的用法示例。
在下文中一共展示了HashSet.Except方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: PrintChanges
/// <summary>
/// Locates the changes between the prior and post state of the modules..
/// </summary>
/// <param name="modules_prior">List of the available modules prior to the update.</param>
/// <param name="modules_post">List of the available modules after the update.</param>
private void PrintChanges(List<CkanModule> modules_prior, List<CkanModule> modules_post)
{
var prior = new HashSet<CkanModule>(modules_prior, new NameComparer());
var post = new HashSet<CkanModule>(modules_post, new NameComparer());
var added = new HashSet<CkanModule>(post.Except(prior, new NameComparer()));
var removed = new HashSet<CkanModule>(prior.Except(post, new NameComparer()));
var unchanged = post.Intersect(prior);//Default compare includes versions
var updated = post.Except(unchanged).Except(added).Except(removed).ToList();
// Print the changes.
user.RaiseMessage("Found {0} new modules, {1} removed modules and {2} updated modules.", added.Count(), removed.Count(), updated.Count());
if (added.Count > 0)
{
PrintModules("New modules [Name (CKAN identifier)]:", added);
}
if (removed.Count > 0)
{
PrintModules("Removed modules [Name (CKAN identifier)]:", removed);
}
if (updated.Count > 0)
{
PrintModules("Updated modules [Name (CKAN identifier)]:", updated);
}
}
示例2: OnUpdateList
public override void OnUpdateList ()
{
base.OnUpdateList ();
StackFrame frame = DebuggingService.CurrentFrame;
if (frame == null || !FrameEquals (frame, lastFrame)) {
tree.ClearExpressions ();
lastExpressions = null;
}
lastFrame = frame;
if (frame == null)
return;
//FIXME: tree should use the local refs rather than expressions. ATM we exclude items without names
var expr = new HashSet<string> (frame.GetAllLocals ().Select (i => i.Name)
.Where (n => !string.IsNullOrEmpty (n) && n != "?"));
//add expressions not in tree already, remove expressions that are longer valid
if (lastExpressions != null) {
foreach (string rem in lastExpressions.Except (expr))
tree.RemoveExpression (rem);
foreach (string rem in expr.Except (lastExpressions))
tree.AddExpression (rem);
} else {
tree.AddExpressions (expr);
}
lastExpressions = expr;
}
示例3: GetBusinessDays
public static List<DateTime> GetBusinessDays(DateTime dateFrom, DateTime dateTo)
{
HashSet<DateTime> holidays = new HashSet<DateTime>();
HashSet<DateTime> businessDaysSet = new HashSet<DateTime>();
for (int year=dateFrom.Year; year<=dateTo.Year; year++)
{
HashSet<DateTime> holidayList = GetHolidays(year);
holidays.UnionWith(holidayList);
}
for (var dt = dateFrom; dt <= dateTo; dt = dt.AddDays(1))
{if ((dt.DayOfWeek == DayOfWeek.Saturday) || (dt.DayOfWeek == DayOfWeek.Sunday))
continue;
else
businessDaysSet.Add(dt);
}
List<DateTime> businessDays = businessDaysSet.Except(holidays).ToList();
businessDays.Sort((a,b)=>a.CompareTo(b));
return businessDays;
}
示例4: LoadTagCoroutine
IEnumerator LoadTagCoroutine(string id, string sceneName, string tagName)
{
var before = new HashSet<GameObject>((GameObject[])GameObject.FindObjectsOfType(typeof(GameObject)));
Application.LoadLevelAdditive(sceneName);
yield return new WaitForEndOfFrame();
var after = new HashSet<GameObject>((GameObject[])GameObject.FindObjectsOfType(typeof(GameObject)));
var newObjects = after.Except(before).ToList();
var destroy = newObjects.Where (arg => arg.tag != tagName).ToArray();
foreach(var i in destroy)
{
var parent = i.transform.parent;
while(parent && parent.tag != tagName)
{
parent = parent.transform.parent;
}
if(parent)
continue;
GameObject.DestroyImmediate(i);
}
newObjects.RemoveAll((obj) => !obj);
Group.AddToGroup(id, newObjects);
}
示例5: AllValuesInArrayAreIndexed
public void AllValuesInArrayAreIndexed()
{
var coll = GetCollection();
// Make sure property Tags is indexed
coll.Indices.EnsureIndex("Tags");
// Insert something where Tags is list of values
const string key = "a key of some sort";
var values = new HashSet<object> {"A", "B", DateTime.Now, null, Math.PI};
coll.Update(key, new {Tags = values});
// Now, extract what the index really contains
var indexContent = new List<KeyValuePair<IndexValue, string>>();
coll.Indices.VisitIndex("Tags", indexContent.Add);
// First of all, each index entry must point to our key
foreach (var kv in indexContent)
{
Assert.AreEqual(key, kv.Value);
}
// Second, the index should contain the array values
var indexValues = new HashSet<object>(indexContent.Select(kv => kv.Key.Value));
Assert.AreEqual(0, indexValues.Except(values).Count(), "Index values are too many");
Assert.AreEqual(0, values.Except(indexValues).Count(), "Index values are too feew");
}
示例6: DiffInputs
public DiffResult DiffInputs(CompilerIO other)
{
var myInputSet = new HashSet<string>(Inputs);
var otherInputSet = new HashSet<string>(other.Inputs);
var additions = myInputSet.Except(otherInputSet);
var deletions = otherInputSet.Except(myInputSet);
return new DiffResult(additions, deletions);
}
示例7: LoadCoroutine
IEnumerator LoadCoroutine(string id, string sceneName)
{
var before = new HashSet<GameObject>((GameObject[])GameObject.FindObjectsOfType(typeof(GameObject)));
Application.LoadLevelAdditive(sceneName);
yield return 0;
var after = new HashSet<GameObject>((GameObject[])GameObject.FindObjectsOfType(typeof(GameObject)));
var newObjects = after.Except(before).ToList();
Group.AddToGroup(id, newObjects);
}
示例8: CanSetValues
/// <summary>
/// 检查要设置的值是否存在于候选值列表中
/// </summary>
/// <param name="values">所要设置的值</param>
/// <param name="message">若不能设置,获取错误信息</param>
/// <returns>是否可以设置</returns>
protected virtual bool CanSetValues( HashSet<string> values, out string message )
{
var invalidValue = values.Except( CandidateValues ).FirstOrDefault();
if ( invalidValue != null && !Form.Configuration.IgnoreInvailidValuesInGroupControl )//如果有一个设置的值不在候选值列表
{
message = string.Format( "不能对控件设置值 \"{0}\"", invalidValue.First() );
return false;
}
message = null;
return true;
}
示例9: Run
public void Run(Action<string> emitError, Action<string> emitWarning, Ruleset rules)
{
foreach (var actorInfo in rules.Actors)
{
if (actorInfo.Key.StartsWith("^", StringComparison.Ordinal))
continue;
var granted = new HashSet<string>();
var consumed = new HashSet<string>();
foreach (var trait in actorInfo.Value.TraitInfos<ITraitInfo>())
{
var fieldConsumed = trait.GetType().GetFields()
.Where(x => x.HasAttribute<ConsumedConditionReferenceAttribute>())
.SelectMany(f => LintExts.GetFieldValues(trait, f, emitError));
var propertyConsumed = trait.GetType().GetProperties()
.Where(x => x.HasAttribute<ConsumedConditionReferenceAttribute>())
.SelectMany(p => LintExts.GetPropertyValues(trait, p, emitError));
var fieldGranted = trait.GetType().GetFields()
.Where(x => x.HasAttribute<GrantedConditionReferenceAttribute>())
.SelectMany(f => LintExts.GetFieldValues(trait, f, emitError));
var propertyGranted = trait.GetType().GetProperties()
.Where(x => x.HasAttribute<GrantedConditionReferenceAttribute>())
.SelectMany(f => LintExts.GetPropertyValues(trait, f, emitError));
foreach (var c in fieldConsumed.Concat(propertyConsumed))
if (!string.IsNullOrEmpty(c))
consumed.Add(c);
foreach (var g in fieldGranted.Concat(propertyGranted))
if (!string.IsNullOrEmpty(g))
granted.Add(g);
}
var unconsumed = granted.Except(consumed);
if (unconsumed.Any())
emitWarning("Actor type `{0}` grants conditions that are not consumed: {1}".F(actorInfo.Key, unconsumed.JoinWith(", ")));
var ungranted = consumed.Except(granted);
if (ungranted.Any())
emitError("Actor type `{0}` consumes conditions that are not granted: {1}".F(actorInfo.Key, ungranted.JoinWith(", ")));
if ((consumed.Any() || granted.Any()) && actorInfo.Value.TraitInfoOrDefault<UpgradeManagerInfo>() == null)
emitError("Actor type `{0}` defines conditions but does not include an UpgradeManager".F(actorInfo.Key));
}
}
示例10: Refresh
public ActionResult Refresh()
{
var directory = HostingEnvironment.VirtualPathProvider.GetDirectory( VirtualPathUtility.ToAbsolute( templatePath ) );
var data = new HashSet<string>( dbUtility.Data( "SELECT virtualPath FROM Templates " ).Column<string>(), StringComparer.OrdinalIgnoreCase );
var local = new HashSet<string>( SearchFiles( directory ).Select( f => VirtualPathUtility.ToAppRelative( f.VirtualPath ) ) );
foreach ( var virtualPath in local.Except( data ) )
dbUtility.NonQuery( "INSERT INTO Templates ( virtualPath ) VALUES ( {0} )", virtualPath );
foreach ( var virtualPath in data.Except( local ) )
dbUtility.NonQuery( "DELETE Templates WHERE virtualPath = {0}", virtualPath );
return RedirectToAction( "List" );
}
示例11: Update
public static void Update()
{
currentState = Keyboard.GetState();
HashSet <Keys> currentKeySet = new HashSet <Keys> (currentState.GetPressedKeys());
IEnumerable <Keys> pressedKeys = currentKeySet.Except(previousKeySet);
IEnumerable <Keys> releasedKeys = previousKeySet.Except(currentKeySet);
if (pressedKeys.Count() > 0) {
FireKeyPressed(new KeyEvent(pressedKeys));
}
if (releasedKeys.Count() > 0) {
FireKeyReleased(new KeyEvent(releasedKeys));
}
previousKeySet = currentKeySet;
previousState = currentState;
}
示例12: AllStatesCanBeReached
public static void AllStatesCanBeReached(IEnumerable<State> states)
{
var allStates = new HashSet<State>(states);
var visitedStates = new HashSet<State>();
TraverseStateGraph(states.First(), visitedStates);
var unreachableStates = allStates.Except(visitedStates).ToList();
if (unreachableStates.Count != 0)
{
Console.WriteLine("Unreachable states:");
foreach (var unreachableState in unreachableStates)
{
Console.WriteLine(unreachableState.Name);
}
}
Assert.Equal(allStates.Count, visitedStates.Count);
}
示例13: crossCheck
// cross check /Resources/Prefabs and Levels.xml if there are any item prefabs that exist only in one but not the other
public void crossCheck()
{
// create a two sets of prefabs
HashSet<string> resPrefabSet = new HashSet<string>();
HashSet<string> xmlPrefabSet = new HashSet<string>();
// Get prefabs from Levels.xml
getLevelPrefabs(xmlPrefabSet);
// Get prefabs from the /Resources/Prefabs folder
getResPrefabs(resPrefabSet);
// Cross checks
foreach (string prefab in xmlPrefabSet.Except(resPrefabSet).ToList())
Debug.LogError(prefab + " is missing in the /Resorces/Prefabs folder but used in Levels.xml");
foreach (string prefab in resPrefabSet.Except(xmlPrefabSet).ToList())
Debug.Log(prefab + " exists in the /Resorces/Prefabs folder but not used in Levels.xml");
Debug.Log("Cross Check Done");
}
示例14: AssertNumberOfResultsIsConsistentOnRecompile
public void AssertNumberOfResultsIsConsistentOnRecompile(IEnumerable<IViewComputationResultModel> results)
{
HashSet<Tuple<string, ValueSpecification>> values = null;
foreach (var result in results)
{
Assert.NotNull(result);
var newValues = new HashSet<Tuple<string, ValueSpecification>>(result.AllResults.Select(r => Tuple.Create(r.CalculationConfiguration, r.ComputedValue.Specification)));
if (values != null)
{
if (!values.SetEquals(newValues))
{
var missing = values.Except(newValues).ToList();
var added = newValues.Except(values).ToList();
throw new Exception(string.Format("Previously missing {0} results, now {1}. Missing {2}. Added {3}", values.Count, newValues.Count, String.Join(",", missing), String.Join(",", added)));
}
}
else
{
values = newValues;
}
}
}
示例15: Should_Return_All_Metadata_From_Metadata_Repository_OnGet
public void Should_Return_All_Metadata_From_Metadata_Repository_OnGet()
{
// Arrange
var queryableList = this.ConstructQueryableList();
MetadataController controller = new MetadataController();
var metadataRepositoryMock = new Mock<IMetadataRepository>();
metadataRepositoryMock.Setup(x => x.GetAll()).Returns(queryableList).Verifiable();
controller.MetadataRepository = metadataRepositoryMock.Object;
// Act
var actionResult = controller.Get();
// Assert
GenericValueResult<IEnumerable<Models.MetadataInfo>> results = actionResult as GenericValueResult<IEnumerable<Models.MetadataInfo>>;
results.Should().NotBeNull("Wrong data type was returned from the controller");
results.Value.Count().Should().Be(queryableList.Count());
HashSet<int> receivedIds = new HashSet<int>(results.Value.Select(x => x.Id.Value).AsEnumerable());
HashSet<int> expectedIds = new HashSet<int>(queryableList.Select(x => x.Id).AsEnumerable());
expectedIds.Except(receivedIds).Count().Should().Be(0, "Result list should contain all the same IDs as the list in Repository");
metadataRepositoryMock.VerifyAll();
}