private static HeapState ConstructBasicState()
            {
                var states = ImmutableSortedDictionary.CreateRange(new[]
                {
                    new KeyValuePair <int, VariableState>(VariableState.NullId, VariableState.Null)
                });
                var varStateMap = ImmutableDictionary.CreateRange(new[]
                {
                    new KeyValuePair <VersionedVariable, int>(VersionedVariable.Null, VariableState.NullId)
                });
                var stateVarsMap = ImmutableDictionary.CreateRange(new[]
                {
                    new KeyValuePair <int, ImmutableList <VersionedVariable> >(
                        VariableState.NullId,
                        ImmutableList.Create(VersionedVariable.Null))
                });

                return(new HeapState(
                           states,
                           varStateMap,
                           stateVarsMap,
                           ImmutableDictionary <IFieldDefinition, ArrayHandle <IntHandle, Handle> > .Empty,
                           1,
                           1));
            }
Пример #2
0
        public void PruneElements(IEnumerable <KeyValuePair <UInt256, IEnumerable <int> > > blockTxIndices)
        {
            foreach (var keyPair in blockTxIndices)
            {
                var blockHash = keyPair.Key;
                var txIndices = keyPair.Value;

                ImmutableSortedDictionary <int, BlockTxNode> blockTxNodes;
                if (this.allBlockTxNodes.TryGetValue(blockHash, out blockTxNodes))
                {
                    var pruningCursor = new MemoryMerkleTreePruningCursor <BlockTxNode>(blockTxNodes.Values);
                    foreach (var index in txIndices)
                    {
                        MerkleTree.PruneNode(pruningCursor, index);
                    }

                    var prunedBlockTxes =
                        ImmutableSortedDictionary.CreateRange <int, BlockTxNode>(
                            pruningCursor.ReadNodes().Select(blockTx =>
                                                             new KeyValuePair <int, BlockTxNode>(blockTx.Index, blockTx)));

                    this.allBlockTxNodes[blockHash] = prunedBlockTxes;
                }
            }
        }
Пример #3
0
 public bool TryAddBlockTransactions(UInt256 blockHash, IEnumerable <Transaction> blockTxes)
 {
     return(this.allBlockTxes.TryAdd(blockHash,
                                     ImmutableSortedDictionary.CreateRange <int, BlockTx>(
                                         blockTxes.Select((tx, txIndex) =>
                                                          new KeyValuePair <int, BlockTx>(txIndex, new BlockTx(txIndex, 0, tx.Hash, false, tx))))));
 }
Пример #4
0
        public void Setup()
        {
            List <string> list = new List <string> {
            };
            Dictionary <string, string> dict = new Dictionary <string, string> {
            };

            for (int i = 0; i < ElementCount; i++)
            {
                list.Add($"hello{i}");
                dict.Add($"hello{i}", $"world{i}");
            }

            _iimmutablelist            = ImmutableList.CreateRange(list);
            _iimmutablestack           = ImmutableStack.CreateRange(list);
            _iimmutablequeue           = ImmutableQueue.CreateRange(list);
            _iimmutableset             = ImmutableHashSet.CreateRange(list);
            _iimmutabledictionary      = ImmutableDictionary.CreateRange(dict);
            _immutablearray            = ImmutableArray.CreateRange(list);
            _immutablelist             = ImmutableList.CreateRange(list);
            _immutablestack            = ImmutableStack.CreateRange(list);
            _immutablequeue            = ImmutableQueue.CreateRange(list);
            _immutablesortedset        = ImmutableSortedSet.CreateRange(list);
            _immutablehashset          = ImmutableHashSet.CreateRange(list);
            _immutabledictionary       = ImmutableDictionary.CreateRange(dict);
            _immutablesorteddictionary = ImmutableSortedDictionary.CreateRange(dict);

            _jsonListString = System.Text.Json.JsonSerializer.Serialize(list);
            _jsonDictString = System.Text.Json.JsonSerializer.Serialize(dict);
        }
        public void WriteImmutableSortedDictionaryOfInt32()
        {
            ImmutableSortedDictionary <int, int> value = ImmutableSortedDictionary.CreateRange(new SortedDictionary <int, int>
            {
                { 1, 1 },
                { 2, 2 },
                { 3, 3 }
            });
            const string expectedHexBuffer = "A3010102020303";

            Helper.TestWrite(value, expectedHexBuffer);
        }
        public void ReadImmutableSortedDictionaryOfInt32()
        {
            ImmutableSortedDictionary <int, int> expectedValue = ImmutableSortedDictionary.CreateRange(new SortedDictionary <int, int>
            {
                { 1, 1 },
                { 2, 2 },
                { 3, 3 }
            });
            const string hexBuffer = "A3010102020303";

            Helper.TestRead(hexBuffer, expectedValue);
        }
