Integration Property To String

//CruiseControl is open source software and is developed and maintained by a group of dedicated volunteers.
//CruiseControl is distributed under a BSD-style license.
//http://cruisecontrol.sourceforge.net/
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Text;
using System.Text.RegularExpressions;

namespace ThoughtWorks.CruiseControl.Core.Util
{
///

/// Class with handy stirng routines
///

public class StringUtil
{

public static string IntegrationPropertyToString(object value)
{
string DEFAULT_DELIMITER = “,”;
return IntegrationPropertyToString(value, DEFAULT_DELIMITER);
}

public static string IntegrationPropertyToString(object value, string delimiter)
{
if (value == null)
return null;

if ((value is string) || (value is int) || (value is Enum))
return value.ToString();

if (value is ArrayList)
{
string[] tmp = (string[])((ArrayList)value).ToArray(typeof(string));
if (tmp.Length <= 1) return string.Join(string.Empty, tmp); return string.Format(""{0}"", string.Join(delimiter, tmp)); } throw new ArgumentException( string.Format("The IntegrationProperty type {0} is not supported yet", value.GetType()), "value"); } } } [/csharp][/csharp][/csharp][/csharp][/csharp][/csharp][/csharp]

Set the value of a property that has been declared as an Enum type using reflection

#region License and Copyright
/*
* Dotnet Commons Reflection
*
* Copyright 2005. EDWARD LIM
*
* This library is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 2.1 of the License, or
* (at your option) any later version.
*
* This library is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
* for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this library; if not, write to the
* Free Software Foundation, Inc.,
* 59 Temple Place,
* Suite 330,
* Boston,
* MA 02111-1307
* USA
*
*/
#endregion

using System;
using System.Collections;
using System.Collections.Specialized;
using System.Reflection;

//using Dotnet.Commons.Lang;

namespace Dotnet.Commons.Reflection
{
///
///

/// This class contains utility methods that perform operations on object properties.
///

///
///
/// Copyright 2006 by Edward Lim.
/// All rights reserved.
///

///
public sealed class PropertyUtils
{
private PropertyUtils() {}

/// ——————————————————————–
///

/// Set the value of a property that has been declared as an Enum type using reflection
///

/// target object in which property is to be set /// name of the property /// value of the object to be set /// ignore case sensitivity /// null if target object or is null, else target object with property set if property if found
/// if the propertyName is null or empty
/// ——————————————————————–
public static object SetEnumTypeProperty(object targetObj, string propertyName, object propertyValue, bool ignoreCase)
{
if (targetObj == null)
return null;

if ((propertyName == null) || (propertyName.Length < 1)) { throw new ArgumentException("propertyName cannot be null or empty."); } if (propertyValue == null) return targetObj; PropertyInfo propInfo = targetObj.GetType().GetProperty(propertyName); if (propInfo == null) return targetObj; if (!propInfo.PropertyType.IsEnum) throw new ArgumentException("property " + propertyName + " is not an Enum type"); if (propertyValue is String) propertyValue = Enum.Parse(propInfo.PropertyType, (string) propertyValue, ignoreCase); propInfo.SetValue(targetObj, Enum.ToObject(propInfo.PropertyType, Convert.ToUInt64(propertyValue)), null); return targetObj; } } } [/csharp][/csharp][/csharp][/csharp][/csharp][/csharp][/csharp]

Get the type of the Property.

#region License and Copyright
/*
* Dotnet Commons Reflection
*
* Copyright 2005. EDWARD LIM
*
* This library is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 2.1 of the License, or
* (at your option) any later version.
*
* This library is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
* for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this library; if not, write to the
* Free Software Foundation, Inc.,
* 59 Temple Place,
* Suite 330,
* Boston,
* MA 02111-1307
* USA
*
*/
#endregion

using System;
using System.Collections;
using System.Collections.Specialized;
using System.Reflection;

//using Dotnet.Commons.Lang;

namespace Dotnet.Commons.Reflection
{
///
///

/// This class contains utility methods that perform operations on object properties.
///

///
///
/// Copyright 2006 by Edward Lim.
/// All rights reserved.
///

///
public sealed class PropertyUtils
{
private PropertyUtils() {}

/// ——————————————————————–
///

/// Get the type of the Property.
///

/// the object to investigate /// name of the property /// flag to indicate if the the search should include private properties /// the Type of the property
/// ——————————————————————–
public static Type GetPropertyType(object targetObj, string property, bool searchPrivate)
{
if (targetObj == null)
throw new System.ArgumentNullException(“targetObject”);

if ((property == null) || (property.Length < 1)) return null; BindingFlags flags = BindingFlags.Public | BindingFlags.Instance | BindingFlags.Static; if (searchPrivate) flags = flags | BindingFlags.NonPublic; PropertyInfo propInfo = targetObj.GetType().GetProperty(property); return propInfo.PropertyType; } } } [/csharp][/csharp][/csharp][/csharp][/csharp][/csharp][/csharp]