Skip to content

Commit 0112ccf

Browse files
committed
Merge branch 'jnyrup-IsDefined'
2 parents 9178c66 + 12c8630 commit 0112ccf

File tree

3 files changed

+7
-7
lines changed

3 files changed

+7
-7
lines changed

src/CsvHelper/Configuration/ClassMap.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -346,7 +346,7 @@ protected virtual void AutoMapMembers(ClassMap map, CsvContext context, LinkedLi
346346
continue;
347347
}
348348

349-
if (!field.GetCustomAttributes(typeof(CompilerGeneratedAttribute), false).Any())
349+
if (!Attribute.IsDefined(field, typeof(CompilerGeneratedAttribute), false))
350350
{
351351
fields.Add(ReflectionHelper.GetDeclaringField(type, field, flags));
352352
}
@@ -357,7 +357,7 @@ protected virtual void AutoMapMembers(ClassMap map, CsvContext context, LinkedLi
357357

358358
foreach (var member in members)
359359
{
360-
if (member.GetCustomAttribute<IgnoreAttribute>() != null)
360+
if (Attribute.IsDefined(member, typeof(IgnoreAttribute)))
361361
{
362362
// Ignore this member including its tree if it's a reference.
363363
continue;
@@ -459,7 +459,7 @@ protected virtual void AutoMapConstructorParameters(ClassMap map, CsvContext con
459459
{
460460
var parameterMap = new ParameterMap(parameter);
461461

462-
if (parameter.GetCustomAttributes<IgnoreAttribute>(true).Any() || parameter.GetCustomAttributes<ConstantAttribute>(true).Any())
462+
if (Attribute.IsDefined(parameter, typeof(IgnoreAttribute), true) || Attribute.IsDefined(parameter, typeof(ConstantAttribute), true))
463463
{
464464
// If there is an IgnoreAttribute or ConstantAttribute, we still need to add a map because a constructor requires
465465
// all parameters to be present. A default value will be used later on.

src/CsvHelper/Configuration/CsvConfiguration.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -297,8 +297,8 @@ public static CsvConfiguration FromAttributes<T>(CultureInfo cultureInfo)
297297
/// <exception cref="CultureNotFoundException">If the argument to the <see cref="CultureInfoAttribute"/> does not specify a supported culture.</exception>
298298
public static CsvConfiguration FromAttributes(Type type)
299299
{
300-
var cultureInfoAttribute = (CultureInfoAttribute?)Attribute.GetCustomAttribute(type, typeof(CultureInfoAttribute));
301-
if (cultureInfoAttribute == null)
300+
var hasCultureInfoAttribute = Attribute.IsDefined(type, typeof(CultureInfoAttribute));
301+
if (!hasCultureInfoAttribute)
302302
{
303303
throw new ConfigurationException($"A {nameof(CultureInfoAttribute)} is required on type '{type.Name}' to use this method.");
304304
}

src/CsvHelper/ReflectionHelper.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ public static FieldInfo GetDeclaringField(Type type, FieldInfo field, BindingFla
6161
[MethodImpl(MethodImplOptions.AggressiveInlining)]
6262
public static List<PropertyInfo> GetUniqueProperties(Type type, BindingFlags flags, bool overwrite = false)
6363
{
64-
var ignoreBase = type.GetCustomAttribute(typeof(IgnoreBaseAttribute)) != null;
64+
var ignoreBase = Attribute.IsDefined(type, typeof(IgnoreBaseAttribute));
6565

6666
var properties = new Dictionary<string, PropertyInfo>();
6767

@@ -99,7 +99,7 @@ public static List<PropertyInfo> GetUniqueProperties(Type type, BindingFlags fla
9999
[MethodImpl(MethodImplOptions.AggressiveInlining)]
100100
public static List<FieldInfo> GetUniqueFields(Type type, BindingFlags flags, bool overwrite = false)
101101
{
102-
var ignoreBase = type.GetCustomAttribute(typeof(IgnoreBaseAttribute)) != null;
102+
var ignoreBase = Attribute.IsDefined(type, typeof(IgnoreBaseAttribute));
103103

104104
var fields = new Dictionary<string, FieldInfo>();
105105

0 commit comments

Comments
 (0)