本文整理汇总了C#中System.Type.Type.GetCustomAttributes方法的典型用法代码示例。如果您正苦于以下问题:C# Type.Type.GetCustomAttributes方法的具体用法?C# Type.Type.GetCustomAttributes怎么用?C# Type.Type.GetCustomAttributes使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Type.Type
的用法示例。
在下文中一共展示了Type.Type.GetCustomAttributes方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: IsIgnored
/// <summary>
/// Determines if the property or field should not be serialized.
/// </summary>
/// <param name="objType"></param>
/// <param name="member"></param>
/// <param name="value"></param>
/// <returns></returns>
/// <remarks>
/// Checks these in order, if any returns true then this is true:
/// - is flagged with the JsonIgnoreAttribute property
/// - has a JsonSpecifiedProperty which returns false
/// </remarks>
private bool IsIgnored(Type objType, MemberInfo member, object obj)
{
if (JsonIgnoreAttribute.IsJsonIgnore(member))
{
return true;
}
string specifiedProperty = JsonSpecifiedPropertyAttribute.GetJsonSpecifiedProperty(member);
if (!String.IsNullOrEmpty(specifiedProperty))
{
PropertyInfo specProp = objType.GetProperty(specifiedProperty);
if (specProp != null)
{
object isSpecified = specProp.GetValue(obj, null);
if (isSpecified is Boolean && !Convert.ToBoolean(isSpecified))
{
return true;
}
}
}
//If the class is specified as opt-in serialization only, members must have the JsonMember attribute
if (objType.GetCustomAttributes (typeof(JsonOptInAttribute),true).Length != 0) {
if (member.GetCustomAttributes(typeof(JsonMemberAttribute),true).Length == 0) {
return true;
}
}
if (this.settings.UseXmlSerializationAttributes)
{
if (JsonIgnoreAttribute.IsXmlIgnore(member))
{
return true;
}
PropertyInfo specProp = objType.GetProperty(member.Name+"Specified");
if (specProp != null)
{
object isSpecified = specProp.GetValue(obj, null);
if (isSpecified is Boolean && !Convert.ToBoolean(isSpecified))
{
return true;
}
}
}
return false;
}