Пример #7
0
        public ProjectState(ProjectInfo projectInfo, HostLanguageServices languageServices, SolutionServices solutionServices)
        {
            Contract.ThrowIfNull(projectInfo);
            Contract.ThrowIfNull(languageServices);
            Contract.ThrowIfNull(solutionServices);

            _languageServices = languageServices;
            _solutionServices = solutionServices;

            var projectInfoFixed = FixProjectInfo(projectInfo);

            // We need to compute our AnalyerConfigDocumentStates first, since we use those to produce our DocumentStates
            _analyzerConfigDocumentStates = ImmutableSortedDictionary.CreateRange(DocumentIdComparer.Instance,
                                                                                  projectInfoFixed.AnalyzerConfigDocuments.Select(d =>
                                                                                                                                  KeyValuePairUtil.Create(d.Id, new AnalyzerConfigDocumentState(d, solutionServices))));
            _lazyAnalyzerConfigSet = ComputeAnalyzerConfigSetValueSource(_analyzerConfigDocumentStates.Values);

            // Add analyzer config information to the compilation options
            if (projectInfoFixed.CompilationOptions != null)
            {
                projectInfoFixed = projectInfoFixed.WithCompilationOptions(
                    projectInfoFixed.CompilationOptions.WithSyntaxTreeOptionsProvider(
                        new WorkspaceSyntaxTreeOptionsProvider(_lazyAnalyzerConfigSet)));
            }

            _documentIds           = projectInfoFixed.Documents.Select(d => d.Id).ToImmutableList();
            _additionalDocumentIds = projectInfoFixed.AdditionalDocuments.Select(d => d.Id).ToImmutableList();

            var parseOptions = projectInfoFixed.ParseOptions;
            var docStates    = ImmutableSortedDictionary.CreateRange(DocumentIdComparer.Instance,
                                                                     projectInfoFixed.Documents.Select(d =>
                                                                                                       new KeyValuePair <DocumentId, DocumentState>(d.Id,
                                                                                                                                                    CreateDocument(d, parseOptions))));

            _documentStates = docStates;

            var additionalDocStates = ImmutableSortedDictionary.CreateRange(DocumentIdComparer.Instance,
                                                                            projectInfoFixed.AdditionalDocuments.Select(d =>
                                                                                                                        new KeyValuePair <DocumentId, TextDocumentState>(d.Id, new TextDocumentState(d, solutionServices))));

            _additionalDocumentStates  = additionalDocStates;
            _lazyLatestDocumentVersion = new AsyncLazy <VersionStamp>(c => ComputeLatestDocumentVersionAsync(docStates, additionalDocStates, c), cacheResult: true);
            _lazyLatestDocumentTopLevelChangeVersion = new AsyncLazy <VersionStamp>(c => ComputeLatestDocumentTopLevelChangeVersionAsync(docStates, additionalDocStates, c), cacheResult: true);

            // ownership of information on document has moved to project state. clear out documentInfo the state is
            // holding on. otherwise, these information will be held onto unnecessarily by projectInfo even after
            // the info has changed by DocumentState.
            // we hold onto the info so that we don't need to duplicate all information info already has in the state
            _projectInfo = ClearAllDocumentsFromProjectInfo(projectInfoFixed);

            _lazyChecksums = new AsyncLazy <ProjectStateChecksums>(ComputeChecksumsAsync, cacheResult: true);
        }
 /// <summary>
 /// Initializes a new instance of <see cref="OrderBook"/> with details.
 /// </summary>
 /// <param name="source">The name of exchange.</param>
 /// <param name="asset">The asset pair.</param>
 /// <param name="timestamp">The creation time of order book. </param>
 /// <param name="asks">The levels of sell orders in order book.</param>
 /// <param name="bids">The levels of buy orders in order book.</param>
 private OrderBook(
     string source,
     string asset,
     DateTime timestamp,
     IEnumerable <KeyValuePair <decimal, decimal> > asks,
     IEnumerable <KeyValuePair <decimal, decimal> > bids)
 {
     Source    = source;
     Asset     = asset;
     Timestamp = timestamp;
     AskLevels = ImmutableSortedDictionary.CreateRange(asks);
     BidLevels = ImmutableSortedDictionary.CreateRange(DescComparer, bids);
 }
        private IDictionary <int, string> changedByPos()
        {
            if (this.changedByPosMap == null)
            {
                SortedDictionary <int, string> res = new SortedDictionary <int, string>();
                foreach (int pos in changedFields)
                {
                    res[pos] = updates[pos - 1];
                }
                changedByPosMap = ImmutableSortedDictionary.CreateRange(res);
            }

            return(changedByPosMap);
        }
        private void AddAmbiguous(InternalEntityTypeBuilder entityTypeBuilder, IEnumerable <PropertyInfo> navigationProperties, Type targetType)
        {
            var newAmbiguousNavigations = ImmutableSortedDictionary.CreateRange(PropertyInfoNameComparer.Instance,
                                                                                navigationProperties.Select(n => new KeyValuePair <PropertyInfo, Type>(n, targetType)));

            var currentAmbiguousNavigations = GetAmbigousNavigations(entityTypeBuilder.Metadata);

            if (currentAmbiguousNavigations != null)
            {
                newAmbiguousNavigations = currentAmbiguousNavigations.AddRange(newAmbiguousNavigations);
            }

            SetAmbigousNavigations(entityTypeBuilder, newAmbiguousNavigations);
        }
        private IDictionary <string, string> changedByName()
        {
            if (this.changedByNameMap == null)
            {
                SortedDictionary <string, string> res = new SortedDictionary <string, string>(new OrderedFieldNamesComparator(this));
                foreach (int pos in changedFields)
                {
                    res[fields.getName(pos)] = updates[pos - 1];
                }

                changedByNameMap = ImmutableSortedDictionary.CreateRange(res);
            }

            return(changedByNameMap);
        }
