Table of Contents

Class ExtensionMethods

Namespace
EpNet
Assembly
EpNet.dll

Provides additional functionality in the form of extension methods.

public static class ExtensionMethods
Inheritance
ExtensionMethods

Methods

AddKpi(Environment, string, double)

Adds a Kpi result for parametric/optimisation. Use in AfterEnergySimulation hook.

public static void AddKpi(this Environment ApiEnvironment, string kpiName, double kpiValue)

Parameters

ApiEnvironment Environment
kpiName string
kpiValue double

CommonEnding(IEnumerable<string>)

Gets the substring in common at the end of a list of strings

public static string CommonEnding(this IEnumerable<string> stringList)

Parameters

stringList IEnumerable<string>

Returns

string

Common ending substring

CommonEnding(string, string)

Gets the substring in common at the end of two strings.

public static string CommonEnding(this string text1, string text2)

Parameters

text1 string

Current string.

text2 string

Second string.

Returns

string

Common ending substring

ContainsIgnoreCase(IEnumerable<string>, string)

Determines whether a sequence of strings contains a specified string. Ignores case.

public static bool ContainsIgnoreCase(this IEnumerable<string> s, string value)

Parameters

s IEnumerable<string>

Sequence of strings

value string

Search value.

Returns

bool

true if sequence contains the search string.

ContainsIgnoreCase(string, string)

Determines whether a specified substring occurs within this string.

public static bool ContainsIgnoreCase(this string s, string value)

Parameters

s string

Current string.

value string

Search substring.

Returns

bool

true if current string contains search substring.

ContainsIgnoreCase(string, params string[])

Determines whether any of the specified substrings occurs within this string.

public static bool ContainsIgnoreCase(this string s, params string[] values)

Parameters

s string

Current string.

values string[]

Search substrings.

Returns

bool

true if current string contains search substring.

ContainsWord(string, string)

Gets if the field string contains the whole string word. Ignores case.

public static bool ContainsWord(this string field, string word)

Parameters

field string

string where to look for

word string

searched string

Returns

bool

true if found

Deserialize(Type, string)

Deserializes an object which is saved to an XML data string.

public static object Deserialize(Type toDeserialize, string xmlData)

Parameters

toDeserialize Type

A type of an object of which XML data to deserialize.

xmlData string

A string containing a serialized XML data do deserialize.

Returns

object

An object which is deserialized from the XML data string.

Deserialize<T>(T, string)

Deserializes an object which is saved to an XML data string. If the object has no instance a new object will be constructed if possible.

note

An exception will occur if a null reference is called an no valid constructor of the class is available.

public static T Deserialize<T>(this T toDeserialize, string xmlData)

Parameters

toDeserialize T

An object of which XML data to deserialize. If the object is null a a default constructor is called.

xmlData string

A string containing a serialized XML data do deserialize.

Returns

T

An object which is deserialized from the XML data string.

Type Parameters

T

An object to deserialize from a XML data string.

EndsWithIgnoreCase(string, string)

Determines whether the end of this string instance matches the specified string. Ignores case.

public static bool EndsWithIgnoreCase(this string s, string value)

Parameters

s string

Current string.

value string

Search substring.

Returns

bool

true if current string ends with substring.

EqualsIgnoreCase(string, string)

Determines whether two strings are equal ignoring case

public static bool EqualsIgnoreCase(this string s, string value)

Parameters

s string

First string.

value string

Second strings

Returns

bool

true if both strings are equal ignoring case.

Find(IEnumerable<IdfObject>, string)

Searches for an IdfObject within the given collection that matches the specified name. Raises an exception if not found.

public static IdfObject Find(this IEnumerable<IdfObject> idfObjects, string name)

Parameters

idfObjects IEnumerable<IdfObject>

An IEnumerable collection of IdfObject instances to search.

name string

The name of the IdfObject to find. The search is case-sensitive.

Returns

IdfObject

The first IdfObject in the collection that matches the specified name.

FindByField(List<IdfObject>, int, string)

Returns the first idfObject where the provided field matches the value.

public static IdfObject FindByField(this List<IdfObject> idfObjects, int field, string value)

Parameters

idfObjects List<IdfObject>

idfObject List

field int

field number

value string

value to find

Returns

IdfObject

First idfObjectFound

FindByField(List<IdfObject>, string, string)

Returns the first idfObject where the provided field matches the value.

public static IdfObject FindByField(this List<IdfObject> idfObjects, string field, string value)

Parameters

