_Core/Helpers/ReflectionHelper.cs
(开头部分) 2KB这里只显示每个文件的开头 60 行。登录后可以解锁完整代码。
/*
* Author: Kishore Reddy
* Url: http://commonlibrarynet.codeplex.com/
* Title: CommonLibrary.NET
* Copyright: � 2009 Kishore Reddy
* License: LGPL License
* LicenseUrl: http://commonlibrarynet.codeplex.com/license
* Description: A C# based .NET 3.5 Open-Source collection of reusable components.
* Usage: Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
using System;
using System.Collections.Generic;
using System.Text;
using System.Reflection;
namespace ComLib
{
/// <summary>
/// This class provides basic reflection helper methods.
/// </summary>
public class ReflectionHelper
{
/// <summary>
/// Set the property value using the string value.
/// </summary>
/// <param name="obj">Object whose property is to be set.</param>
/// <param name="prop">Property name.</param>
/// <param name="propVal">Value to set.</param>
public static void SetProperty(object obj, PropertyInfo prop, string propVal)
{
Guard.IsNotNull(obj, "Object containing properties to set is null");
Guard.IsNotNull(prop, "Property not supplied.");
// Correct property with write access
if (prop != null && prop.CanWrite)
{
// Check same Type
if (Converter.CanConvertToCorrectType(prop, propVal))
{
object convertedVal = Converter.ConvertToSameType(prop, propVal);
prop.SetValue(obj, convertedVal, null);
}
}
}
/// <summary>
/// Gets the property value safely, without throwing an exception.
/// If an exception is caught, null is returned.
/// </summary>
/// <param name="obj">Object whose property is to be retrieved.</param>
/// <param name="propInfo">Property name.</param>
/// <returns></returns>
public static object GetPropertyValueSafely(object obj, PropertyInfo propInfo)
{
后面还有 16 行代码,解锁后查看完整代码
24 小时内免费解锁 3 个项目,之后 1 积分/个。 规则说明
AI 解读
登录后可用,每次 10 积分,解读结果公开显示在下面。
还没有人解读过这个文件。
