public void ToImmutableDictionary() { ImmutableSegmentedDictionary <int, int> .Builder builder = ImmutableSegmentedDictionary.CreateBuilder <int, int>(); builder.Add(0, 0); builder.Add(1, 1); builder.Add(2, 2); var dictionary = builder.ToImmutableSegmentedDictionary(); Assert.Equal(0, dictionary[0]); Assert.Equal(1, dictionary[1]); Assert.Equal(2, dictionary[2]); builder[1] = 5; Assert.Equal(5, builder[1]); Assert.Equal(1, dictionary[1]); builder.Clear(); Assert.True(builder.ToImmutableSegmentedDictionary().IsEmpty); Assert.False(dictionary.IsEmpty); ImmutableSegmentedDictionary <int, int> .Builder?nullBuilder = null; Assert.Throws <ArgumentNullException>( "builder", () => nullBuilder !.ToImmutableSegmentedDictionary() ); }
public void CreateBuilder() { var builder = ImmutableSegmentedDictionary.CreateBuilder <string, string>(); Assert.Same(EqualityComparer <string> .Default, builder.KeyComparer); builder = ImmutableSegmentedDictionary.CreateBuilder <string, string>(StringComparer.Ordinal); Assert.Same(StringComparer.Ordinal, builder.KeyComparer); }
public void DebuggerAttributesValid() { DebuggerAttributes.ValidateDebuggerDisplayReferences(ImmutableSegmentedDictionary.CreateBuilder <string, int>()); ImmutableSegmentedDictionary <int, string> .Builder builder = ImmutableSegmentedDictionary.CreateBuilder <int, string>(); builder.Add(1, "One"); builder.Add(2, "Two"); DebuggerAttributeInfo info = DebuggerAttributes.ValidateDebuggerTypeProxyProperties(builder); PropertyInfo itemProperty = info.Properties.Single(pr => pr.GetCustomAttribute <DebuggerBrowsableAttribute>() !.State == DebuggerBrowsableState.RootHidden); KeyValuePair <int, string>[]? items = itemProperty.GetValue(info.Instance) as KeyValuePair <int, string>[]; Assert.Equal(builder, items); }
internal SourceNamespaceSymbol( SourceModuleSymbol module, Symbol container, MergedNamespaceDeclaration mergedDeclaration, BindingDiagnosticBag diagnostics) { Debug.Assert(mergedDeclaration != null); _module = module; _container = container; _mergedDeclaration = mergedDeclaration; var builder = ImmutableSegmentedDictionary.CreateBuilder <SingleNamespaceDeclaration, AliasesAndUsings>(ReferenceEqualityComparer.Instance); #if DEBUG var builderForAsserts = ImmutableSegmentedDictionary.CreateBuilder <SingleNamespaceDeclaration, AliasesAndUsings>(ReferenceEqualityComparer.Instance); #endif foreach (var singleDeclaration in mergedDeclaration.Declarations) { if (singleDeclaration.HasExternAliases || singleDeclaration.HasGlobalUsings || singleDeclaration.HasUsings) { builder.Add(singleDeclaration, new AliasesAndUsings()); } #if DEBUG else { builderForAsserts.Add(singleDeclaration, new AliasesAndUsings()); } #endif diagnostics.AddRange(singleDeclaration.Diagnostics); } _aliasesAndUsings = builder.ToImmutable(); #if DEBUG _aliasesAndUsingsForAsserts = builderForAsserts.ToImmutable(); #endif }