Show / Hide Table of Contents

Class ParameterBuilder

This class builds parameter strings of the type [item&item&item], with selectable start, middle and end delimiters

Inheritance
object
ParameterBuilder
Inherited Members
object.Equals(object)
object.Equals(object, object)
object.ReferenceEquals(object, object)
object.GetHashCode()
object.GetType()
object.MemberwiseClone()
Namespace: SuperOffice.Util
Assembly: SoCore.dll
Syntax
public class ParameterBuilder
Remarks

A StringBuilder class is used for improved performance, there should be only one memory allocation during formatting regardless of the number of items. The item collection is a List and has its usual behavior.

Examples

XmlUtil.ParameterBuilder modebits = new XmlUtil.ParameterBuilder( "[", "&", "]" ); if( ( extApp.ShowState & ShowState.ToolBar ) == ShowState.ToolBar ) modebits.Add( "Toolbar=true" ); if( ( (int)extApp.ShowState & (int)ShowState.MenuBar ) != 0 ) modebits.Add( "Menubar=true" ); if( ( (int)extApp.ShowState & (int)ShowState.AddressBar ) != 0 ) modebits.Add( "Adressbar=true" ); if( ( (int)extApp.ShowState & (int)ShowState.StatusBar ) != 0 ) modebits.Add( "Statusbar=true" );

_soProtocolModeBits = modebits.ToString();

Constructors

ParameterBuilder()

Default constructor, makes a builder with all delimiters blank

Declaration
public ParameterBuilder()
Remarks

A StringBuilder class is used for improved performance, there should be only one memory allocation during formatting regardless of the number of items. The item collection is a List and has its usual behavior.

ParameterBuilder(string)

Constructor that sets the middle delimiter, and leaves the start and end delimiters blank

Declaration
public ParameterBuilder(string middleDelimiter)
Parameters
Type Name Description
string middleDelimiter

String to be used as the middle delimiter

Remarks

A StringBuilder class is used for improved performance, there should be only one memory allocation during formatting regardless of the number of items. The item collection is a List and has its usual behavior.

ParameterBuilder(string, string, string)

Constructor that sets all delimiters

Declaration
public ParameterBuilder(string startDelimiter, string middleDelimiter, string endDelimiter)
Parameters
Type Name Description
string startDelimiter

String to be used as starting delimiter

string middleDelimiter

String to be used as middle delimiter

string endDelimiter

String to be used as end delimiter

Remarks

A StringBuilder class is used for improved performance, there should be only one memory allocation during formatting regardless of the number of items. The item collection is a List and has its usual behavior.

ParameterBuilder(string, string, string, params string[])

Constructor that sets all delimiters and populates the item collection. You can add more items later as well.

Declaration
public ParameterBuilder(string startDelimiter, string middleDelimiter, string endDelimiter, params string[] items)
Parameters
Type Name Description
string startDelimiter

String to be used as starting delimiter

string middleDelimiter

String to be used as middle delimiter

string endDelimiter

String to be used as end delimiter

string[] items

One or more string items that will be put into the item collection. You can add more items later.

Remarks

A StringBuilder class is used for improved performance, there should be only one memory allocation during formatting regardless of the number of items. The item collection is a List and has its usual behavior.

Properties

Capacity

Get or set the capacity of the items collection. Use this if you know in advance (or during use) how many items you need to set; this will make the Add operation an O(1) task instead of O(n). Note that the default behaviour is to allocate 10 items at a time, which is usually good enough

Declaration
public int Capacity { get; set; }
Property Value
Type Description
int
Remarks

A StringBuilder class is used for improved performance, there should be only one memory allocation during formatting regardless of the number of items. The item collection is a List and has its usual behavior.

Count

Get the number of items (excluding delimiters, but including empty items) currently in the items collection

Declaration
public int Count { get; }
Property Value
Type Description
int
Remarks

A StringBuilder class is used for improved performance, there should be only one memory allocation during formatting regardless of the number of items. The item collection is a List and has its usual behavior.

EndDelimiter

End delimiter, will be at the end of the resulting string. Can be empty.

Declaration
public string EndDelimiter { get; set; }
Property Value
Type Description
string
Remarks

A StringBuilder class is used for improved performance, there should be only one memory allocation during formatting regardless of the number of items. The item collection is a List and has its usual behavior.

MiddleDelimiter

Middle delimiter, will be between items if there is more than one item. Can be empty.

Declaration
public string MiddleDelimiter { get; set; }
Property Value
Type Description
string
Remarks

A StringBuilder class is used for improved performance, there should be only one memory allocation during formatting regardless of the number of items. The item collection is a List and has its usual behavior.

StartDelimiter

Starting delimiter, will be at the beginning of the resulting string. Can be empty.

Declaration
public string StartDelimiter { get; set; }
Property Value
Type Description
string
Remarks

A StringBuilder class is used for improved performance, there should be only one memory allocation during formatting regardless of the number of items. The item collection is a List and has its usual behavior.

UseDelimitersBetweenEmptyElements

