mirror of
				https://github.com/lantean-code/qbtmud.git
				synced 2025-11-04 05:53:22 +00:00 
			
		
		
		
	
		
			
				
	
	
		
			48 lines
		
	
	
		
			1.3 KiB
		
	
	
	
		
			C#
		
	
	
	
	
	
			
		
		
	
	
			48 lines
		
	
	
		
			1.3 KiB
		
	
	
	
		
			C#
		
	
	
	
	
	
namespace Lantean.QBitTorrentClient
 | 
						|
{
 | 
						|
    public class FormUrlEncodedBuilder
 | 
						|
    {
 | 
						|
        private readonly IList<KeyValuePair<string, string>> _parameters;
 | 
						|
 | 
						|
        public FormUrlEncodedBuilder()
 | 
						|
        {
 | 
						|
            _parameters = [];
 | 
						|
        }
 | 
						|
 | 
						|
        public FormUrlEncodedBuilder(IList<KeyValuePair<string, string>> parameters)
 | 
						|
        {
 | 
						|
            _parameters = parameters;
 | 
						|
        }
 | 
						|
 | 
						|
        public FormUrlEncodedBuilder Add(string key, string value)
 | 
						|
        {
 | 
						|
            _parameters.Add(new KeyValuePair<string, string>(key, value));
 | 
						|
            return this;
 | 
						|
        }
 | 
						|
 | 
						|
        public FormUrlEncodedBuilder AddIfNotNullOrEmpty(string key, string? value)
 | 
						|
        {
 | 
						|
            if (!string.IsNullOrEmpty(value))
 | 
						|
            {
 | 
						|
                _parameters.Add(new KeyValuePair<string, string>(key, value));
 | 
						|
            }
 | 
						|
 | 
						|
            return this;
 | 
						|
        }
 | 
						|
 | 
						|
        public FormUrlEncodedBuilder AddIfNotNullOrEmpty<T>(string key, T? value) where T : struct
 | 
						|
        {
 | 
						|
            if (value.HasValue)
 | 
						|
            {
 | 
						|
                _parameters.Add(new KeyValuePair<string, string>(key, value.ToString()!));
 | 
						|
            }
 | 
						|
 | 
						|
            return this;
 | 
						|
        }
 | 
						|
 | 
						|
        public FormUrlEncodedContent ToFormUrlEncodedContent()
 | 
						|
        {
 | 
						|
            return new FormUrlEncodedContent(_parameters);
 | 
						|
        }
 | 
						|
    }
 | 
						|
} |