コード例 #1
0
        /// <summary>
        /// Renders the object as a properly formatted Touchstone file based on the configured Touchstone options.
        /// </summary>
        /// <returns>A string representation of a Touchstone file.</returns>
        public override string ToString()
        {
            StringBuilder sb = new StringBuilder();

            using TouchstoneWriter writer = TouchstoneWriter.Create(sb);
            writer.Options  = Options;
            writer.Keywords = Keywords;

            foreach (var data in NetworkParameters)
            {
                writer.WriteData(data);
            }
            return(sb.ToString());
        }
コード例 #2
0
        /// <summary>Writes the Touchstone file object to the specified file with the specified writer settings.</summary>
        /// <param name="filePath">The *.sNp file to be created or overwritten.</param>
        /// <param name="settings">Additional settings regarding how the network data in the file should be written.</param>
        /// <remarks>Use the <see cref="TouchstoneWriter"/> class for more control over the file writing process.</remarks>
        public void Write(string filePath, TouchstoneWriterSettings settings)
        {
            if (filePath == null)
            {
                throw new ArgumentNullException(nameof(filePath));
            }

            using (TouchstoneWriter writer = TouchstoneWriter.Create(filePath, settings))
            {
                writer.Options  = Options;
                writer.Keywords = Keywords;

                foreach (var pair in NetworkParameters)
                {
                    writer.WriteData(pair);
                }
                writer.Flush();
            };
        }
コード例 #3
0
        /// <summary>Asynchronously writes the Touchstone file object to the specified file with the specified writer settings.</summary>
        /// <param name="filePath">The *.sNp file to be created or overwritten.</param>
        /// <param name="settings">Additional settings regarding how the network data in the file should be written.</param>
        /// <param name="token">A <see cref="CancellationToken"/> to cancel the operation.</param>
        /// <remarks>Use the <see cref="TouchstoneWriter"/> class for more control over the file writing process.</remarks>
        public async Task WriteAsync(string filePath, TouchstoneWriterSettings settings, CancellationToken token = default)
        {
            if (filePath == null)
            {
                throw new ArgumentNullException(nameof(filePath));
            }

            using (TouchstoneWriter writer = TouchstoneWriter.Create(filePath, settings))
            {
                writer.Options     = Options;
                writer.Keywords    = Keywords;
                writer.CancelToken = token;

                foreach (var pair in NetworkParameters)
                {
                    token.ThrowIfCancellationRequested();
                    await writer.WriteDataAsync(pair);
                }

                writer.Flush();
            };
        }