Пример #12
0
        public void SerializeSortedDictionary()
        {
            ImmutableSortedDictionary<int, string> l = ImmutableSortedDictionary.CreateRange(new SortedDictionary<int, string>
            {
                { 1, "One" },
                { 2, "II" },
                { 3, "3" }
            });

            string json = JsonConvert.SerializeObject(l, Formatting.Indented);
            StringAssert.AreEqual(@"{
  ""1"": ""One"",
  ""2"": ""II"",
  ""3"": ""3""
}", json);
        }
        private IDictionary <string, string> allByName()
        {
            if (this.allByNameMap == null)
            {
                SortedDictionary <string, string> res = new SortedDictionary <string, string>(new OrderedFieldNamesComparator(this));
                IEnumerator <string> iterate          = updates.GetEnumerator();
                int pos = 1;
                while (iterate.MoveNext())
                {
                    res[fields.getName(pos)] = iterate.Current;
                    pos++;
                }

                allByNameMap = ImmutableSortedDictionary.CreateRange(res);
            }
            return(allByNameMap);
        }
        public async Task Test_Immutable_Sorted_Dictionary_Simple_Number(int len)
        {
            Dictionary<long, long> dic = new Dictionary<long, long>();
            for (long i = 0; i < len; i++)
            {
                dic.Add(i, i);
            }

            var a = ImmutableSortedDictionary.CreateRange(dic);


            await Test(a,
                CheckIEnumerableOfIIDictionary(a,
                (a, b) => Assert.Equal(a, b),
                (a, b) => Assert.Equal(a, b)));

        }
        public void ReadImmutableSortedDictionaryOfInt32()
        {
            ImmutableSortedDictionary <int, int> expected = ImmutableSortedDictionary.CreateRange(new SortedDictionary <int, int>
            {
                { 1, 1 },
                { 2, 2 },
                { 3, 3 }
            });
            const string json = @"{""1"":1,""2"":2,""3"":3}";

            JsonSerializerOptions options = new JsonSerializerOptions();

            options.SetupExtensions();
            ImmutableSortedDictionary <int, int> actual = JsonSerializer.Deserialize <ImmutableSortedDictionary <int, int> >(json, options);

            Assert.Equal(expected, actual);
        }
        private IDictionary <int, string> allByPos()
        {
            if (this.allByPosMap == null)
            {
                SortedDictionary <int, string> res     = new SortedDictionary <int, string>();
                IEnumerator <string>           iterate = updates.GetEnumerator();
                int pos = 1;
                while (iterate.MoveNext())
                {
                    res[pos] = iterate.Current;
                    pos++;
                }

                allByPosMap = ImmutableSortedDictionary.CreateRange(res);
            }
            return(allByPosMap);
        }
