[/csharp][/csharp][/csharp][/csharp][/csharp]
Gets the value of a static property on a specific type.
[/csharp][/csharp][/csharp][/csharp][/csharp]
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
{
///
///
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]
Return true> if the specified property name identifies a writeable property on the specified object;
[/csharp][/csharp][/csharp][/csharp][/csharp]
Return true> if the specified property name identifies a readable property on the specified object;
[/csharp][/csharp][/csharp][/csharp][/csharp]
Determine if a property's Type is an enum
[/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
{
///
///
///
///
///
/// Copyright 2006 by Edward Lim.
/// All rights reserved.
///
///
public sealed class PropertyUtils
{
private PropertyUtils() {}
/// ——————————————————————–
///
///
/// target object in which property is to be set
/// name of the property
/// value of the object to be set
/// ignore case sensitivity
///
///
/// ——————————————————————–
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]