Fix IDE0025 (use expression body for properties)
[mono-project.git] / netcore / System.Private.CoreLib / shared / System / Reflection / CustomAttributeNamedArgument.cs
blob8aa4d8fa72daf63b4da6f007f67b560a9f36ea30
1 // Licensed to the .NET Foundation under one or more agreements.
2 // The .NET Foundation licenses this file to you under the MIT license.
3 // See the LICENSE file in the project root for more information.
5 namespace System.Reflection
7 public readonly partial struct CustomAttributeNamedArgument
9 public static bool operator ==(CustomAttributeNamedArgument left, CustomAttributeNamedArgument right) => left.Equals(right);
10 public static bool operator !=(CustomAttributeNamedArgument left, CustomAttributeNamedArgument right) => !left.Equals(right);
12 private readonly MemberInfo m_memberInfo;
13 private readonly CustomAttributeTypedArgument m_value;
15 public CustomAttributeNamedArgument(MemberInfo memberInfo, object? value)
17 if (memberInfo == null)
18 throw new ArgumentNullException(nameof(memberInfo));
20 Type type;
21 if (memberInfo is FieldInfo field)
23 type = field.FieldType;
25 else if (memberInfo is PropertyInfo property)
27 type = property.PropertyType;
29 else
31 throw new ArgumentException(SR.Argument_InvalidMemberForNamedArgument);
34 m_memberInfo = memberInfo;
35 m_value = new CustomAttributeTypedArgument(type, value);
38 public CustomAttributeNamedArgument(MemberInfo memberInfo, CustomAttributeTypedArgument typedArgument)
40 if (memberInfo == null)
41 throw new ArgumentNullException(nameof(memberInfo));
43 m_memberInfo = memberInfo;
44 m_value = typedArgument;
47 public override string ToString()
49 if (m_memberInfo == null)
50 return base.ToString()!;
52 return string.Format("{0} = {1}", MemberInfo.Name, TypedValue.ToString(ArgumentType != typeof(object)));
55 public override int GetHashCode()
57 return base.GetHashCode();
60 public override bool Equals(object? obj)
62 return obj == (object)this;
65 internal Type ArgumentType =>
66 m_memberInfo is FieldInfo ?
67 ((FieldInfo)m_memberInfo).FieldType :
68 ((PropertyInfo)m_memberInfo).PropertyType;
70 public MemberInfo MemberInfo => m_memberInfo;
71 public CustomAttributeTypedArgument TypedValue => m_value;
72 public string MemberName => MemberInfo.Name;
73 public bool IsField => MemberInfo is FieldInfo;