Пример #17
0
        public void SerializeSortedDictionary()
        {
            ImmutableSortedDictionary <int, string> data = ImmutableSortedDictionary.CreateRange(new SortedDictionary <int, string>
            {
                { 1, "One" },
                { 2, "II" },
                { 3, "3" }
            });

            string json = JsonSerializer.Serialize(data, s_indentedOption);

            Assert.Equal(@"{
  ""1"": ""One"",
  ""2"": ""II"",
  ""3"": ""3""
}", json);
        }
        public void WriteImmutableSortedDictionaryOfInt32()
        {
            ImmutableSortedDictionary <int, int> value = ImmutableSortedDictionary.CreateRange(new SortedDictionary <int, int>
            {
                { 1, 1 },
                { 2, 2 },
                { 3, 3 }
            });
            const string expected = @"{""1"":1,""2"":2,""3"":3}";

            JsonSerializerOptions options = new JsonSerializerOptions();

            options.SetupExtensions();
            string actual = JsonSerializer.Serialize(value, value.GetType(), options);

            Assert.Equal(expected, actual);
        }
        public override ImmutableSortedDictionary <decimal, decimal> ReadJson(
            JsonReader reader,
            Type objectType,
            ImmutableSortedDictionary <decimal, decimal> existingValue,
            bool hasExistingValue,
            JsonSerializer serializer)
        {
            if (!hasExistingValue)
            {
                throw new JsonSerializationException("Expected non empty ImmutableSortedDictionary instance");
            }

            var range = ReadJsonObject(reader).GroupBy(x => x.Key).Select(grouping => KeyValuePair.Create(
                                                                              grouping.Key,
                                                                              grouping.Sum(t => t.Value)));

            return(ImmutableSortedDictionary.CreateRange(
                       existingValue.KeyComparer,
                       range));
        }
 /// <summary>
 /// Initializes a new instance of <see cref="OrderBook"/> with details.
 /// </summary>
 /// <param name="source">The name of exchange.</param>
 /// <param name="asset">The asset pair.</param>
 /// <param name="timestamp">The creation time of order book. </param>
 /// <param name="asks">The levels of sell orders in order book.</param>
 /// <param name="bids">The levels of buy orders in order book.</param>
 public OrderBook(
     string source,
     string asset,
     DateTime timestamp,
     IEnumerable <OrderBookItem> asks,
     IEnumerable <OrderBookItem> bids)
 {
     Source    = source;
     Asset     = asset;
     Timestamp = timestamp;
     AskLevels = ImmutableSortedDictionary.CreateRange(
         asks.Where(x => x.Price != 0M)
         .GroupBy(x => x.Price)
         .ToDictionary(x => x.Key, x => x.Sum(i => i.Volume)));
     BidLevels = ImmutableSortedDictionary.CreateRange(
         DescComparer,
         bids.Where(x => x.Price != 0M)
         .GroupBy(x => x.Price)
         .ToDictionary(x => x.Key, x => x.Sum(i => i.Volume)));
 }
Пример #21
0
        public DataModel(string sourceFilePath, DataModelMetadata metaData, IEnumerable <DataModelType> types)
        {
            this.SourceFilePath = sourceFilePath;
            this.MetaData       = metaData;

            _g4Lookup = ImmutableSortedDictionary.CreateRange(
                StringComparer.Ordinal, types.Select(type => Pair.Make(type.G4DeclaredName, type)));
            ImmutableSortedDictionary <string, DataModelType> .Builder csTypes = ImmutableSortedDictionary.CreateBuilder <string, DataModelType>(StringComparer.Ordinal);
            foreach (DataModelType type in _g4Lookup.Values)
            {
                string key = type.CSharpName;
                if (csTypes.ContainsKey(key))
                {
                    csTypes[key] = null;
                }
                else
                {
                    csTypes.Add(key, type);
                }
            }
        }
Пример #22
0
        public void Create()
        {
            IEnumerable <KeyValuePair <string, string> > pairs = new Dictionary <string, string> {
                { "a", "b" }
            };
            var keyComparer   = StringComparer.OrdinalIgnoreCase;
            var valueComparer = StringComparer.CurrentCulture;

            var dictionary = ImmutableSortedDictionary.Create <string, string>();

            Assert.Equal(0, dictionary.Count);
            Assert.Same(Comparer <string> .Default, dictionary.KeyComparer);
            Assert.Same(EqualityComparer <string> .Default, dictionary.ValueComparer);

            dictionary = ImmutableSortedDictionary.Create <string, string>(keyComparer);
            Assert.Equal(0, dictionary.Count);
            Assert.Same(keyComparer, dictionary.KeyComparer);
            Assert.Same(EqualityComparer <string> .Default, dictionary.ValueComparer);

            dictionary = ImmutableSortedDictionary.Create(keyComparer, valueComparer);
            Assert.Equal(0, dictionary.Count);
            Assert.Same(keyComparer, dictionary.KeyComparer);
            Assert.Same(valueComparer, dictionary.ValueComparer);

            dictionary = ImmutableSortedDictionary.CreateRange(pairs);
            Assert.Equal(1, dictionary.Count);
            Assert.Same(Comparer <string> .Default, dictionary.KeyComparer);
            Assert.Same(EqualityComparer <string> .Default, dictionary.ValueComparer);

            dictionary = ImmutableSortedDictionary.CreateRange(keyComparer, pairs);
            Assert.Equal(1, dictionary.Count);
            Assert.Same(keyComparer, dictionary.KeyComparer);
            Assert.Same(EqualityComparer <string> .Default, dictionary.ValueComparer);

            dictionary = ImmutableSortedDictionary.CreateRange(keyComparer, valueComparer, pairs);
            Assert.Equal(1, dictionary.Count);
            Assert.Same(keyComparer, dictionary.KeyComparer);
            Assert.Same(valueComparer, dictionary.ValueComparer);
        }
