Class ExtensionMethods
- Namespace
- EpNet
- Assembly
- EpNet.dll
Provides additional functionality in the form of extension methods.
public static class ExtensionMethods
- Inheritance
-
objectExtensionMethods
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
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
stringListIEnumerable<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
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
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
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
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
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
toDeserializeTypeA type of an object of which XML data to deserialize.
xmlDatastringA 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
toDeserializeTAn object of which XML data to deserialize. If the object is null a a default constructor is called.
xmlDatastringA string containing a serialized XML data do deserialize.
Returns
- T
An object which is deserialized from the XML data string.
Type Parameters
TAn 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
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
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
idfObjectsIEnumerable<IdfObject>An IEnumerable collection of IdfObject instances to search.
namestringThe 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
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
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
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
idfIEnumerable<IdfObject>Idf Object IEnumerable
firstFieldintZero-based first field position.
secondFieldintZero-based second field position.
Returns
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
idfIEnumerable<IdfObject>Idf Object IEnumerable
firstFieldstringFirst field name.
secondFieldstringSecond field name.
Returns
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
idfIEnumerable<IdfObject>Idf Object IEnumerable
firstFieldintZero-based first field position.
secondFieldintZero-based second field position.
Returns
- Dictionary<string, T>
Dictionary with Keys as first fields and Values as second fields.
Type Parameters
Tdouble 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
idfIEnumerable<IdfObject>Idf Object IEnumerable
firstFieldstringFirst field name.
secondFieldstringSecond field name.
Returns
- Dictionary<string, T>
Dictionary with Keys as first fields and Values as second fields.
Type Parameters
Tdouble 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
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
conditionsIEnumerable<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
Returns
RemoveData(IdfObject, string)
Removes data from the precomments of an idfObject
public static void RemoveData(this IdfObject idfObject, string key)
Parameters
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
toSerializeTA 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
TAn 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
sourcestringThe source string to check.
prefixesIEnumerable<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
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
valuestringstring 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
valuestringstring value.
cultureCultureInfo
Returns
- int
int value.
ToNumber(string)
Converts from string to double using InvariantCulture.
public static double ToNumber(this string value)
Parameters
valuestringstring 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
valuestringstring value.
cultureCultureInfo
Returns
- double
double value.
ToText(double)
Converts from number to string in InvariantCulture format
public static string ToText(this double value)
Parameters
valuedoublenumeric 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
valuedoublenumeric value
cultureCultureInfo
Returns
- string
string Value
ToText(int)
Converts from number to string in InvariantCulture format
public static string ToText(this int value)
Parameters
valueintnumeric 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
valueintnumeric value
cultureCultureInfo
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
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
idfIEnumerable<IdfObject>idf objects enumerable
dictionaryDictionary<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.
firstFieldintfield with text value
secondFieldintfield 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
idfIEnumerable<IdfObject>idf objects enumerable
dictionaryDictionary<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.
firstFieldstringfield with text value
secondFieldstringfield 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
idfIEnumerable<IdfObject>idf objects enumerable
dictionaryDictionary<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.
firstFieldintfield with text value
secondFieldintfield 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
idfIEnumerable<IdfObject>idf objects enumerable
dictionaryDictionary<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.
firstFieldstringfield with text value
secondFieldstringfield 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
stringListIEnumerable<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)