idfObjects List<IdfObject>

idfObject List

field string

field name

value string

value to find

Returns

IdfObject

First idfObjectFound

GetByName(IEnumerable<IdfObject>, string)

Get the first element of a list of IdfObjects with a certain name

public static IdfObject GetByName(this IEnumerable<IdfObject> idf, string name)

Parameters

idf IEnumerable<IdfObject>

List of IdfObjects

name string

name to find

Returns

IdfObject

IdfObject with Name as name

GetData(IEnumerable<IdfObject>, int, int)

Gets a Dictionary<string,double>> with Keys as first field string values and Values as second field numeric values.

public static Dictionary<string, double> GetData(this IEnumerable<IdfObject> idf, int firstField, int secondField)

Parameters

idf IEnumerable<IdfObject>

Idf Object IEnumerable

firstField int

Zero-based first field position.

secondField int

Zero-based second field position.

Returns

Dictionary<string, double>

Dictionary with Keys as first fields and Values as second fields.

GetData(IEnumerable<IdfObject>, string, string)

Gets a Dictionary<string,double> with Keys as first field string values and Values as second field numeric values.

public static Dictionary<string, double> GetData(this IEnumerable<IdfObject> idf, string firstField, string secondField)

Parameters

idf IEnumerable<IdfObject>

Idf Object IEnumerable

firstField string

First field name.

secondField string

Second field name.

Returns

Dictionary<string, double>

Dictionary with Keys as first fields and Values as second fields.

GetData<T>(IEnumerable<IdfObject>, int, int)

Gets a Dictionary<string,T>> with Keys as first field string values and Values as second field T values.

public static Dictionary<string, T> GetData<T>(this IEnumerable<IdfObject> idf, int firstField, int secondField)

Parameters

idf IEnumerable<IdfObject>

Idf Object IEnumerable

firstField int

Zero-based first field position.

secondField int

Zero-based second field position.

Returns

Dictionary<string, T>

Dictionary with Keys as first fields and Values as second fields.

Type Parameters

T

double or string depending on the type of the second field

GetData<T>(IEnumerable<IdfObject>, string, string)

Gets a Dictionary<string,T>> with Keys as first field string values and Values as second field T values.

public static Dictionary<string, T> GetData<T>(this IEnumerable<IdfObject> idf, string firstField, string secondField)

Parameters

idf IEnumerable<IdfObject>

Idf Object IEnumerable

firstField string

First field name.

secondField string

Second field name.

Returns

Dictionary<string, T>

Dictionary with Keys as first fields and Values as second fields.

Type Parameters

T

double or string depending on the type of the second field

OR(bool, params bool[])

Alternative to || operator since DesignBuilder text parser does not allow | symbol

public static bool OR(this bool left, params bool[] others)

Parameters

left bool

left condition

others bool[]

right conditions

Returns

bool

the boolean OR between the conditions

OR(IEnumerable<bool>)

Alternative to || operator since DesignBuilder text parser does not allow | symbol

public static bool OR(this IEnumerable<bool> conditions)

Parameters

conditions IEnumerable<bool>

List of conditions

Returns

bool

OR of the conditions

ReadData(IdfObject, string)

Reads data from the Precomments of an idfObject

public static string ReadData(this IdfObject idfObject, string key)

Parameters

idfObject IdfObject
key string

Returns

string

RemoveData(IdfObject, string)

Removes data from the precomments of an idfObject

public static void RemoveData(this IdfObject idfObject, string key)

Parameters

idfObject IdfObject
key string

Serialize<T>(T)

A helper to serialize an object to a string containing XML data of the object.

public static string Serialize<T>(this T toSerialize)

Parameters

toSerialize T

A helper method for any type of object to be serialized to a XML data string.

Returns

string

A string containing XML data of the object.

Type Parameters

T

An object to serialize to a XML data string.

StartsWithAny(string, IEnumerable<string>)

Checks if the source string starts with any of the provided prefixes. Ignores case.

public static bool StartsWithAny(this string source, IEnumerable<string> prefixes)

Parameters

source string

The source string to check.

prefixes IEnumerable<string>

An enumerable collection of prefixes to compare against the source string.

Returns

bool

True if the source string starts with any of the given prefixes; otherwise, false.

StartsWithIgnoreCase(string, string)

Determines whether the beginning of this string instance matches the specified string. Ignores case.

public static bool StartsWithIgnoreCase(this string s, string value)

Parameters

s string

Current string.

value string

Search substring.