Пример #23
0
        public ProjectState(ProjectInfo projectInfo, HostLanguageServices languageServices, SolutionServices solutionServices)
        {
            Contract.ThrowIfNull(projectInfo);
            Contract.ThrowIfNull(languageServices);
            Contract.ThrowIfNull(solutionServices);

            _languageServices = languageServices;
            _solutionServices = solutionServices;

            var projectInfoFixed = FixProjectInfo(projectInfo);

            _documentIds           = projectInfoFixed.Documents.Select(d => d.Id).ToImmutableList();
            _additionalDocumentIds = projectInfoFixed.AdditionalDocuments.Select(d => d.Id).ToImmutableList();

            var parseOptions = projectInfoFixed.ParseOptions;
            var docStates    = ImmutableSortedDictionary.CreateRange(DocumentIdComparer.Instance,
                                                                     projectInfoFixed.Documents.Select(d =>
                                                                                                       new KeyValuePair <DocumentId, DocumentState>(d.Id,
                                                                                                                                                    CreateDocument(d, parseOptions, languageServices, solutionServices))));

            _documentStates = docStates;

            var additionalDocStates = ImmutableSortedDictionary.CreateRange(DocumentIdComparer.Instance,
                                                                            projectInfoFixed.AdditionalDocuments.Select(d =>
                                                                                                                        new KeyValuePair <DocumentId, TextDocumentState>(d.Id, TextDocumentState.Create(d, solutionServices))));

            _additionalDocumentStates = additionalDocStates;

            _lazyLatestDocumentVersion = new AsyncLazy <VersionStamp>(c => ComputeLatestDocumentVersionAsync(docStates, additionalDocStates, c), cacheResult: true);
            _lazyLatestDocumentTopLevelChangeVersion = new AsyncLazy <VersionStamp>(c => ComputeLatestDocumentTopLevelChangeVersionAsync(docStates, additionalDocStates, c), cacheResult: true);

            // ownership of information on document has moved to project state. clear out documentInfo the state is
            // holding on. otherwise, these information will be held onto unnecesarily by projectInfo even after
            // the info has changed by DocumentState.
            // we hold onto the info so that we don't need to duplicate all information info already has in the state
            _projectInfo = ClearAllDocumentsFromProjectInfo(projectInfoFixed);

            _lazyChecksums = new AsyncLazy <ProjectStateChecksums>(ComputeChecksumsAsync, cacheResult: true);
        }
        public override ImmutableSortedDictionary <TKey, TValue> ConvertFromSurrogate(ref ImmutableSortedDictionarySurrogate <TKey, TValue> surrogate)
        {
            if (surrogate.Values is null)
            {
                return(null);
            }
            else
            {
                var result = ImmutableSortedDictionary.CreateRange(surrogate.Values);

                if (surrogate.KeyComparer is object && surrogate.ValueComparer is object)
                {
                    result = result.WithComparers(surrogate.KeyComparer, surrogate.ValueComparer);
                }
                else if (surrogate.KeyComparer is object)
                {
                    result = result.WithComparers(surrogate.KeyComparer);
                }

                return(result);
            }
        }
