diff --git a/src/libraries/System.Private.CoreLib/src/System/Type.cs b/src/libraries/System.Private.CoreLib/src/System/Type.cs index 9991def2f4b92..b25a7a0e6e319 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Type.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Type.cs @@ -132,6 +132,27 @@ public ConstructorInfo? TypeInitializer [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors)] public ConstructorInfo? GetConstructor(Type[] types) => GetConstructor(BindingFlags.Public | BindingFlags.Instance, null, types, null); + /// + /// Searches for a constructor whose parameters match the specified argument types, using the specified binding constraints. + /// + /// + /// A bitwise combination of the enumeration values that specify how the search is conducted. + /// -or- + /// Default to return null. + /// + /// + /// An array of Type objects representing the number, order, and type of the parameters for the constructor to get. + /// -or- + /// An empty array of the type (that is, Type[] types = Array.Empty{Type}()) to get a constructor that takes no parameters. + /// -or- + /// . + /// + /// + /// A object representing the constructor that matches the specified requirements, if found; otherwise, null. + /// + [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors | DynamicallyAccessedMemberTypes.NonPublicConstructors)] + public ConstructorInfo? GetConstructor(BindingFlags bindingAttr, Type[] types) => GetConstructor(bindingAttr, binder: null, types, modifiers: null); + [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors | DynamicallyAccessedMemberTypes.NonPublicConstructors)] public ConstructorInfo? GetConstructor(BindingFlags bindingAttr, Binder? binder, Type[] types, ParameterModifier[]? modifiers) => GetConstructor(bindingAttr, binder, CallingConventions.Any, types, modifiers); @@ -221,6 +242,24 @@ public ConstructorInfo? TypeInitializer return GetMethodImpl(name, bindingAttr, null, CallingConventions.Any, null, null); } + /// + /// Searches for the specified method whose parameters match the specified argument types, using the specified binding constraints. + /// + /// The string containing the name of the method to get. + /// + /// A bitwise combination of the enumeration values that specify how the search is conducted. + /// -or- + /// Default to return null. + /// + /// + /// An array of objects representing the number, order, and type of the parameters for the method to get. + /// -or- + /// An empty array of objects (as provided by the field) to get a method that takes no parameters. + /// + /// An object representing the method that matches the specified requirements, if found; otherwise, null. + [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicMethods | DynamicallyAccessedMemberTypes.NonPublicMethods)] + public MethodInfo? GetMethod(string name, BindingFlags bindingAttr, Type[] types) => GetMethod(name, bindingAttr, binder: null, types, modifiers: null); + [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicMethods)] public MethodInfo? GetMethod(string name, Type[] types) => GetMethod(name, types, null); diff --git a/src/libraries/System.Private.DataContractSerialization/src/System/Runtime/Serialization/ClassDataContract.cs b/src/libraries/System.Private.DataContractSerialization/src/System/Runtime/Serialization/ClassDataContract.cs index 22f02e15a9728..db5869fde713e 100644 --- a/src/libraries/System.Private.DataContractSerialization/src/System/Runtime/Serialization/ClassDataContract.cs +++ b/src/libraries/System.Private.DataContractSerialization/src/System/Runtime/Serialization/ClassDataContract.cs @@ -388,7 +388,7 @@ internal static bool IsNonAttributedTypeValidForSerialization(Type type) else { return (type.IsVisible && - type.GetConstructor(BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public, null, Array.Empty(), null) != null); + type.GetConstructor(BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public, Array.Empty()) != null); } } @@ -1368,7 +1368,7 @@ private void SetKeyValuePairAdapterFlags(Type type) { _isKeyValuePairAdapter = true; _keyValuePairGenericArguments = type.GetGenericArguments(); - _keyValuePairCtorInfo = type.GetConstructor(Globals.ScanAllMembers, null, new Type[] { Globals.TypeOfKeyValuePair.MakeGenericType(_keyValuePairGenericArguments) }, null); + _keyValuePairCtorInfo = type.GetConstructor(Globals.ScanAllMembers, new Type[] { Globals.TypeOfKeyValuePair.MakeGenericType(_keyValuePairGenericArguments) }); _getKeyValuePairMethodInfo = type.GetMethod("GetKeyValuePair", Globals.ScanAllMembers)!; } } @@ -1408,7 +1408,7 @@ internal MethodInfo? GetKeyValuePairMethodInfo if (!IsISerializable) return null; - ConstructorInfo? ctor = UnderlyingType.GetConstructor(Globals.ScanAllMembers, null, SerInfoCtorArgs, null); + ConstructorInfo? ctor = UnderlyingType.GetConstructor(Globals.ScanAllMembers, SerInfoCtorArgs); if (ctor == null) throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(XmlObjectSerializer.CreateSerializationException(SR.Format(SR.SerializationInfo_ConstructorNotFound, DataContract.GetClrTypeFullName(UnderlyingType)))); @@ -1425,7 +1425,7 @@ internal MethodInfo? GetKeyValuePairMethodInfo if (type.IsValueType) return null; - ConstructorInfo? ctor = type.GetConstructor(BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public, null, Array.Empty(), null); + ConstructorInfo? ctor = type.GetConstructor(BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public, Array.Empty()); if (ctor == null) throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidDataContractException(SR.Format(SR.NonAttributedSerializableTypesMustHaveDefaultConstructor, DataContract.GetClrTypeFullName(type)))); diff --git a/src/libraries/System.Private.DataContractSerialization/src/System/Runtime/Serialization/CollectionDataContract.cs b/src/libraries/System.Private.DataContractSerialization/src/System/Runtime/Serialization/CollectionDataContract.cs index 430e7ba45df9b..55945694336f5 100644 --- a/src/libraries/System.Private.DataContractSerialization/src/System/Runtime/Serialization/CollectionDataContract.cs +++ b/src/libraries/System.Private.DataContractSerialization/src/System/Runtime/Serialization/CollectionDataContract.cs @@ -883,7 +883,7 @@ internal Type GetCollectionElementType() enumeratorType = GetEnumeratorMethod.ReturnType; } - MethodInfo? getCurrentMethod = enumeratorType.GetMethod(Globals.GetCurrentMethodName, BindingFlags.Instance | BindingFlags.Public, null, Array.Empty(), null); + MethodInfo? getCurrentMethod = enumeratorType.GetMethod(Globals.GetCurrentMethodName, BindingFlags.Instance | BindingFlags.Public, Array.Empty()); if (getCurrentMethod == null) { if (enumeratorType.IsInterface) @@ -1145,7 +1145,7 @@ private static bool IsCollectionOrTryCreate(Type type, bool tryCreate, out DataC ConstructorInfo? defaultCtor = null; if (!type.IsValueType) { - defaultCtor = type.GetConstructor(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic, null, Array.Empty(), null); + defaultCtor = type.GetConstructor(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic, Array.Empty()); if (defaultCtor == null && constructorRequired) { // All collection types could be considered read-only collections except collection types that are marked [Serializable]. @@ -1331,7 +1331,7 @@ private static void GetCollectionMethods(Type type, Type interfaceType, Type[] a if (addMethodOnInterface) { - addMethod = type.GetMethod(Globals.AddMethodName, BindingFlags.Instance | BindingFlags.Public, null, addMethodTypeArray, null); + addMethod = type.GetMethod(Globals.AddMethodName, BindingFlags.Instance | BindingFlags.Public, addMethodTypeArray); if (addMethod == null || addMethod.GetParameters()[0].ParameterType != addMethodTypeArray[0]) { FindCollectionMethodsOnInterface(type, interfaceType, ref addMethod, ref getEnumeratorMethod); @@ -1359,12 +1359,12 @@ private static void GetCollectionMethods(Type type, Type interfaceType, Type[] a else { // GetMethod returns Add() method with parameter closest matching T in assignability/inheritance chain - addMethod = type.GetMethod(Globals.AddMethodName, BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic, null, addMethodTypeArray, null); + addMethod = type.GetMethod(Globals.AddMethodName, BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic, addMethodTypeArray); } if (getEnumeratorMethod == null) { - getEnumeratorMethod = type.GetMethod(Globals.GetEnumeratorMethodName, BindingFlags.Instance | BindingFlags.Public, null, Array.Empty(), null); + getEnumeratorMethod = type.GetMethod(Globals.GetEnumeratorMethodName, BindingFlags.Instance | BindingFlags.Public, Array.Empty()); if (getEnumeratorMethod == null || !Globals.TypeOfIEnumerator.IsAssignableFrom(getEnumeratorMethod.ReturnType)) { Type? ienumerableInterface = interfaceType.GetInterfaces().Where(t => t.FullName!.StartsWith("System.Collections.Generic.IEnumerable")).FirstOrDefault(); diff --git a/src/libraries/System.Private.DataContractSerialization/src/System/Runtime/Serialization/DataContract.cs b/src/libraries/System.Private.DataContractSerialization/src/System/Runtime/Serialization/DataContract.cs index d720f0ef4f33c..8e1f6bc4f1d0a 100644 --- a/src/libraries/System.Private.DataContractSerialization/src/System/Runtime/Serialization/DataContract.cs +++ b/src/libraries/System.Private.DataContractSerialization/src/System/Runtime/Serialization/DataContract.cs @@ -1126,7 +1126,7 @@ internal MethodInfo? ParseMethod { if (!_parseMethodSet) { - MethodInfo? method = UnderlyingType.GetMethod(Globals.ParseMethodName, BindingFlags.Public | BindingFlags.Static, null, new Type[] { typeof(string) }, null); + MethodInfo? method = UnderlyingType.GetMethod(Globals.ParseMethodName, BindingFlags.Public | BindingFlags.Static, new Type[] { typeof(string) }); if (method != null && method.ReturnType == UnderlyingType) { @@ -1979,7 +1979,7 @@ private static void ImportKnownTypeAttributes(Type? type, Dictionary if (methodName.Length == 0) DataContract.ThrowInvalidDataContractException(SR.Format(SR.KnownTypeAttributeEmptyString, DataContract.GetClrTypeFullName(type)), type); - MethodInfo? method = type.GetMethod(methodName, BindingFlags.Static | BindingFlags.NonPublic | BindingFlags.Public, null, Array.Empty(), null); + MethodInfo? method = type.GetMethod(methodName, BindingFlags.Static | BindingFlags.NonPublic | BindingFlags.Public, Array.Empty()); if (method == null) DataContract.ThrowInvalidDataContractException(SR.Format(SR.KnownTypeAttributeUnknownMethod, methodName, DataContract.GetClrTypeFullName(type)), type); diff --git a/src/libraries/System.Private.DataContractSerialization/src/System/Runtime/Serialization/Json/JsonFormatGeneratorStatics.cs b/src/libraries/System.Private.DataContractSerialization/src/System/Runtime/Serialization/Json/JsonFormatGeneratorStatics.cs index 2ed0acc31cd18..6020b107db6b9 100644 --- a/src/libraries/System.Private.DataContractSerialization/src/System/Runtime/Serialization/Json/JsonFormatGeneratorStatics.cs +++ b/src/libraries/System.Private.DataContractSerialization/src/System/Runtime/Serialization/Json/JsonFormatGeneratorStatics.cs @@ -96,7 +96,7 @@ public static PropertyInfo CollectionItemNameProperty public static ConstructorInfo ExtensionDataObjectCtor => s_extensionDataObjectCtor ?? (s_extensionDataObjectCtor = - typeof(ExtensionDataObject).GetConstructor(Globals.ScanAllMembers, null, Array.Empty(), null))!; + typeof(ExtensionDataObject).GetConstructor(Globals.ScanAllMembers, Array.Empty()))!; public static PropertyInfo ExtensionDataProperty => s_extensionDataProperty ?? (s_extensionDataProperty = typeof(IExtensibleDataObject).GetProperty("ExtensionData")!); @@ -167,7 +167,7 @@ public static MethodInfo GetUninitializedObjectMethod { if (s_getUninitializedObjectMethod == null) { - s_getUninitializedObjectMethod = typeof(XmlFormatReaderGenerator).GetMethod("UnsafeGetUninitializedObject", Globals.ScanAllMembers, null, new Type[] { typeof(Type) }, null); + s_getUninitializedObjectMethod = typeof(XmlFormatReaderGenerator).GetMethod("UnsafeGetUninitializedObject", Globals.ScanAllMembers, new Type[] { typeof(Type) }); Debug.Assert(s_getUninitializedObjectMethod != null); } return s_getUninitializedObjectMethod; @@ -180,7 +180,7 @@ public static MethodInfo IsStartElementMethod0 { if (s_isStartElementMethod0 == null) { - s_isStartElementMethod0 = typeof(XmlReaderDelegator).GetMethod("IsStartElement", Globals.ScanAllMembers, null, Array.Empty(), null); + s_isStartElementMethod0 = typeof(XmlReaderDelegator).GetMethod("IsStartElement", Globals.ScanAllMembers, Array.Empty()); Debug.Assert(s_isStartElementMethod0 != null); } return s_isStartElementMethod0; @@ -192,7 +192,7 @@ public static MethodInfo IsStartElementMethod2 { if (s_isStartElementMethod2 == null) { - s_isStartElementMethod2 = typeof(XmlReaderDelegator).GetMethod("IsStartElement", Globals.ScanAllMembers, null, new Type[] { typeof(XmlDictionaryString), typeof(XmlDictionaryString) }, null); + s_isStartElementMethod2 = typeof(XmlReaderDelegator).GetMethod("IsStartElement", Globals.ScanAllMembers, new Type[] { typeof(XmlDictionaryString), typeof(XmlDictionaryString) }); Debug.Assert(s_isStartElementMethod2 != null); } return s_isStartElementMethod2; @@ -371,7 +371,7 @@ public static MethodInfo WriteAttributeStringMethod { if (s_writeAttributeStringMethod == null) { - s_writeAttributeStringMethod = typeof(XmlWriterDelegator).GetMethod("WriteAttributeString", Globals.ScanAllMembers, null, new Type[] { typeof(string), typeof(string), typeof(string), typeof(string) }, null); + s_writeAttributeStringMethod = typeof(XmlWriterDelegator).GetMethod("WriteAttributeString", Globals.ScanAllMembers, new Type[] { typeof(string), typeof(string), typeof(string), typeof(string) }); Debug.Assert(s_writeAttributeStringMethod != null); } return s_writeAttributeStringMethod; @@ -383,7 +383,7 @@ public static MethodInfo WriteEndElementMethod { if (s_writeEndElementMethod == null) { - s_writeEndElementMethod = typeof(XmlWriterDelegator).GetMethod("WriteEndElement", Globals.ScanAllMembers, null, Array.Empty(), null); + s_writeEndElementMethod = typeof(XmlWriterDelegator).GetMethod("WriteEndElement", Globals.ScanAllMembers, Array.Empty()); Debug.Assert(s_writeEndElementMethod != null); } return s_writeEndElementMethod; @@ -431,7 +431,7 @@ public static MethodInfo WriteStartElementMethod { if (s_writeStartElementMethod == null) { - s_writeStartElementMethod = typeof(XmlWriterDelegator).GetMethod("WriteStartElement", Globals.ScanAllMembers, null, new Type[] { typeof(XmlDictionaryString), typeof(XmlDictionaryString) }, null); + s_writeStartElementMethod = typeof(XmlWriterDelegator).GetMethod("WriteStartElement", Globals.ScanAllMembers, new Type[] { typeof(XmlDictionaryString), typeof(XmlDictionaryString) }); Debug.Assert(s_writeStartElementMethod != null); } return s_writeStartElementMethod; @@ -444,7 +444,7 @@ public static MethodInfo WriteStartElementStringMethod { if (s_writeStartElementStringMethod == null) { - s_writeStartElementStringMethod = typeof(XmlWriterDelegator).GetMethod("WriteStartElement", Globals.ScanAllMembers, null, new Type[] { typeof(string), typeof(string) }, null); + s_writeStartElementStringMethod = typeof(XmlWriterDelegator).GetMethod("WriteStartElement", Globals.ScanAllMembers, new Type[] { typeof(string), typeof(string) }); Debug.Assert(s_writeStartElementStringMethod != null); } return s_writeStartElementStringMethod; @@ -457,7 +457,7 @@ public static MethodInfo ParseEnumMethod { if (s_parseEnumMethod == null) { - s_parseEnumMethod = typeof(Enum).GetMethod("Parse", BindingFlags.Static | BindingFlags.Public, null, new Type[] { typeof(Type), typeof(string) }, null); + s_parseEnumMethod = typeof(Enum).GetMethod("Parse", BindingFlags.Static | BindingFlags.Public, new Type[] { typeof(Type), typeof(string) }); Debug.Assert(s_parseEnumMethod != null); } return s_parseEnumMethod; @@ -470,7 +470,7 @@ public static MethodInfo GetJsonMemberNameMethod { if (s_getJsonMemberNameMethod == null) { - s_getJsonMemberNameMethod = typeof(XmlObjectSerializerReadContextComplexJson).GetMethod("GetJsonMemberName", Globals.ScanAllMembers, null, new Type[] { typeof(XmlReaderDelegator) }, null); + s_getJsonMemberNameMethod = typeof(XmlObjectSerializerReadContextComplexJson).GetMethod("GetJsonMemberName", Globals.ScanAllMembers, new Type[] { typeof(XmlReaderDelegator) }); Debug.Assert(s_getJsonMemberNameMethod != null); } return s_getJsonMemberNameMethod; diff --git a/src/libraries/System.Private.DataContractSerialization/src/System/Runtime/Serialization/Json/JsonFormatReaderGenerator.cs b/src/libraries/System.Private.DataContractSerialization/src/System/Runtime/Serialization/Json/JsonFormatReaderGenerator.cs index 477ad9a7bb487..79bfe7bbf9a39 100644 --- a/src/libraries/System.Private.DataContractSerialization/src/System/Runtime/Serialization/Json/JsonFormatReaderGenerator.cs +++ b/src/libraries/System.Private.DataContractSerialization/src/System/Runtime/Serialization/Json/JsonFormatReaderGenerator.cs @@ -430,7 +430,7 @@ private void ResetExpectedElements(BitFlagsGenerator expectedElements, int index private void ReadISerializable(ClassDataContract classContract) { - ConstructorInfo? ctor = classContract.UnderlyingType.GetConstructor(Globals.ScanAllMembers, null, JsonFormatGeneratorStatics.SerInfoCtorArgs, null); + ConstructorInfo? ctor = classContract.UnderlyingType.GetConstructor(Globals.ScanAllMembers, JsonFormatGeneratorStatics.SerInfoCtorArgs); if (ctor == null) throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperError(XmlObjectSerializer.CreateSerializationException(SR.Format(SR.SerializationInfo_ConstructorNotFound, DataContract.GetClrTypeFullName(classContract.UnderlyingType)))); _ilg.LoadAddress(_objectLocal); @@ -573,11 +573,11 @@ private void ReadCollection(CollectionDataContract collectionContract) { case CollectionKind.GenericDictionary: type = Globals.TypeOfDictionaryGeneric.MakeGenericType(itemType.GetGenericArguments()); - constructor = type.GetConstructor(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic, null, Array.Empty(), null)!; + constructor = type.GetConstructor(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic, Array.Empty())!; break; case CollectionKind.Dictionary: type = Globals.TypeOfHashtable; - constructor = type.GetConstructor(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic, null, Array.Empty(), null)!; + constructor = type.GetConstructor(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic, Array.Empty())!; break; case CollectionKind.Collection: case CollectionKind.GenericCollection: diff --git a/src/libraries/System.Private.DataContractSerialization/src/System/Runtime/Serialization/Json/JsonFormatWriterGenerator.cs b/src/libraries/System.Private.DataContractSerialization/src/System/Runtime/Serialization/Json/JsonFormatWriterGenerator.cs index 68eaefbc45751..c219893b3d78a 100644 --- a/src/libraries/System.Private.DataContractSerialization/src/System/Runtime/Serialization/Json/JsonFormatWriterGenerator.cs +++ b/src/libraries/System.Private.DataContractSerialization/src/System/Runtime/Serialization/Json/JsonFormatWriterGenerator.cs @@ -346,8 +346,8 @@ private void WriteCollection(CollectionDataContract collectionContract) { enumeratorType = collectionContract.GetEnumeratorMethod.ReturnType; } - MethodInfo? moveNextMethod = enumeratorType.GetMethod(Globals.MoveNextMethodName, BindingFlags.Instance | BindingFlags.Public, null, Array.Empty(), null); - MethodInfo? getCurrentMethod = enumeratorType.GetMethod(Globals.GetCurrentMethodName, BindingFlags.Instance | BindingFlags.Public, null, Array.Empty(), null); + MethodInfo? moveNextMethod = enumeratorType.GetMethod(Globals.MoveNextMethodName, BindingFlags.Instance | BindingFlags.Public, Array.Empty()); + MethodInfo? getCurrentMethod = enumeratorType.GetMethod(Globals.GetCurrentMethodName, BindingFlags.Instance | BindingFlags.Public, Array.Empty()); if (moveNextMethod == null || getCurrentMethod == null) { if (enumeratorType.IsInterface) @@ -388,7 +388,7 @@ private void WriteCollection(CollectionDataContract collectionContract) _ilg.Call(_objectLocal, collectionContract.GetEnumeratorMethod); if (isDictionary) { - ConstructorInfo dictEnumCtor = enumeratorType.GetConstructor(Globals.ScanAllMembers, null, new Type[] { Globals.TypeOfIDictionaryEnumerator }, null)!; + ConstructorInfo dictEnumCtor = enumeratorType.GetConstructor(Globals.ScanAllMembers, new Type[] { Globals.TypeOfIDictionaryEnumerator })!; _ilg.ConvertValue(collectionContract.GetEnumeratorMethod.ReturnType, Globals.TypeOfIDictionaryEnumerator); _ilg.New(dictEnumCtor); } @@ -396,7 +396,7 @@ private void WriteCollection(CollectionDataContract collectionContract) { Debug.Assert(keyValueTypes != null); Type ctorParam = Globals.TypeOfIEnumeratorGeneric.MakeGenericType(Globals.TypeOfKeyValuePair.MakeGenericType(keyValueTypes)); - ConstructorInfo dictEnumCtor = enumeratorType.GetConstructor(Globals.ScanAllMembers, null, new Type[] { ctorParam }, null)!; + ConstructorInfo dictEnumCtor = enumeratorType.GetConstructor(Globals.ScanAllMembers, new Type[] { ctorParam })!; _ilg.ConvertValue(collectionContract.GetEnumeratorMethod.ReturnType, ctorParam); _ilg.New(dictEnumCtor); } @@ -560,9 +560,7 @@ private bool TryWritePrimitiveArray(Type type, Type itemType, LocalBuilder value MethodInfo writeArrayMethodInfo = typeof(JsonWriterDelegator).GetMethod( writeArrayMethod, Globals.ScanAllMembers, - null, - new Type[] { type, typeof(XmlDictionaryString), typeof(XmlDictionaryString) }, - null)!; + new Type[] { type, typeof(XmlDictionaryString), typeof(XmlDictionaryString) })!; _ilg.Call(_xmlWriterArg, writeArrayMethodInfo, value, itemName, null); return true; } diff --git a/src/libraries/System.Private.DataContractSerialization/src/System/Runtime/Serialization/PrimitiveDataContract.cs b/src/libraries/System.Private.DataContractSerialization/src/System/Runtime/Serialization/PrimitiveDataContract.cs index 8bc6d130f3596..c094c8d4fed4b 100644 --- a/src/libraries/System.Private.DataContractSerialization/src/System/Runtime/Serialization/PrimitiveDataContract.cs +++ b/src/libraries/System.Private.DataContractSerialization/src/System/Runtime/Serialization/PrimitiveDataContract.cs @@ -56,9 +56,9 @@ internal MethodInfo XmlFormatWriterMethod if (_helper.XmlFormatWriterMethod == null) { if (UnderlyingType.IsValueType) - _helper.XmlFormatWriterMethod = typeof(XmlWriterDelegator).GetMethod(WriteMethodName, Globals.ScanAllMembers, null, new Type[] { UnderlyingType, typeof(XmlDictionaryString), typeof(XmlDictionaryString) }, null)!; + _helper.XmlFormatWriterMethod = typeof(XmlWriterDelegator).GetMethod(WriteMethodName, Globals.ScanAllMembers, new Type[] { UnderlyingType, typeof(XmlDictionaryString), typeof(XmlDictionaryString) })!; else - _helper.XmlFormatWriterMethod = typeof(XmlObjectSerializerWriteContext).GetMethod(WriteMethodName, Globals.ScanAllMembers, null, new Type[] { typeof(XmlWriterDelegator), UnderlyingType, typeof(XmlDictionaryString), typeof(XmlDictionaryString) }, null)!; + _helper.XmlFormatWriterMethod = typeof(XmlObjectSerializerWriteContext).GetMethod(WriteMethodName, Globals.ScanAllMembers, new Type[] { typeof(XmlWriterDelegator), UnderlyingType, typeof(XmlDictionaryString), typeof(XmlDictionaryString) })!; } return _helper.XmlFormatWriterMethod; } @@ -71,9 +71,9 @@ internal MethodInfo XmlFormatContentWriterMethod if (_helper.XmlFormatContentWriterMethod == null) { if (UnderlyingType.IsValueType) - _helper.XmlFormatContentWriterMethod = typeof(XmlWriterDelegator).GetMethod(WriteMethodName, Globals.ScanAllMembers, null, new Type[] { UnderlyingType }, null)!; + _helper.XmlFormatContentWriterMethod = typeof(XmlWriterDelegator).GetMethod(WriteMethodName, Globals.ScanAllMembers, new Type[] { UnderlyingType })!; else - _helper.XmlFormatContentWriterMethod = typeof(XmlObjectSerializerWriteContext).GetMethod(WriteMethodName, Globals.ScanAllMembers, null, new Type[] { typeof(XmlWriterDelegator), UnderlyingType }, null)!; + _helper.XmlFormatContentWriterMethod = typeof(XmlObjectSerializerWriteContext).GetMethod(WriteMethodName, Globals.ScanAllMembers, new Type[] { typeof(XmlWriterDelegator), UnderlyingType })!; } return _helper.XmlFormatContentWriterMethod; } diff --git a/src/libraries/System.Private.DataContractSerialization/src/System/Runtime/Serialization/ReflectionReader.cs b/src/libraries/System.Private.DataContractSerialization/src/System/Runtime/Serialization/ReflectionReader.cs index 284d45dc8dae4..f1392a84328f5 100644 --- a/src/libraries/System.Private.DataContractSerialization/src/System/Runtime/Serialization/ReflectionReader.cs +++ b/src/libraries/System.Private.DataContractSerialization/src/System/Runtime/Serialization/ReflectionReader.cs @@ -441,7 +441,7 @@ private object ReflectionCreateCollection(CollectionDataContract collectionContr else if (collectionContract.Kind == CollectionKind.GenericDictionary && collectionContract.UnderlyingType.IsInterface) { Type type = Globals.TypeOfDictionaryGeneric.MakeGenericType(collectionContract.ItemType.GetGenericArguments()); - ConstructorInfo ci = type.GetConstructor(BindingFlags.Instance | BindingFlags.Public, null, Array.Empty(), null)!; + ConstructorInfo ci = type.GetConstructor(BindingFlags.Instance | BindingFlags.Public, Array.Empty())!; object newGenericDict = ci.Invoke(Array.Empty()); return newGenericDict; } diff --git a/src/libraries/System.Private.DataContractSerialization/src/System/Runtime/Serialization/SchemaExporter.cs b/src/libraries/System.Private.DataContractSerialization/src/System/Runtime/Serialization/SchemaExporter.cs index d372854bf1159..3e1b22ad958e1 100644 --- a/src/libraries/System.Private.DataContractSerialization/src/System/Runtime/Serialization/SchemaExporter.cs +++ b/src/libraries/System.Private.DataContractSerialization/src/System/Runtime/Serialization/SchemaExporter.cs @@ -603,7 +603,7 @@ private static bool InvokeSchemaProviderMethod(Type clrType, XmlSchemaSet schema } else { - MethodInfo? getMethod = clrType.GetMethod(methodName, /*BindingFlags.DeclaredOnly |*/ BindingFlags.Static | BindingFlags.NonPublic | BindingFlags.Public, null, new Type[] { typeof(XmlSchemaSet) }, null); + MethodInfo? getMethod = clrType.GetMethod(methodName, /*BindingFlags.DeclaredOnly |*/ BindingFlags.Static | BindingFlags.NonPublic | BindingFlags.Public, new Type[] { typeof(XmlSchemaSet) }); if (getMethod == null) throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidDataContractException(SR.Format(SR.MissingGetSchemaMethod, DataContract.GetClrTypeFullName(clrType), methodName))); diff --git a/src/libraries/System.Private.DataContractSerialization/src/System/Runtime/Serialization/XmlDataContract.cs b/src/libraries/System.Private.DataContractSerialization/src/System/Runtime/Serialization/XmlDataContract.cs index e7c1950ada538..703fa385cb57b 100644 --- a/src/libraries/System.Private.DataContractSerialization/src/System/Runtime/Serialization/XmlDataContract.cs +++ b/src/libraries/System.Private.DataContractSerialization/src/System/Runtime/Serialization/XmlDataContract.cs @@ -241,7 +241,7 @@ internal CreateXmlSerializableDelegate? CreateXmlSerializableDelegate if (type.IsValueType) return null; - ConstructorInfo? ctor = type.GetConstructor(BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public, null, Array.Empty(), null); + ConstructorInfo? ctor = type.GetConstructor(BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public, Array.Empty()); if (ctor == null) throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidDataContractException(SR.Format(SR.IXmlSerializableMustHaveDefaultConstructor, DataContract.GetClrTypeFullName(type)))); @@ -288,15 +288,11 @@ internal CreateXmlSerializableDelegate GenerateCreateXmlSerializableDelegate() MethodInfo? XName_op_Implicit = xName.GetMethod( "op_Implicit", BindingFlags.Static | BindingFlags.NonPublic | BindingFlags.Public, - null, - new Type[] { typeof(string) }, - null + new Type[] { typeof(string) } ); ConstructorInfo? XElement_ctor = type.GetConstructor( BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public, - null, - new Type[] { xName }, - null + new Type[] { xName } ); if (XName_op_Implicit != null && XElement_ctor != null) { diff --git a/src/libraries/System.Private.DataContractSerialization/src/System/Runtime/Serialization/XmlFormatGeneratorStatics.cs b/src/libraries/System.Private.DataContractSerialization/src/System/Runtime/Serialization/XmlFormatGeneratorStatics.cs index 3cbcba6288fec..4867266a5408b 100644 --- a/src/libraries/System.Private.DataContractSerialization/src/System/Runtime/Serialization/XmlFormatGeneratorStatics.cs +++ b/src/libraries/System.Private.DataContractSerialization/src/System/Runtime/Serialization/XmlFormatGeneratorStatics.cs @@ -17,7 +17,7 @@ internal static MethodInfo WriteStartElementMethod2 { if (s_writeStartElementMethod2 == null) { - s_writeStartElementMethod2 = typeof(XmlWriterDelegator).GetMethod("WriteStartElement", Globals.ScanAllMembers, null, new Type[] { typeof(XmlDictionaryString), typeof(XmlDictionaryString) }, null); + s_writeStartElementMethod2 = typeof(XmlWriterDelegator).GetMethod("WriteStartElement", Globals.ScanAllMembers, new Type[] { typeof(XmlDictionaryString), typeof(XmlDictionaryString) }); Debug.Assert(s_writeStartElementMethod2 != null); } return s_writeStartElementMethod2; @@ -31,7 +31,7 @@ internal static MethodInfo WriteStartElementMethod3 { if (s_writeStartElementMethod3 == null) { - s_writeStartElementMethod3 = typeof(XmlWriterDelegator).GetMethod("WriteStartElement", Globals.ScanAllMembers, null, new Type[] { typeof(string), typeof(XmlDictionaryString), typeof(XmlDictionaryString) }, null); + s_writeStartElementMethod3 = typeof(XmlWriterDelegator).GetMethod("WriteStartElement", Globals.ScanAllMembers, new Type[] { typeof(string), typeof(XmlDictionaryString), typeof(XmlDictionaryString) }); Debug.Assert(s_writeStartElementMethod3 != null); } return s_writeStartElementMethod3; @@ -45,7 +45,7 @@ internal static MethodInfo WriteEndElementMethod { if (s_writeEndElementMethod == null) { - s_writeEndElementMethod = typeof(XmlWriterDelegator).GetMethod("WriteEndElement", Globals.ScanAllMembers, null, Array.Empty(), null); + s_writeEndElementMethod = typeof(XmlWriterDelegator).GetMethod("WriteEndElement", Globals.ScanAllMembers, Array.Empty()); Debug.Assert(s_writeEndElementMethod != null); } return s_writeEndElementMethod; @@ -59,7 +59,7 @@ internal static MethodInfo WriteNamespaceDeclMethod { if (s_writeNamespaceDeclMethod == null) { - s_writeNamespaceDeclMethod = typeof(XmlWriterDelegator).GetMethod("WriteNamespaceDecl", Globals.ScanAllMembers, null, new Type[] { typeof(XmlDictionaryString) }, null); + s_writeNamespaceDeclMethod = typeof(XmlWriterDelegator).GetMethod("WriteNamespaceDecl", Globals.ScanAllMembers, new Type[] { typeof(XmlDictionaryString) }); Debug.Assert(s_writeNamespaceDeclMethod != null); } return s_writeNamespaceDeclMethod; @@ -77,7 +77,7 @@ internal static ConstructorInfo DictionaryEnumeratorCtor { if (s_dictionaryEnumeratorCtor == null) { - s_dictionaryEnumeratorCtor = typeof(CollectionDataContract.DictionaryEnumerator).GetConstructor(Globals.ScanAllMembers, null, new Type[] { Globals.TypeOfIDictionaryEnumerator }, null); + s_dictionaryEnumeratorCtor = typeof(CollectionDataContract.DictionaryEnumerator).GetConstructor(Globals.ScanAllMembers, new Type[] { Globals.TypeOfIDictionaryEnumerator }); Debug.Assert(s_dictionaryEnumeratorCtor != null); } return s_dictionaryEnumeratorCtor; @@ -133,7 +133,7 @@ internal static MethodInfo IsStartElementMethod2 { if (s_isStartElementMethod2 == null) { - s_isStartElementMethod2 = typeof(XmlReaderDelegator).GetMethod("IsStartElement", Globals.ScanAllMembers, null, new Type[] { typeof(XmlDictionaryString), typeof(XmlDictionaryString) }, null); + s_isStartElementMethod2 = typeof(XmlReaderDelegator).GetMethod("IsStartElement", Globals.ScanAllMembers, new Type[] { typeof(XmlDictionaryString), typeof(XmlDictionaryString) }); Debug.Assert(s_isStartElementMethod2 != null); } return s_isStartElementMethod2; @@ -147,7 +147,7 @@ internal static MethodInfo IsStartElementMethod0 { if (s_isStartElementMethod0 == null) { - s_isStartElementMethod0 = typeof(XmlReaderDelegator).GetMethod("IsStartElement", Globals.ScanAllMembers, null, Array.Empty(), null); + s_isStartElementMethod0 = typeof(XmlReaderDelegator).GetMethod("IsStartElement", Globals.ScanAllMembers, Array.Empty()); Debug.Assert(s_isStartElementMethod0 != null); } return s_isStartElementMethod0; @@ -161,7 +161,7 @@ internal static MethodInfo GetUninitializedObjectMethod { if (s_getUninitializedObjectMethod == null) { - s_getUninitializedObjectMethod = typeof(XmlFormatReaderGenerator).GetMethod("UnsafeGetUninitializedObject", Globals.ScanAllMembers, null, new Type[] { typeof(int) }, null); + s_getUninitializedObjectMethod = typeof(XmlFormatReaderGenerator).GetMethod("UnsafeGetUninitializedObject", Globals.ScanAllMembers, new Type[] { typeof(int) }); Debug.Assert(s_getUninitializedObjectMethod != null); } return s_getUninitializedObjectMethod; @@ -199,7 +199,7 @@ internal static PropertyInfo NodeTypeProperty private static ConstructorInfo? s_extensionDataObjectCtor; internal static ConstructorInfo ExtensionDataObjectCtor => s_extensionDataObjectCtor ?? (s_extensionDataObjectCtor = - typeof(ExtensionDataObject).GetConstructor(Globals.ScanAllMembers, null, Array.Empty(), null)!); + typeof(ExtensionDataObject).GetConstructor(Globals.ScanAllMembers, Array.Empty())!); private static ConstructorInfo? s_hashtableCtor; internal static ConstructorInfo HashtableCtor @@ -208,7 +208,7 @@ internal static ConstructorInfo HashtableCtor { if (s_hashtableCtor == null) { - s_hashtableCtor = Globals.TypeOfHashtable.GetConstructor(Globals.ScanAllMembers, null, Array.Empty(), null); + s_hashtableCtor = Globals.TypeOfHashtable.GetConstructor(Globals.ScanAllMembers, Array.Empty()); Debug.Assert(s_hashtableCtor != null); } return s_hashtableCtor; @@ -250,7 +250,7 @@ internal static MethodInfo StoreCollectionMemberInfoMethod { if (s_storeCollectionMemberInfoMethod == null) { - s_storeCollectionMemberInfoMethod = typeof(XmlObjectSerializerReadContext).GetMethod("StoreCollectionMemberInfo", Globals.ScanAllMembers, null, new Type[] { typeof(object) }, null); + s_storeCollectionMemberInfoMethod = typeof(XmlObjectSerializerReadContext).GetMethod("StoreCollectionMemberInfo", Globals.ScanAllMembers, new Type[] { typeof(object) }); Debug.Assert(s_storeCollectionMemberInfoMethod != null); } return s_storeCollectionMemberInfoMethod; @@ -264,7 +264,7 @@ internal static MethodInfo ResetCollectionMemberInfoMethod { if (s_resetCollectionMemberInfoMethod == null) { - s_resetCollectionMemberInfoMethod = typeof(XmlObjectSerializerReadContext).GetMethod("ResetCollectionMemberInfo", Globals.ScanAllMembers, null, Array.Empty(), null); + s_resetCollectionMemberInfoMethod = typeof(XmlObjectSerializerReadContext).GetMethod("ResetCollectionMemberInfo", Globals.ScanAllMembers, Array.Empty()); Debug.Assert(s_resetCollectionMemberInfoMethod != null); } return s_resetCollectionMemberInfoMethod; @@ -348,7 +348,7 @@ internal static MethodInfo InternalDeserializeMethod { if (s_internalDeserializeMethod == null) { - s_internalDeserializeMethod = typeof(XmlObjectSerializerReadContext).GetMethod("InternalDeserialize", Globals.ScanAllMembers, null, new Type[] { typeof(XmlReaderDelegator), typeof(int), typeof(RuntimeTypeHandle), typeof(string), typeof(string) }, null); + s_internalDeserializeMethod = typeof(XmlObjectSerializerReadContext).GetMethod("InternalDeserialize", Globals.ScanAllMembers, new Type[] { typeof(XmlReaderDelegator), typeof(int), typeof(RuntimeTypeHandle), typeof(string), typeof(string) }); Debug.Assert(s_internalDeserializeMethod != null); } return s_internalDeserializeMethod; @@ -432,7 +432,7 @@ internal static MethodInfo ReadIfNullOrRefMethod { if (s_readIfNullOrRefMethod == null) { - s_readIfNullOrRefMethod = typeof(XmlObjectSerializerReadContext).GetMethod("ReadIfNullOrRef", Globals.ScanAllMembers, null, new Type[] { typeof(XmlReaderDelegator), typeof(Type), typeof(bool) }, null); + s_readIfNullOrRefMethod = typeof(XmlObjectSerializerReadContext).GetMethod("ReadIfNullOrRef", Globals.ScanAllMembers, new Type[] { typeof(XmlReaderDelegator), typeof(Type), typeof(bool) }); Debug.Assert(s_readIfNullOrRefMethod != null); } return s_readIfNullOrRefMethod; @@ -614,7 +614,7 @@ internal static MethodInfo CreateSerializationExceptionMethod { if (s_createSerializationExceptionMethod == null) { - s_createSerializationExceptionMethod = typeof(XmlObjectSerializerReadContext).GetMethod("CreateSerializationException", Globals.ScanAllMembers, null, new Type[] { typeof(string) }, null); + s_createSerializationExceptionMethod = typeof(XmlObjectSerializerReadContext).GetMethod("CreateSerializationException", Globals.ScanAllMembers, new Type[] { typeof(string) }); Debug.Assert(s_createSerializationExceptionMethod != null); } return s_createSerializationExceptionMethod; @@ -642,7 +642,7 @@ internal static MethodInfo CreateUnexpectedStateExceptionMethod { if (s_createUnexpectedStateExceptionMethod == null) { - s_createUnexpectedStateExceptionMethod = typeof(XmlObjectSerializerReadContext).GetMethod("CreateUnexpectedStateException", Globals.ScanAllMembers, null, new Type[] { typeof(XmlNodeType), typeof(XmlReaderDelegator) }, null); + s_createUnexpectedStateExceptionMethod = typeof(XmlObjectSerializerReadContext).GetMethod("CreateUnexpectedStateException", Globals.ScanAllMembers, new Type[] { typeof(XmlNodeType), typeof(XmlReaderDelegator) }); Debug.Assert(s_createUnexpectedStateExceptionMethod != null); } return s_createUnexpectedStateExceptionMethod; @@ -684,7 +684,7 @@ internal static MethodInfo WriteNullMethod { if (s_writeNullMethod == null) { - s_writeNullMethod = typeof(XmlObjectSerializerWriteContext).GetMethod("WriteNull", Globals.ScanAllMembers, null, new Type[] { typeof(XmlWriterDelegator), typeof(Type), typeof(bool) }, null); + s_writeNullMethod = typeof(XmlObjectSerializerWriteContext).GetMethod("WriteNull", Globals.ScanAllMembers, new Type[] { typeof(XmlWriterDelegator), typeof(Type), typeof(bool) }); Debug.Assert(s_writeNullMethod != null); } return s_writeNullMethod; @@ -712,7 +712,7 @@ internal static MethodInfo IncrementCollectionCountMethod { if (s_incrementCollectionCountMethod == null) { - s_incrementCollectionCountMethod = typeof(XmlObjectSerializerWriteContext).GetMethod("IncrementCollectionCount", Globals.ScanAllMembers, null, new Type[] { typeof(XmlWriterDelegator), typeof(ICollection) }, null); + s_incrementCollectionCountMethod = typeof(XmlObjectSerializerWriteContext).GetMethod("IncrementCollectionCount", Globals.ScanAllMembers, new Type[] { typeof(XmlWriterDelegator), typeof(ICollection) }); Debug.Assert(s_incrementCollectionCountMethod != null); } return s_incrementCollectionCountMethod; @@ -816,7 +816,7 @@ internal static MethodInfo IsMemberTypeSameAsMemberValue { if (s_isMemberTypeSameAsMemberValue == null) { - s_isMemberTypeSameAsMemberValue = typeof(XmlObjectSerializerWriteContext).GetMethod("IsMemberTypeSameAsMemberValue", Globals.ScanAllMembers, null, new Type[] { typeof(object), typeof(Type) }, null); + s_isMemberTypeSameAsMemberValue = typeof(XmlObjectSerializerWriteContext).GetMethod("IsMemberTypeSameAsMemberValue", Globals.ScanAllMembers, new Type[] { typeof(object), typeof(Type) }); Debug.Assert(s_isMemberTypeSameAsMemberValue != null); } return s_isMemberTypeSameAsMemberValue; @@ -1006,7 +1006,7 @@ internal static MethodInfo ThrowInvalidDataContractExceptionMethod { if (s_throwInvalidDataContractExceptionMethod == null) { - s_throwInvalidDataContractExceptionMethod = typeof(DataContract).GetMethod("ThrowInvalidDataContractException", Globals.ScanAllMembers, null, new Type[] { typeof(string), typeof(Type) }, null); + s_throwInvalidDataContractExceptionMethod = typeof(DataContract).GetMethod("ThrowInvalidDataContractException", Globals.ScanAllMembers, new Type[] { typeof(string), typeof(Type) }); Debug.Assert(s_throwInvalidDataContractExceptionMethod != null); } return s_throwInvalidDataContractExceptionMethod; diff --git a/src/libraries/System.Private.DataContractSerialization/src/System/Runtime/Serialization/XmlFormatReaderGenerator.cs b/src/libraries/System.Private.DataContractSerialization/src/System/Runtime/Serialization/XmlFormatReaderGenerator.cs index 4e5ea78c3e34d..095cd8278ce7d 100644 --- a/src/libraries/System.Private.DataContractSerialization/src/System/Runtime/Serialization/XmlFormatReaderGenerator.cs +++ b/src/libraries/System.Private.DataContractSerialization/src/System/Runtime/Serialization/XmlFormatReaderGenerator.cs @@ -596,7 +596,7 @@ private void ReadCollection(CollectionDataContract collectionContract) { case CollectionKind.GenericDictionary: type = Globals.TypeOfDictionaryGeneric.MakeGenericType(itemType.GetGenericArguments()); - constructor = type.GetConstructor(BindingFlags.Instance | BindingFlags.Public, null, Array.Empty(), null)!; + constructor = type.GetConstructor(BindingFlags.Instance | BindingFlags.Public, Array.Empty())!; break; case CollectionKind.Dictionary: type = Globals.TypeOfHashtable; diff --git a/src/libraries/System.Private.DataContractSerialization/src/System/Runtime/Serialization/XmlFormatWriterGenerator.cs b/src/libraries/System.Private.DataContractSerialization/src/System/Runtime/Serialization/XmlFormatWriterGenerator.cs index aa69ceb8e72e8..ee7dbdba7a059 100644 --- a/src/libraries/System.Private.DataContractSerialization/src/System/Runtime/Serialization/XmlFormatWriterGenerator.cs +++ b/src/libraries/System.Private.DataContractSerialization/src/System/Runtime/Serialization/XmlFormatWriterGenerator.cs @@ -409,8 +409,8 @@ private void WriteCollection(CollectionDataContract collectionContract) { enumeratorType = collectionContract.GetEnumeratorMethod.ReturnType; } - MethodInfo? moveNextMethod = enumeratorType.GetMethod(Globals.MoveNextMethodName, BindingFlags.Instance | BindingFlags.Public, null, Array.Empty(), null); - MethodInfo? getCurrentMethod = enumeratorType.GetMethod(Globals.GetCurrentMethodName, BindingFlags.Instance | BindingFlags.Public, null, Array.Empty(), null); + MethodInfo? moveNextMethod = enumeratorType.GetMethod(Globals.MoveNextMethodName, BindingFlags.Instance | BindingFlags.Public, Array.Empty()); + MethodInfo? getCurrentMethod = enumeratorType.GetMethod(Globals.GetCurrentMethodName, BindingFlags.Instance | BindingFlags.Public, Array.Empty()); if (moveNextMethod == null || getCurrentMethod == null) { if (enumeratorType.IsInterface) @@ -457,7 +457,7 @@ private void WriteCollection(CollectionDataContract collectionContract) else if (isGenericDictionary) { Type ctorParam = Globals.TypeOfIEnumeratorGeneric.MakeGenericType(Globals.TypeOfKeyValuePair.MakeGenericType(keyValueTypes!)); - ConstructorInfo dictEnumCtor = enumeratorType.GetConstructor(Globals.ScanAllMembers, null, new Type[] { ctorParam }, null)!; + ConstructorInfo dictEnumCtor = enumeratorType.GetConstructor(Globals.ScanAllMembers, new Type[] { ctorParam })!; _ilg.ConvertValue(collectionContract.GetEnumeratorMethod.ReturnType, ctorParam); _ilg.New(dictEnumCtor); } @@ -576,7 +576,7 @@ private bool TryWritePrimitiveArray(Type type, Type itemType, LocalBuilder value _ilg.Load(value); _ilg.Load(itemName); _ilg.Load(itemNamespace); - _ilg.Call(typeof(XmlWriterDelegator).GetMethod(writeArrayMethod, Globals.ScanAllMembers, null, new Type[] { type, typeof(XmlDictionaryString), typeof(XmlDictionaryString) }, null)!); + _ilg.Call(typeof(XmlWriterDelegator).GetMethod(writeArrayMethod, Globals.ScanAllMembers, new Type[] { type, typeof(XmlDictionaryString), typeof(XmlDictionaryString) })!); return true; } return false; diff --git a/src/libraries/System.Private.Xml/src/ILLink/ILLink.Suppressions.xml b/src/libraries/System.Private.Xml/src/ILLink/ILLink.Suppressions.xml index 2feabe05d6d39..95df6776ce7ab 100644 --- a/src/libraries/System.Private.Xml/src/ILLink/ILLink.Suppressions.xml +++ b/src/libraries/System.Private.Xml/src/ILLink/ILLink.Suppressions.xml @@ -53,37 +53,37 @@ ILLink IL2070 member - M:System.Xml.Extensions.ExtensionMethods.GetConstructor(System.Type,System.Reflection.BindingFlags,System.Type[]) + M:System.Xml.Serialization.ReflectionAwareILGen.ILGenForCreateInstance(System.Xml.Serialization.CodeGenerator,System.Type,System.Boolean,System.Boolean) ILLink IL2070 member - M:System.Xml.Extensions.ExtensionMethods.GetMethod(System.Type,System.String,System.Reflection.BindingFlags,System.Type[]) + M:System.Xml.Serialization.ReflectionAwareILGen.ILGenForCreateInstance(System.Xml.Serialization.CodeGenerator,System.Type,System.Type,System.Boolean) ILLink IL2070 member - M:System.Xml.Serialization.ReflectionAwareILGen.ILGenForCreateInstance(System.Xml.Serialization.CodeGenerator,System.Type,System.Type,System.Boolean) + M:System.Xml.Serialization.ReflectionXmlSerializationHelper.GetMember(System.Type,System.String) ILLink IL2070 member - M:System.Xml.Serialization.ReflectionXmlSerializationHelper.GetMember(System.Type,System.String) + M:System.Xml.Serialization.ReflectionXmlSerializationReader.AddObjectsIntoTargetCollection(System.Object,System.Collections.Generic.List{System.Object},System.Type) ILLink IL2070 member - M:System.Xml.Serialization.ReflectionXmlSerializationReader.AddObjectsIntoTargetCollection(System.Object,System.Collections.Generic.List{System.Object},System.Type) + M:System.Xml.Serialization.ReflectionXmlSerializationReader.GetDefaultConstructor(System.Type) ILLink IL2070 member - M:System.Xml.Serialization.ReflectionXmlSerializationReader.GetDefaultConstructor(System.Type) + M:System.Xml.Serialization.SourceInfo.ConvertNullableValue(System.Type,System.Type) ILLink @@ -97,6 +97,12 @@ member M:System.Xml.Serialization.TypeExtensions.TryConvertTo(System.Type,System.Object,System.Object@) + + ILLink + IL2070 + member + M:System.Xml.Serialization.TypeScope.GetConstructorFlags(System.Type,System.Exception@) + ILLink IL2070 @@ -119,7 +125,7 @@ ILLink IL2070 member - M:System.Xml.Xsl.IlGen.XmlILConstructors.GetConstructor(System.Type) + M:System.Xml.Serialization.XmlReflectionImporter.GetMethodFromSchemaProvider(System.Xml.Serialization.XmlSchemaProviderAttribute,System.Type) ILLink @@ -131,7 +137,7 @@ ILLink IL2070 member - M:System.Xml.Xsl.IlGen.XmlILMethods.GetMethod(System.Type,System.String) + M:System.Xml.Xsl.IlGen.XmlILConstructors.GetConstructor(System.Type) ILLink @@ -143,13 +149,13 @@ ILLink IL2070 member - M:System.Xml.Xsl.Runtime.EarlyBoundInfo.#ctor(System.String,System.Type) + M:System.Xml.Xsl.IlGen.XmlILMethods.GetMethod(System.Type,System.String) ILLink IL2070 member - M:System.Xml.Xsl.Runtime.XsltMethods.GetMethod(System.Type,System.String) + M:System.Xml.Xsl.Runtime.EarlyBoundInfo.#ctor(System.String,System.Type) ILLink @@ -157,6 +163,12 @@ member M:System.Xml.Xsl.Runtime.XsltMethods.GetMethod(System.Type,System.String,System.Type[]) + + ILLink + IL2070 + member + M:System.Xml.Xsl.Runtime.XsltMethods.GetMethod(System.Type,System.String) + ILLink IL2070 @@ -205,6 +217,12 @@ member M:System.Xml.Serialization.FieldModel.#ctor(System.Reflection.MemberInfo,System.Type,System.Xml.Serialization.TypeDesc) + + ILLink + IL2075 + member + M:System.Xml.Serialization.ReflectionAwareILGen.ILGenForCreateInstance(System.Xml.Serialization.CodeGenerator,System.Type,System.Type,System.Boolean) + ILLink IL2075 @@ -235,6 +253,12 @@ member T:System.Xml.Serialization.ReflectionXmlSerializationReader + + ILLink + IL2075 + member + M:System.Xml.Serialization.SourceInfo.InternalLoad(System.Type,System.Boolean) + ILLink IL2075 @@ -253,6 +277,42 @@ member M:System.Xml.Serialization.XmlReflectionImporter.GetChoiceIdentifierType(System.Xml.Serialization.XmlChoiceIdentifierAttribute,System.Xml.Serialization.StructModel,System.Boolean,System.String) + + ILLink + IL2075 + member + M:System.Xml.Serialization.XmlSerializationILGen.GenerateBaseSerializer(System.String,System.String,System.String,System.Xml.Serialization.CodeIdentifiers) + + + ILLink + IL2075 + member + M:System.Xml.Serialization.XmlSerializationILGen.GenerateGetSerializer(System.Collections.Generic.Dictionary{System.String,System.String},System.Xml.Serialization.XmlMapping[],System.Reflection.Emit.TypeBuilder) + + + ILLink + IL2075 + member + M:System.Xml.Serialization.XmlSerializationILGen.GenerateSerializerContract(System.String,System.Xml.Serialization.XmlMapping[],System.Type[],System.String,System.String[],System.String,System.String[],System.Collections.Generic.Dictionary{System.String,System.String}) + + + ILLink + IL2075 + member + M:System.Xml.Serialization.XmlSerializationILGen.GenerateTypedSerializer(System.String,System.String,System.Xml.Serialization.XmlMapping,System.Xml.Serialization.CodeIdentifiers,System.String,System.String,System.String) + + + ILLink + IL2075 + member + M:System.Xml.Serialization.XmlSerializationILGen.GenerateTypedSerializers(System.Collections.Generic.Dictionary{System.String,System.String},System.Reflection.Emit.TypeBuilder) + + + ILLink + IL2075 + member + M:System.Xml.Serialization.XmlSerializationReaderILGen.WriteAttributes(System.Xml.Serialization.XmlSerializationReaderILGen.Member[],System.Xml.Serialization.XmlSerializationReaderILGen.Member,System.String,System.Reflection.Emit.LocalBuilder) + ILLink IL2075 @@ -265,6 +325,18 @@ member M:System.Xml.Serialization.XmlSerializationWriterILGen.WriteArrayItems(System.Xml.Serialization.ElementAccessor[],System.Xml.Serialization.TextAccessor,System.Xml.Serialization.ChoiceIdentifierAccessor,System.Xml.Serialization.TypeDesc,System.String,System.String) + + ILLink + IL2075 + member + M:System.Xml.Serialization.XmlSerializationWriterILGen.WriteCheckDefault(System.Xml.Serialization.SourceInfo,System.Object,System.Boolean) + + + ILLink + IL2075 + member + M:System.Xml.Serialization.XmlSerializationWriterILGen.WriteElement(System.Xml.Serialization.SourceInfo,System.Xml.Serialization.ElementAccessor,System.String,System.Boolean) + ILLink IL2075 @@ -289,6 +361,12 @@ member M:System.Xml.Serialization.SerializableMapping.RetrieveSerializableSchema + + ILLink + IL2080 + member + M:System.Xml.Serialization.XmlSerializationWriterILGen.WriteText(System.Xml.Serialization.SourceInfo,System.Xml.Serialization.TextAccessor) + ILLink IL2080 diff --git a/src/libraries/System.Private.Xml/src/System/Xml/Extensions/ExtensionMethods.cs b/src/libraries/System.Private.Xml/src/System/Xml/Extensions/ExtensionMethods.cs index d91034169fea6..f2d955a6ef19c 100644 --- a/src/libraries/System.Private.Xml/src/System/Xml/Extensions/ExtensionMethods.cs +++ b/src/libraries/System.Private.Xml/src/System/Xml/Extensions/ExtensionMethods.cs @@ -8,20 +8,6 @@ namespace System.Xml.Extensions { internal static class ExtensionMethods { - #region Contract compliance for System.Type - - internal static ConstructorInfo? GetConstructor(this Type type, BindingFlags bindingFlags, Type[] parameterTypes) - { - return type.GetConstructor(bindingFlags, null, parameterTypes, null); - } - - internal static MethodInfo? GetMethod(this Type type, string methodName, BindingFlags bindingFlags, Type[] parameterTypes) - { - return type.GetMethod(methodName, bindingFlags, null, parameterTypes, null); - } - - #endregion - internal static Uri ToUri(string s) { if (s != null && s.Length > 0) diff --git a/src/libraries/System.Runtime/ref/System.Runtime.cs b/src/libraries/System.Runtime/ref/System.Runtime.cs index c954f9be6226d..6b7c12d25923e 100644 --- a/src/libraries/System.Runtime/ref/System.Runtime.cs +++ b/src/libraries/System.Runtime/ref/System.Runtime.cs @@ -4202,6 +4202,8 @@ protected Type() { } public virtual int GetArrayRank() { throw null; } protected abstract System.Reflection.TypeAttributes GetAttributeFlagsImpl(); [System.Diagnostics.CodeAnalysis.DynamicallyAccessedMembersAttribute(System.Diagnostics.CodeAnalysis.DynamicallyAccessedMemberTypes.NonPublicConstructors | System.Diagnostics.CodeAnalysis.DynamicallyAccessedMemberTypes.PublicConstructors)] + public System.Reflection.ConstructorInfo? GetConstructor(System.Reflection.BindingFlags bindingAttr, System.Type[] types) { throw null; } + [System.Diagnostics.CodeAnalysis.DynamicallyAccessedMembersAttribute(System.Diagnostics.CodeAnalysis.DynamicallyAccessedMemberTypes.NonPublicConstructors | System.Diagnostics.CodeAnalysis.DynamicallyAccessedMemberTypes.PublicConstructors)] public System.Reflection.ConstructorInfo? GetConstructor(System.Reflection.BindingFlags bindingAttr, System.Reflection.Binder? binder, System.Reflection.CallingConventions callConvention, System.Type[] types, System.Reflection.ParameterModifier[]? modifiers) { throw null; } [System.Diagnostics.CodeAnalysis.DynamicallyAccessedMembersAttribute(System.Diagnostics.CodeAnalysis.DynamicallyAccessedMemberTypes.NonPublicConstructors | System.Diagnostics.CodeAnalysis.DynamicallyAccessedMemberTypes.PublicConstructors)] public System.Reflection.ConstructorInfo? GetConstructor(System.Reflection.BindingFlags bindingAttr, System.Reflection.Binder? binder, System.Type[] types, System.Reflection.ParameterModifier[]? modifiers) { throw null; } @@ -4267,6 +4269,8 @@ protected Type() { } [System.Diagnostics.CodeAnalysis.DynamicallyAccessedMembersAttribute(System.Diagnostics.CodeAnalysis.DynamicallyAccessedMemberTypes.NonPublicMethods | System.Diagnostics.CodeAnalysis.DynamicallyAccessedMemberTypes.PublicMethods)] public System.Reflection.MethodInfo? GetMethod(string name, System.Reflection.BindingFlags bindingAttr) { throw null; } [System.Diagnostics.CodeAnalysis.DynamicallyAccessedMembersAttribute(System.Diagnostics.CodeAnalysis.DynamicallyAccessedMemberTypes.NonPublicMethods | System.Diagnostics.CodeAnalysis.DynamicallyAccessedMemberTypes.PublicMethods)] + public System.Reflection.MethodInfo? GetMethod(string name, System.Reflection.BindingFlags bindingAttr, System.Type[] types) { throw null; } + [System.Diagnostics.CodeAnalysis.DynamicallyAccessedMembersAttribute(System.Diagnostics.CodeAnalysis.DynamicallyAccessedMemberTypes.NonPublicMethods | System.Diagnostics.CodeAnalysis.DynamicallyAccessedMemberTypes.PublicMethods)] public System.Reflection.MethodInfo? GetMethod(string name, System.Reflection.BindingFlags bindingAttr, System.Reflection.Binder? binder, System.Reflection.CallingConventions callConvention, System.Type[] types, System.Reflection.ParameterModifier[]? modifiers) { throw null; } [System.Diagnostics.CodeAnalysis.DynamicallyAccessedMembersAttribute(System.Diagnostics.CodeAnalysis.DynamicallyAccessedMemberTypes.NonPublicMethods | System.Diagnostics.CodeAnalysis.DynamicallyAccessedMemberTypes.PublicMethods)] public System.Reflection.MethodInfo? GetMethod(string name, System.Reflection.BindingFlags bindingAttr, System.Reflection.Binder? binder, System.Type[] types, System.Reflection.ParameterModifier[]? modifiers) { throw null; } diff --git a/src/libraries/System.Runtime/tests/System/Reflection/BindingFlagsDoNotWrap.cs b/src/libraries/System.Runtime/tests/System/Reflection/BindingFlagsDoNotWrap.cs index b7d940b422f2f..ecd025108299a 100644 --- a/src/libraries/System.Runtime/tests/System/Reflection/BindingFlagsDoNotWrap.cs +++ b/src/libraries/System.Runtime/tests/System/Reflection/BindingFlagsDoNotWrap.cs @@ -24,6 +24,13 @@ public static void ConstructorInvoke() TestDoNotWrap((bf) => c.Invoke(bf, null, Array.Empty(), null)); } + [Fact] + public static void ConstructorInvokeTwoArgs() + { + ConstructorInfo c = typeof(TestClass).GetConstructor(BindingFlags.Public | BindingFlags.Instance, Array.Empty()); + TestDoNotWrap((bf) => c.Invoke(bf, null, Array.Empty(), null)); + } + [Fact] public static void ConstructorInvokeStringCtor() { @@ -32,6 +39,13 @@ public static void ConstructorInvokeStringCtor() TestDoNotWrap((bf) => c.Invoke(bf, null, new object[] { null, 0, 0 }, null)); } + [Fact] + public static void ConstructorInvokeStringCtorTwoArgs() + { + ConstructorInfo c = typeof(string).GetConstructor(BindingFlags.Public | BindingFlags.Instance, new Type[] { typeof(char[]), typeof(int), typeof(int) }); + TestDoNotWrap((bf) => c.Invoke(bf, null, new object[] { null, 0, 0 }, null)); + } + [Fact] public static void ConstructorInvokeUsingMethodInfoInvoke() { diff --git a/src/libraries/System.Runtime/tests/System/Reflection/SignatureTypes.cs b/src/libraries/System.Runtime/tests/System/Reflection/SignatureTypes.cs index fd9a1d862c464..f631cd6f1e319 100644 --- a/src/libraries/System.Runtime/tests/System/Reflection/SignatureTypes.cs +++ b/src/libraries/System.Runtime/tests/System/Reflection/SignatureTypes.cs @@ -129,6 +129,19 @@ public static void GetMethodOverloadTest(bool exactBinding) AssertIsMarked(moo, 3); } + [Fact] + public static void GetMethodBindingFlagsAndArgs() + { + Type t = typeof(SignatureTypeTests); + const BindingFlags bf = BindingFlags.Public | BindingFlags.Static | BindingFlags.DeclaredOnly; + MethodInfo testMethod = t.GetMethod(nameof(GetMethodBindingFlagsAndArgs), bf, Type.EmptyTypes); + Assert.NotNull(testMethod); + + t = typeof(TestClass1); + Type[] args = { typeof(int) }; + Assert.Throws(() => t.GetMethod("Moo", bf, args)); + } + [Theory] [InlineData(true)] [InlineData(false)]