c# extensionseXtlib

System.Data.DataRowView

added by skh 2011-01-18

Returns whether the specified column is null or empty

static bool IsColumnEmpty(this DataRowView row, string columnName)
{
    return row[columnName] == null || string.IsNullOrEmpty(row[columnName].ToString());
}

System.DateTime

added by jbo 2011-01-21

Returns the first day of the month

static DateTime GetFirstDayOfMonth(this DateTime date)
{
    return new DateTime(date.Year, date.Month, 1);
}
added by jbo 2011-01-21

Returns the first day of the week

static DateTime GetFirstDayOfWeek(this DateTime date, DayOfWeek startOfWeek)
{
    date = new DateTime(date.Year, date.Month, date.Day);
    int diff = date.DayOfWeek - startOfWeek;
    if (diff < 0)
    {
        diff += 7;
    }
    return date.AddDays(-1 * diff);
}

System.String

added by skh 2011-01-18

Appends the parameters

static string Append(this String str, params string[] parameters)
{
    return string.Concat(str, parameters);
}

added by skh 2011-01-18

Prepends the parameters

static string Prepend(this String str, params string[] parameters)
{
    return string.Concat(parameters, str);
}

System.Xml.XmlNode

added by skh 2011-01-19

Returns the integer value of the specified childnode

static int GetChildInt(this XmlNode node, string childNode)
{
    int result = -1;
    string str = node.GetChildString(childNode);
    if (str != null)
    {
        int.TryParse(str, out result);
        str = null;
    }
    return result;
}
added by skh 2011-01-18

Returns the string value of the specified childnode

static string GetChildString(this XmlNode node, string childNode)
{
    string str = null;
    XmlNode cNode = node.SelectSingleNode(string.Format("./{0}", childNode));
    if (cNode != null)
    {
        str = cNode.InnerText;
        cNode = null;
    }
    return str;
}