Пример #25
0
        public DefaultConfigurationManager(ConfigurationManagerConfig config)
        {
            if (config == null)
            {
                throw new ArgumentNullException("config is null");
            }

            _config = config;

            _sortedSources = ImmutableSortedDictionary.CreateRange(PriorityComparator, _config.Sources);
            _sortedSources.Values.ToList().ForEach(s => s.OnChange += OnSourceChange);

            _properties     = new ConcurrentDictionary <object, IProperty>();
            _propertiesLock = new object();

            _genericGetPropertyValueMethod = GetType().GetMethods().Where(methodInfo =>
                                                                          methodInfo.Name == "GetPropertyValue" &&
                                                                          methodInfo.IsGenericMethod && methodInfo.GetGenericArguments().Length == 2 &&
                                                                          methodInfo.GetParameters().Count() == 1
                                                                          ).Single();

            Logger.Info("Configuration Manager created: {0}", ToString());
        }
        public override void Initialize()
        {
            base.Initialize();

            MyInt16Array        = new short[] { 1 };
            MyInt32Array        = new int[] { 2 };
            MyInt64Array        = new long[] { 3 };
            MyUInt16Array       = new ushort[] { 4 };
            MyUInt32Array       = new uint[] { 5 };
            MyUInt64Array       = new ulong[] { 6 };
            MyByteArray         = new byte[] { 7 };
            MySByteArray        = new sbyte[] { 8 };
            MyCharArray         = new char[] { 'a' };
            MyStringArray       = new string[] { "Hello" };
            MyBooleanTrueArray  = new bool[] { true };
            MyBooleanFalseArray = new bool[] { false };
            MySingleArray       = new float[] { 1.1f };
            MyDoubleArray       = new double[] { 2.2d };
            MyDecimalArray      = new decimal[] { 3.3m };
            MyDateTimeArray     = new DateTime[] { new DateTime(2019, 1, 30, 12, 1, 2, DateTimeKind.Utc) };
            MyEnumArray         = new SampleEnum[] { SampleEnum.Two };

            MyStringList = new List <string>()
            {
                "Hello"
            };
            MyStringIEnumerableT         = new string[] { "Hello" };
            MyStringIListT               = new string[] { "Hello" };
            MyStringICollectionT         = new string[] { "Hello" };
            MyStringIReadOnlyCollectionT = new string[] { "Hello" };
            MyStringIReadOnlyListT       = new string[] { "Hello" };

            MyStringToStringDict = new Dictionary <string, string> {
                { "key", "value" }
            };
            MyStringToStringIDict = new Dictionary <string, string> {
                { "key", "value" }
            };
            MyStringToStringIReadOnlyDict = new Dictionary <string, string> {
                { "key", "value" }
            };

            MyStringToStringImmutableDict       = ImmutableDictionary.CreateRange((Dictionary <string, string>)MyStringToStringDict);
            MyStringToStringIImmutableDict      = ImmutableDictionary.CreateRange((Dictionary <string, string>)MyStringToStringDict);
            MyStringToStringImmutableSortedDict = ImmutableSortedDictionary.CreateRange((Dictionary <string, string>)MyStringToStringDict);

            MyStringStackT = new Stack <string>(new List <string>()
            {
                "Hello", "World"
            });
            MyStringQueueT = new Queue <string>(new List <string>()
            {
                "Hello", "World"
            });
            MyStringHashSetT = new HashSet <string>(new List <string>()
            {
                "Hello"
            });
            MyStringLinkedListT = new LinkedList <string>(new List <string>()
            {
                "Hello"
            });
            MyStringSortedSetT = new SortedSet <string>(new List <string>()
            {
                "Hello"
            });

            MyStringIImmutableListT = ImmutableList.CreateRange(new List <string> {
                "Hello"
            });
            MyStringIImmutableStackT = ImmutableStack.CreateRange(new List <string> {
                "Hello"
            });
            MyStringIImmutableQueueT = ImmutableQueue.CreateRange(new List <string> {
                "Hello"
            });
            MyStringIImmutableSetT = ImmutableHashSet.CreateRange(new List <string> {
                "Hello"
            });
            MyStringImmutableHashSetT = ImmutableHashSet.CreateRange(new List <string> {
                "Hello"
            });
            MyStringImmutableListT = ImmutableList.CreateRange(new List <string> {
                "Hello"
            });
            MyStringImmutableStackT = ImmutableStack.CreateRange(new List <string> {
                "Hello"
            });
            MyStringImmutablQueueT = ImmutableQueue.CreateRange(new List <string> {
                "Hello"
            });
            MyStringImmutableSortedSetT = ImmutableSortedSet.CreateRange(new List <string> {
                "Hello"
            });
        }