This class builds parameter strings of the type [item&item&item], with selectable start, middle and end delimiters

Declaration
public bool UseDelimitersBetweenEmptyElements { get; set; }
Property Value
Type Description
bool
Remarks

A StringBuilder class is used for improved performance, there should be only one memory allocation during formatting regardless of the number of items. The item collection is a List and has its usual behavior.

UseDelimitersIfEmpty

Should the start and end delimiters be in the output string, even if there are no items. Default false.

Declaration
public bool UseDelimitersIfEmpty { get; set; }
Property Value
Type Description
bool
Remarks

A StringBuilder class is used for improved performance, there should be only one memory allocation during formatting regardless of the number of items. The item collection is a List and has its usual behavior.

Methods

Add(params string[])

Add one or more items to the end of the item collection

Declaration
public void Add(params string[] items)
Parameters
Type Name Description
string[] items
Remarks

A StringBuilder class is used for improved performance, there should be only one memory allocation during formatting regardless of the number of items. The item collection is a List and has its usual behavior.

AddRange(IEnumerable<string>)

Add one or more items to the end of the item collection

Declaration
public void AddRange(IEnumerable<string> items)
Parameters
Type Name Description
IEnumerable<string> items
Remarks

A StringBuilder class is used for improved performance, there should be only one memory allocation during formatting regardless of the number of items. The item collection is a List and has its usual behavior.

Clear()

Clear all data, but keep all settings

Declaration
public void Clear()
Remarks

A StringBuilder class is used for improved performance, there should be only one memory allocation during formatting regardless of the number of items. The item collection is a List and has its usual behavior.

Format(string, bool, params string[])

This class builds parameter strings of the type [item&item&item], with selectable start, middle and end delimiters

Declaration
public static string Format(string middleDelimiter, bool useDelimitersBetweenEmptyElements, params string[] items)
Parameters
Type Name Description
string middleDelimiter
bool useDelimitersBetweenEmptyElements
string[] items
Returns
Type Description
string
Remarks

A StringBuilder class is used for improved performance, there should be only one memory allocation during formatting regardless of the number of items. The item collection is a List and has its usual behavior.

Examples

XmlUtil.ParameterBuilder modebits = new XmlUtil.ParameterBuilder( "[", "&", "]" ); if( ( extApp.ShowState & ShowState.ToolBar ) == ShowState.ToolBar ) modebits.Add( "Toolbar=true" ); if( ( (int)extApp.ShowState & (int)ShowState.MenuBar ) != 0 ) modebits.Add( "Menubar=true" ); if( ( (int)extApp.ShowState & (int)ShowState.AddressBar ) != 0 ) modebits.Add( "Adressbar=true" ); if( ( (int)extApp.ShowState & (int)ShowState.StatusBar ) != 0 ) modebits.Add( "Statusbar=true" );

_soProtocolModeBits = modebits.ToString();

Format(string, params string[])

Shortcut method that will create a parameterbuilder with the given middle delimiter, add all items to it, and return the resulting string

Declaration
public static string Format(string middleDelimiter, params string[] items)
Parameters
Type Name Description
string middleDelimiter

Middle delimiter to use

string[] items

Items to add, can be null or empty

Returns
Type Description
string

Items separated by given delimiter

Remarks

A StringBuilder class is used for improved performance, there should be only one memory allocation during formatting regardless of the number of items. The item collection is a List and has its usual behavior.

FormatObjects(string, params object[])

Shortcut method that will create a parameterbuilder with the given middle delimiter, add all items to it, and return the resulting string

Declaration
public static string FormatObjects(string middleDelimiter, params object[] items)
Parameters
Type Name Description
string middleDelimiter

Middle delimiter to use

object[] items

Items to add, can be null or empty

Returns
Type Description
string

Items separated by given delimiter

Remarks

A StringBuilder class is used for improved performance, there should be only one memory allocation during formatting regardless of the number of items. The item collection is a List and has its usual behavior.

ToReverseString()

Combine all items and delimiters to produce the final result - but iterate in reverse over the items

Declaration
public string ToReverseString()
Returns
Type Description
string

Formatted results, which is never null but may be string.Empty if there are no items and no delimiters

Remarks

A StringBuilder class is used for improved performance, there should be only one memory allocation regardless of the number of items.

ToString()

Combine all items and delimiters to produce the final result

Declaration
public override string ToString()
Returns
Type Description
string

Formatted results, which is never null but may be string.Empty if there are no items and no delimiters

Overrides
object.ToString()
Remarks

A StringBuilder class is used for improved performance, there should be only one memory allocation regardless of the number of items.

Extension Methods

EnumUtil.MapEnums<From, To>(From)
Converters.MapEnums<From, To>(From)
ObjectExtensions.AssignByReflection<T>(T, T)
ObjectExtensions.GraphCopy<T>(T)
© SuperOffice. All rights reserved.
SuperOffice |  Community |  Release Notes |  Privacy |  Site feedback |  Search Docs |  About Docs |  Contribute |  Back to top