Returns

bool

true if current string starts with substring.

ToInt(string)

Converts from string to double using InvariantCulture.

public static double ToInt(this string value)

Parameters

value string

string value.

Returns

double

double value.

ToInt(string, CultureInfo)

Converts from string to int using a specified Culture format.

public static int ToInt(this string value, CultureInfo culture)

Parameters

value string

string value.

culture CultureInfo

Returns

int

int value.

ToNumber(string)

Converts from string to double using InvariantCulture.

public static double ToNumber(this string value)

Parameters

value string

string value.

Returns

double

double value.

ToNumber(string, CultureInfo)

Converts from string to double using a specified Culture format.

public static double ToNumber(this string value, CultureInfo culture)

Parameters

value string

string value.

culture CultureInfo

Returns

double

double value.

ToText(double)

Converts from number to string in InvariantCulture format

public static string ToText(this double value)

Parameters

value double

numeric value.

Returns

string

string value.

ToText(double, CultureInfo)

Converts from number to string in the specified Culture format

public static string ToText(this double value, CultureInfo culture)

Parameters

value double

numeric value

culture CultureInfo

Returns

string

string Value

ToText(int)

Converts from number to string in InvariantCulture format

public static string ToText(this int value)

Parameters

value int

numeric value.

Returns

string

string value.

ToText(int, CultureInfo)

Converts from number to string in the specified Culture format

public static string ToText(this int value, CultureInfo culture)

Parameters

value int

numeric value

culture CultureInfo

Returns

string

string Value

TrimFromEnd(string, string)

Trims the end of a string from the position where endString is found.

public static string TrimFromEnd(this string text, string endString)

Parameters

text string

Current string.

endString string

Search string.

Returns

string

Trimmed string

Update(IEnumerable<IdfObject>, Dictionary<string, double>, int, int)

From a provided dictionary, updates a field in a list of idf objects with Value where another field matches the Key.

public static void Update(this IEnumerable<IdfObject> idf, Dictionary<string, double> dictionary, int firstField, int secondField)

Parameters

idf IEnumerable<IdfObject>

idf objects enumerable

dictionary Dictionary<string, double>

Dictionary<string,double> where keys are strings that have to match the first field and values are the new values for the second field.

firstField int

field with text value

secondField int

field with numeric value

Update(IEnumerable<IdfObject>, Dictionary<string, double>, string, string)

From a provided dictionary, updates a field in a list of idf objects with Value where another field matches the Key.

public static void Update(this IEnumerable<IdfObject> idf, Dictionary<string, double> dictionary, string firstField, string secondField)

Parameters

idf IEnumerable<IdfObject>

idf objects enumerable

dictionary Dictionary<string, double>

Dictionary<string,double> where keys are strings that have to match the first field and values are the new values for the second field.

firstField string

field with text value

secondField string

field with numeric value

Update(IEnumerable<IdfObject>, Dictionary<string, string>, int, int)

From a provided dictionary, updates a field in a list of idf objects with Value where another field matches the Key.

public static void Update(this IEnumerable<IdfObject> idf, Dictionary<string, string> dictionary, int firstField, int secondField)

Parameters

idf IEnumerable<IdfObject>

idf objects enumerable

dictionary Dictionary<string, string>

Dictionary<string,string> where keys are strings that have to match the first field and values are the new values for the second field.

firstField int

field with text value

secondField int

field with text value

Update(IEnumerable<IdfObject>, Dictionary<string, string>, string, string)

From a provided dictionary, updates a field in a list of idf objects with Value where another field matches the Key.

public static void Update(this IEnumerable<IdfObject> idf, Dictionary<string, string> dictionary, string firstField, string secondField)

Parameters

idf IEnumerable<IdfObject>

idf objects enumerable

dictionary Dictionary<string, string>

Dictionary<string,string> where keys are strings that have to match the first field and values are the new values for the second field.

firstField string

field with text value

secondField string

field with text value

WithoutCommonEnding(IEnumerable<string>)

Returns the list of strings without the common ending removed (all share the same common ending)

public static IEnumerable<string> WithoutCommonEnding(this IEnumerable<string> stringList)

Parameters

stringList IEnumerable<string>

List of string

Returns

IEnumerable<string>

List of strings where the end of the string in common has been removed.

WriteData(IdfObject, string, string)

Writes data to the precomments of an idfObject

public static void WriteData(this IdfObject idfObject, string key, string value)

Parameters

idfObject IdfObject
key string
value string