Пример #27
0
        public void Initialize()
        {
            MyInt16          = 1;
            MyInt32          = 2;
            MyInt64          = 3;
            MyUInt16         = 4;
            MyUInt32         = 5;
            MyUInt64         = 6;
            MyByte           = 7;
            MySByte          = 8;
            MyChar           = 'a';
            MyString         = "Hello";
            MyBooleanTrue    = true;
            MyBooleanFalse   = false;
            MySingle         = 1.1f;
            MyDouble         = 2.2d;
            MyDecimal        = 3.3m;
            MyDateTime       = new DateTime(2019, 1, 30, 12, 1, 2, DateTimeKind.Utc);
            MyDateTimeOffset = new DateTimeOffset(2019, 1, 30, 12, 1, 2, new TimeSpan(1, 0, 0));
            MyEnum           = SampleEnum.Two;

            MyInt16Array          = new short[] { 1 };
            MyInt32Array          = new int[] { 2 };
            MyInt64Array          = new long[] { 3 };
            MyUInt16Array         = new ushort[] { 4 };
            MyUInt32Array         = new uint[] { 5 };
            MyUInt64Array         = new ulong[] { 6 };
            MyByteArray           = new byte[] { 7 };
            MySByteArray          = new sbyte[] { 8 };
            MyCharArray           = new char[] { 'a' };
            MyStringArray         = new string[] { "Hello" };
            MyBooleanTrueArray    = new bool[] { true };
            MyBooleanFalseArray   = new bool[] { false };
            MySingleArray         = new float[] { 1.1f };
            MyDoubleArray         = new double[] { 2.2d };
            MyDecimalArray        = new decimal[] { 3.3m };
            MyDateTimeArray       = new DateTime[] { new DateTime(2019, 1, 30, 12, 1, 2, DateTimeKind.Utc) };
            MyDateTimeOffsetArray = new DateTimeOffset[] { new DateTimeOffset(2019, 1, 30, 12, 1, 2, new TimeSpan(1, 0, 0)) };
            MyEnumArray           = new SampleEnum[] { SampleEnum.Two };

            MyInt16TwoDimensionArray    = new int[2][];
            MyInt16TwoDimensionArray[0] = new int[] { 10, 11 };
            MyInt16TwoDimensionArray[1] = new int[] { 20, 21 };

            MyInt16TwoDimensionList = new List <List <int> >();
            MyInt16TwoDimensionList.Add(new List <int> {
                10, 11
            });
            MyInt16TwoDimensionList.Add(new List <int> {
                20, 21
            });

            MyInt16ThreeDimensionArray       = new int[2][][];
            MyInt16ThreeDimensionArray[0]    = new int[2][];
            MyInt16ThreeDimensionArray[1]    = new int[2][];
            MyInt16ThreeDimensionArray[0][0] = new int[] { 11, 12 };
            MyInt16ThreeDimensionArray[0][1] = new int[] { 13, 14 };
            MyInt16ThreeDimensionArray[1][0] = new int[] { 21, 22 };
            MyInt16ThreeDimensionArray[1][1] = new int[] { 23, 24 };

            MyInt16ThreeDimensionList = new List <List <List <int> > >();
            var list1 = new List <List <int> >();

            MyInt16ThreeDimensionList.Add(list1);
            list1.Add(new List <int> {
                11, 12
            });
            list1.Add(new List <int> {
                13, 14
            });
            var list2 = new List <List <int> >();

            MyInt16ThreeDimensionList.Add(list2);
            list2.Add(new List <int> {
                21, 22
            });
            list2.Add(new List <int> {
                23, 24
            });

            MyStringList = new List <string>()
            {
                "Hello"
            };

            MyStringIEnumerable = new string[] { "Hello" };
            MyStringIList       = new string[] { "Hello" };
            MyStringICollection = new string[] { "Hello" };

            MyStringIEnumerableT         = new string[] { "Hello" };
            MyStringIListT               = new string[] { "Hello" };
            MyStringICollectionT         = new string[] { "Hello" };
            MyStringIReadOnlyCollectionT = new string[] { "Hello" };
            MyStringIReadOnlyListT       = new string[] { "Hello" };
            MyStringISetT = new HashSet <string> {
                "Hello"
            };

            MyStringToStringKeyValuePair = new KeyValuePair <string, string>("myKey", "myValue");
            MyStringToStringIDict        = new Dictionary <string, string> {
                { "key", "value" }
            };

            MyStringToStringGenericDict = new Dictionary <string, string> {
                { "key", "value" }
            };
            MyStringToStringGenericIDict = new Dictionary <string, string> {
                { "key", "value" }
            };
            MyStringToStringGenericIReadOnlyDict = new Dictionary <string, string> {
                { "key", "value" }
            };

            MyStringToStringImmutableDict       = ImmutableDictionary.CreateRange(MyStringToStringGenericDict);
            MyStringToStringIImmutableDict      = ImmutableDictionary.CreateRange(MyStringToStringGenericDict);
            MyStringToStringImmutableSortedDict = ImmutableSortedDictionary.CreateRange(MyStringToStringGenericDict);

            MyStringStackT = new Stack <string>(new List <string>()
            {
                "Hello", "World"
            });
            MyStringQueueT = new Queue <string>(new List <string>()
            {
                "Hello", "World"
            });
            MyStringHashSetT = new HashSet <string>(new List <string>()
            {
                "Hello"
            });
            MyStringLinkedListT = new LinkedList <string>(new List <string>()
            {
                "Hello"
            });
            MyStringSortedSetT = new SortedSet <string>(new List <string>()
            {
                "Hello"
            });

            MyStringIImmutableListT = ImmutableList.CreateRange(new List <string> {
                "Hello"
            });
            MyStringIImmutableStackT = ImmutableStack.CreateRange(new List <string> {
                "Hello"
            });
            MyStringIImmutableQueueT = ImmutableQueue.CreateRange(new List <string> {
                "Hello"
            });
            MyStringIImmutableSetT = ImmutableHashSet.CreateRange(new List <string> {
                "Hello"
            });
            MyStringImmutableHashSetT = ImmutableHashSet.CreateRange(new List <string> {
                "Hello"
            });
            MyStringImmutableListT = ImmutableList.CreateRange(new List <string> {
                "Hello"
            });
            MyStringImmutableStackT = ImmutableStack.CreateRange(new List <string> {
                "Hello"
            });
            MyStringImmutablQueueT = ImmutableQueue.CreateRange(new List <string> {
                "Hello"
            });
            MyStringImmutableSortedSetT = ImmutableSortedSet.CreateRange(new List <string> {
                "Hello"
            });

            MyListOfNullString = new List <string> {
                null
            };
        }
 /// <summary>
 /// The PointData
 /// </summary>
 /// <returns></returns>
 public PointData ToPointData()
 {
     return(new PointData(_measurementName, _precision, _time,
                          ImmutableSortedDictionary.CreateRange(_tags),
                          ImmutableSortedDictionary.CreateRange(_fields)));
 }
