本文整理汇总了C#中ConcurrentBag.Except方法的典型用法代码示例。如果您正苦于以下问题:C# ConcurrentBag.Except方法的具体用法?C# ConcurrentBag.Except怎么用?C# ConcurrentBag.Except使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ConcurrentBag
的用法示例。
在下文中一共展示了ConcurrentBag.Except方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ProcessTypes
//.........这里部分代码省略.........
foreach (UserType userType in newTypes.Concat(userTypes))
{
userType.ClassName = userType.OriginalClassName;
if (userType.DeclaredInType != null && userType.OriginalClassName == userType.DeclaredInType.ClassName)
{
userType.ClassName += "_";
}
TemplateUserType templateUserType = userType as TemplateUserType;
if (templateUserType != null)
{
foreach (UserType specializedUserType in templateUserType.SpecializedTypes)
{
specializedUserType.ClassName = userType.ClassName;
}
}
}
// Remove duplicate types from exported template types (TODO: Remove this when template types start checking subtypes)
foreach (UserType userType in userTypes)
{
TemplateUserType templateType = userType as TemplateUserType;
if (templateType == null)
continue;
HashSet<string> uniqueTypes = new HashSet<string>();
foreach (var innerType in templateType.InnerTypes.ToArray())
{
string className;
if (!(innerType is NamespaceUserType))
className = innerType.ClassName;
else
className = innerType.Namespace;
if (uniqueTypes.Contains(className))
templateType.InnerTypes.Remove(innerType);
else
uniqueTypes.Add(className);
}
}
// Find all derived classes
foreach (UserType userType in userTypes)
{
// We are doing this only for UDTs
if (userType is EnumUserType || userType is GlobalsUserType || userType is NamespaceUserType)
continue;
// For template user types, we want to remember all specializations
TemplateUserType templateUserType = userType as TemplateUserType;
if (templateUserType != null)
{
foreach (UserType specializedUserType in templateUserType.SpecializedTypes)
{
AddDerivedClassToBaseClasses(specializedUserType);
}
}
else
{
AddDerivedClassToBaseClasses(userType);
}
}
// Merge namespaces when possible
foreach (UserType userType in newTypes)
{
NamespaceUserType nameSpace = userType as NamespaceUserType;
if (nameSpace == null)
{
continue;
}
nameSpace.MergeIfPossible();
}
// Remove empty namespaces after merge
List<UserType> removedUserTypes = new List<UserType>();
foreach (UserType userType in newTypes)
{
NamespaceUserType nameSpace = userType as NamespaceUserType;
if (nameSpace == null)
{
continue;
}
if (nameSpace.InnerTypes.Count == 0)
{
removedUserTypes.Add(nameSpace);
}
}
return newTypes.Except(removedUserTypes);
}
示例2: ShouldReturnEquivalentBagToNumberArray
public void ShouldReturnEquivalentBagToNumberArray()
{
int[] numbers = new int[] { 1, 2, 3, 4, 3, 6, 4, 8, 17, 42, 6 };
ConcurrentBag<int> expected = new ConcurrentBag<int>(numbers);
ConcurrentBag<int> actual = new ConcurrentBag<int>();
UniqueRandomNumberGenerator g = new UniqueRandomNumberGenerator(numbers);
while (g.RemainingNumbersCount > 0)
{
int number = g.NewRandomNumber();
actual.Add(number);
}
CollectionAssert.IsEmpty(
actual.Except(expected),
"The bag of random numbers differs from the bag corresponding to the initial array.");
}
示例3: Initialize
public override void Initialize(AnalysisContext analysisContext)
{
analysisContext.EnableConcurrentExecution();
analysisContext.ConfigureGeneratedCodeAnalysis(GeneratedCodeAnalysisFlags.Analyze);
analysisContext.RegisterCompilationStartAction(startContext =>
{
var instantiatedTypes = new ConcurrentBag<INamedTypeSymbol>();
var internalTypes = new ConcurrentBag<INamedTypeSymbol>();
Compilation compilation = startContext.Compilation;
// If the assembly being built by this compilation exposes its internals to
// any other assembly, don't report any "uninstantiated internal class" errors.
// If we were to report an error for an internal type that is not instantiated
// by this assembly, and then it turned out that the friend assembly did
// instantiate the type, that would be a false positive. We've decided it's
// better to have false negatives (which would happen if the type were *not*
// instantiated by any friend assembly, but we didn't report the issue) than
// to have false positives.
INamedTypeSymbol internalsVisibleToAttributeSymbol = compilation.GetTypeByMetadataName("System.Runtime.CompilerServices.InternalsVisibleToAttribute");
if (AssemblyExposesInternals(compilation, internalsVisibleToAttributeSymbol))
{
return;
}
INamedTypeSymbol systemAttributeSymbol = compilation.GetTypeByMetadataName("System.Attribute");
INamedTypeSymbol iConfigurationSectionHandlerSymbol = compilation.GetTypeByMetadataName("System.Configuration.IConfigurationSectionHandler");
INamedTypeSymbol configurationSectionSymbol = compilation.GetTypeByMetadataName("System.Configuration.ConfigurationSection");
INamedTypeSymbol safeHandleSymbol = compilation.GetTypeByMetadataName("System.Runtime.InteropServices.SafeHandle");
INamedTypeSymbol traceListenerSymbol = compilation.GetTypeByMetadataName("System.Diagnostics.TraceListener");
INamedTypeSymbol mef1ExportAttributeSymbol = compilation.GetTypeByMetadataName("System.ComponentModel.Composition.ExportAttribute");
INamedTypeSymbol mef2ExportAttributeSymbol = compilation.GetTypeByMetadataName("System.Composition.ExportAttribute");
startContext.RegisterOperationAction(context =>
{
IObjectCreationExpression expr = (IObjectCreationExpression)context.Operation;
var namedType = expr.Type as INamedTypeSymbol;
if (namedType != null)
{
instantiatedTypes.Add(namedType);
}
}, OperationKind.ObjectCreationExpression);
startContext.RegisterSymbolAction(context =>
{
INamedTypeSymbol type = (INamedTypeSymbol)context.Symbol;
if (type.GetResultantVisibility() != SymbolVisibility.Public &&
!IsOkToBeUnused(type, compilation,
systemAttributeSymbol,
iConfigurationSectionHandlerSymbol,
configurationSectionSymbol,
safeHandleSymbol,
traceListenerSymbol,
mef1ExportAttributeSymbol,
mef2ExportAttributeSymbol))
{
internalTypes.Add(type);
}
}, SymbolKind.NamedType);
startContext.RegisterCompilationEndAction(context =>
{
IEnumerable<INamedTypeSymbol> uninstantiatedInternalTypes = internalTypes
.Except(instantiatedTypes)
.Where(type => !HasInstantiatedNestedType(type, instantiatedTypes));
foreach (INamedTypeSymbol type in uninstantiatedInternalTypes)
{
context.ReportDiagnostic(type.CreateDiagnostic(Rule, type.FormatMemberName()));
}
});
});
}