DmdCustomAttributeNamedArgument ReadNamedArgument() { bool isField; switch ((SerializationType)reader.ReadByte()) { case SerializationType.Property:isField = false; break; case SerializationType.Field: isField = true; break; default: throw new CABlobParserException("Named argument is not a field/property"); } var fieldPropType = ReadFieldOrPropType(); var name = ReadUTF8String(); var argument = ReadFixedArg(fieldPropType); DmdMemberInfo memberInfo; if (isField) { var field = ctorReflectedType.GetField(name); if ((object)field == null || !DmdMemberInfoEqualityComparer.DefaultMember.Equals(field.FieldType, fieldPropType)) memberInfo = null; else memberInfo = field; } else { var property = ctorReflectedType.GetProperty(name); if ((object)property == null || !DmdMemberInfoEqualityComparer.DefaultMember.Equals(property.PropertyType, fieldPropType)) memberInfo = null; else memberInfo = property; } if ((object)memberInfo == null) throw new ResolveException($"Couldn't resolve CA {(isField ? "field" : "property")}: {name}"); return new DmdCustomAttributeNamedArgument(memberInfo, argument); }
DmdCustomAttributeNamedArgument ReadNamedArgument() { bool isField; switch ((SerializationType)reader.ReadByte()) { case SerializationType.Property: isField = false; break; case SerializationType.Field: isField = true; break; default: throw new CABlobParserException("Named argument is not a field/property"); } var fieldPropType = ReadFieldOrPropType(); var name = ReadUTF8String() ?? string.Empty; var argument = ReadFixedArg(fieldPropType); DmdMemberInfo?memberInfo; if (isField) { var field = ctorReflectedType.GetField(name); if (field is null || !DmdMemberInfoEqualityComparer.DefaultMember.Equals(field.FieldType, fieldPropType)) { memberInfo = null; } else { memberInfo = field; } }
static DmdFieldInfo?TryGetBuilderFieldByname(DmdType type) { foreach (var name in KnownMemberNames.builderFieldNames) { const DmdBindingFlags flags = DmdBindingFlags.Instance | DmdBindingFlags.Public | DmdBindingFlags.NonPublic; if (type.GetField(name, flags) is DmdFieldInfo field) { return(field); } } return(null); }