Пример #29
0
        internal static T Generate <T>()
        {
            if (typeof(T) == typeof(LoginViewModel))
            {
                return((T)(object)CreateLoginViewModel());
            }
            if (typeof(T) == typeof(Location))
            {
                return((T)(object)CreateLocation());
            }
            if (typeof(T) == typeof(IndexViewModel))
            {
                return((T)(object)CreateIndexViewModel());
            }
            if (typeof(T) == typeof(MyEventsListerViewModel))
            {
                return((T)(object)CreateMyEventsListerViewModel());
            }
            if (typeof(T) == typeof(BinaryData))
            {
                return((T)(object)CreateBinaryData(1024));
            }
            if (typeof(T) == typeof(CollectionsOfPrimitives))
            {
                return((T)(object)CreateCollectionsOfPrimitives(1024)); // 1024 values was copied from CoreFX benchmarks
            }
            if (typeof(T) == typeof(XmlElement))
            {
                return((T)(object)CreateXmlElement());
            }
            if (typeof(T) == typeof(SimpleStructWithProperties))
            {
                return (T)(object)new SimpleStructWithProperties {
                           Num = 1, Text = "Foo"
                }
            }
            ;
            if (typeof(T) == typeof(SimpleListOfInt))
            {
                return (T)(object)new SimpleListOfInt {
                           10, 20, 30
                }
            }
            ;
            if (typeof(T) == typeof(ClassImplementingIXmlSerialiable))
            {
                return (T)(object)new ClassImplementingIXmlSerialiable {
                           StringValue = "Hello world"
                }
            }
            ;
            if (typeof(T) == typeof(Dictionary <string, string>))
            {
                return((T)(object)ValuesGenerator.ArrayOfUniqueValues <string>(100).ToDictionary(value => value));
            }
            if (typeof(T) == typeof(ImmutableDictionary <string, string>))
            {
                return((T)(object)ImmutableDictionary.CreateRange(ValuesGenerator.ArrayOfUniqueValues <string>(100).ToDictionary(value => value)));
            }
            if (typeof(T) == typeof(ImmutableSortedDictionary <string, string>))
            {
                return((T)(object)ImmutableSortedDictionary.CreateRange(ValuesGenerator.ArrayOfUniqueValues <string>(100).ToDictionary(value => value)));
            }
            if (typeof(T) == typeof(HashSet <string>))
            {
                return((T)(object)new HashSet <string>(ValuesGenerator.ArrayOfUniqueValues <string>(100)));
            }
            if (typeof(T) == typeof(ArrayList))
            {
                return((T)(object)new ArrayList(ValuesGenerator.ArrayOfUniqueValues <string>(100)));
            }
            if (typeof(T) == typeof(Hashtable))
            {
                return((T)(object)new Hashtable(ValuesGenerator.ArrayOfUniqueValues <string>(100).ToDictionary(value => value)));
            }
            if (typeof(T) == typeof(LargeStructWithProperties))
            {
                return((T)(object)CreateLargeStructWithProperties());
            }
            if (typeof(T) == typeof(DateTimeOffset?))
            {
                return((T)(object)new DateTimeOffset(2021, 08, 13, 11, 11, 05, TimeSpan.Zero));
            }
            if (typeof(T) == typeof(int))
            {
                return((T)(object)42);
            }

            throw new NotImplementedException();
        }
Пример #30
0
        /// <summary>
        /// Converts to immutable Dictionary.
        /// </summary>
        /// <typeparam name="TKey">The type of the t key.</typeparam>
        /// <typeparam name="TValue">The type of the t value.</typeparam>
        /// <param name="values">The values.</param>
        /// <returns>ImmutableSortedDictionary&lt;TKey, TValue&gt;.</returns>
        /// <remarks>NEW: Added July 2019</remarks>
        public static ImmutableSortedDictionary <TKey, TValue> ToImmutable <TKey, TValue>(this SortedDictionary <TKey, TValue> values)
        {
            var builder = ImmutableSortedDictionary.CreateRange <TKey, TValue>(values);

            return(builder);
        }