本文整理汇总了C#中PropertyData.GetPropertyInfo方法的典型用法代码示例。如果您正苦于以下问题:C# PropertyData.GetPropertyInfo方法的具体用法?C# PropertyData.GetPropertyInfo怎么用?C# PropertyData.GetPropertyInfo使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PropertyData
的用法示例。
在下文中一共展示了PropertyData.GetPropertyInfo方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ValidatePropertyUsingAnnotations
/// <summary>
/// Validates the property using data annotations.
/// </summary>
/// <param name="propertyName">Name of the property.</param>
/// <param name="value">The value to validate.</param>
/// <param name="catelPropertyData">The catel property data. Can be <c>null</c> for non-Catel properties.</param>
/// <returns><c>true</c> if no errors using data annotations are found; otherwise <c>false</c>.</returns>
private bool ValidatePropertyUsingAnnotations(string propertyName, object value, PropertyData catelPropertyData)
{
if (SuspendValidation)
{
_propertiesNotCheckedDuringDisabledValidation.Add(propertyName);
return true;
}
#if !WINDOWS_PHONE && !NETFX_CORE && !PCL && !NET35
var type = GetType();
try
{
if (!_propertyValuesIgnoredOrFailedForValidation[type].Contains(propertyName))
{
if (catelPropertyData != null)
{
var propertyInfo = catelPropertyData.GetPropertyInfo(type);
if (propertyInfo == null || !propertyInfo.HasPublicGetter)
{
_propertyValuesIgnoredOrFailedForValidation[type].Add(propertyName);
return false;
}
}
else
{
#if NET
if (type.GetPropertyEx(propertyName) == null)
{
Log.Debug("Property '{0}' cannot be found via reflection, ignoring this property for type '{1}'", propertyName, type.FullName);
_propertyValuesIgnoredOrFailedForValidation[type].Add(propertyName);
return false;
}
#else
// Checking via reflection is faster than catching the exception
if (!Reflection.PropertyHelper.IsPublicProperty(this, propertyName))
{
Log.Debug("Property '{0}' is not a public property, cannot validate non-public properties in silverlight", propertyName);
_propertyValuesIgnoredOrFailedForValidation[type].Add(propertyName);
return false;
}
#endif
}
if (!_dataAnnotationsValidationContext.ContainsKey(propertyName))
{
_dataAnnotationsValidationContext[propertyName] = new System.ComponentModel.DataAnnotations.ValidationContext(this, null, null) { MemberName = propertyName };
}
System.ComponentModel.DataAnnotations.Validator.ValidateProperty(value, _dataAnnotationsValidationContext[propertyName]);
// If succeeded, clear any previous error
if (_dataAnnotationValidationResults.ContainsKey(propertyName))
{
_dataAnnotationValidationResults[propertyName] = null;
}
}
}
catch (System.ComponentModel.DataAnnotations.ValidationException validationException)
{
_dataAnnotationValidationResults[propertyName] = validationException.Message;
return false;
}
catch (Exception ex)
{
_propertyValuesIgnoredOrFailedForValidation[type].Add(propertyName);
Log.Warning(ex, "Failed to validate property '{0}' via Validator (property does not exists?)", propertyName);
}
#endif
return true;
}