Skip to content
This repository has been archived by the owner on Jan 23, 2023. It is now read-only.
/ corefx Public archive

Commit

Permalink
Merge pull request #16406 from JonHanna/typeinfo_typeconverter
Browse files Browse the repository at this point in the history
Remove calls to GetTypeInfo from System.ComponentModel.TypeConverter
  • Loading branch information
stephentoub authored Feb 23, 2017
2 parents f92ecba + 2825b1e commit bda8d3f
Show file tree
Hide file tree
Showing 14 changed files with 83 additions and 85 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -205,8 +205,7 @@ public virtual Attribute this[Type attributeType]
for (int i = 0; i < count; i++)
{
Attribute attribute = Attributes[i];
Type aType = attribute.GetType();
if (attributeType.GetTypeInfo().IsAssignableFrom(aType.GetTypeInfo()))
if (attributeType.IsInstanceOfType(attribute))
{
_foundAttributeTypes[ind].index = i;
return attribute;
Expand Down Expand Up @@ -274,15 +273,15 @@ protected Attribute GetDefaultAttribute(Type attributeType)

// Not in the table, so do the legwork to discover the default value.
Type reflect = TypeDescriptor.GetReflectionType(attributeType);
FieldInfo field = reflect.GetTypeInfo().GetField("Default", BindingFlags.Public | BindingFlags.Static | BindingFlags.GetField);
FieldInfo field = reflect.GetField("Default", BindingFlags.Public | BindingFlags.Static | BindingFlags.GetField);

if (field != null && field.IsStatic)
{
attr = (Attribute)field.GetValue(null);
}
else
{
ConstructorInfo ci = reflect.GetTypeInfo().UnderlyingSystemType.GetTypeInfo().GetConstructor(Array.Empty<Type>());
ConstructorInfo ci = reflect.UnderlyingSystemType.GetConstructor(Array.Empty<Type>());
if (ci != null)
{
attr = (Attribute)ci.Invoke(Array.Empty<object>());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ public override object ConvertTo(ITypeDescriptorContext context, CultureInfo cul
throw new ArgumentNullException(nameof(destinationType));
}

if (destinationType == typeof(string) && value != null && TargetType.GetTypeInfo().IsAssignableFrom(value.GetType().GetTypeInfo()))
if (destinationType == typeof(string) && value != null && TargetType.IsInstanceOfType(value))
{
if (culture == null)
{
Expand All @@ -121,7 +121,7 @@ public override object ConvertTo(ITypeDescriptorContext context, CultureInfo cul
return ToString(value, formatInfo);
}

if (destinationType.GetTypeInfo().IsPrimitive)
if (destinationType.IsPrimitive)
{
return Convert.ChangeType(value, destinationType, culture);
}
Expand All @@ -130,7 +130,7 @@ public override object ConvertTo(ITypeDescriptorContext context, CultureInfo cul

public override bool CanConvertTo(ITypeDescriptorContext context, Type destinationType)
{
return base.CanConvertTo(context, destinationType) || destinationType.GetTypeInfo().IsPrimitive;
return base.CanConvertTo(context, destinationType) || destinationType.IsPrimitive;
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ public virtual void AddService(Type serviceType, object serviceInstance, bool pr
//
if (serviceType == null) throw new ArgumentNullException(nameof(serviceType));
if (serviceInstance == null) throw new ArgumentNullException(nameof(serviceInstance));
if (!(serviceInstance is ServiceCreatorCallback) && !serviceInstance.GetType().IsCOMObject && !serviceType.IsAssignableFrom(serviceInstance.GetType()))
if (!(serviceInstance is ServiceCreatorCallback) && !serviceInstance.GetType().IsCOMObject && !serviceType.IsInstanceOfType(serviceInstance))
{
throw new ArgumentException(SR.Format(SR.ErrorInvalidServiceInstance, serviceType.FullName));
}
Expand Down Expand Up @@ -215,7 +215,7 @@ public virtual object GetService(Type serviceType)
Debug.WriteLineIf(s_TRACESERVICE.TraceVerbose, "Encountered a callback. Invoking it");
service = ((ServiceCreatorCallback)service)(this, serviceType);
Debug.WriteLineIf(s_TRACESERVICE.TraceVerbose, $"Callback return object: {(service == null ? "(null)" : service.ToString())}");
if (service != null && !service.GetType().IsCOMObject && !serviceType.IsAssignableFrom(service.GetType()))
if (service != null && !service.GetType().IsCOMObject && !serviceType.IsInstanceOfType(service))
{
// Callback passed us a bad service. NULL it, rather than throwing an exception.
// Callers here do not need to be prepared to handle bad callback implemetations.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ public override object ConvertTo(ITypeDescriptorContext context, CultureInfo cul
// Raise an argument exception if the value isn't defined and if
// the enum isn't a flags style.
//
if (!EnumType.GetTypeInfo().IsDefined(typeof(FlagsAttribute), false) && !Enum.IsDefined(EnumType, value))
if (!EnumType.IsDefined(typeof(FlagsAttribute), false) && !Enum.IsDefined(EnumType, value))
{
throw new ArgumentException(SR.Format(SR.EnumConverterInvalidValue, value.ToString(), EnumType.Name));
}
Expand All @@ -163,7 +163,7 @@ public override object ConvertTo(ITypeDescriptorContext context, CultureInfo cul

if (destinationType == typeof(Enum[]) && value != null)
{
if (EnumType.GetTypeInfo().IsDefined(typeof(FlagsAttribute), false))
if (EnumType.IsDefined(typeof(FlagsAttribute), false))
{
List<Enum> flagValues = new List<Enum>();

Expand Down Expand Up @@ -289,7 +289,7 @@ public override StandardValuesCollection GetStandardValues(ITypeDescriptorContex
/// </summary>
public override bool GetStandardValuesExclusive(ITypeDescriptorContext context)
{
return !EnumType.GetTypeInfo().IsDefined(typeof(FlagsAttribute), false);
return !EnumType.IsDefined(typeof(FlagsAttribute), false);
}

/// <internalonly/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -424,16 +424,16 @@ protected static MethodInfo FindMethod(Type componentClass, string name, Type[]

if (publicOnly)
{
result = componentClass.GetTypeInfo().GetMethod(name, args);
result = componentClass.GetMethod(name, args);
}
else
{
// The original impementation requires the method https://msdn.microsoft.com/en-us/library/5fed8f59(v=vs.110).aspx which is not
// available on .NET Core. The replacement will use the default BindingFlags, which may miss some methods that had been found
// on .NET Framework.
result = componentClass.GetTypeInfo().GetMethod(name, BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic, null, args, null);
result = componentClass.GetMethod(name, BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic, null, args, null);
}
if (result != null && !result.ReturnType.GetTypeInfo().IsEquivalentTo(returnType))
if (result != null && !result.ReturnType.IsEquivalentTo(returnType))
{
result = null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ public override object ConvertTo(ITypeDescriptorContext context, System.Globaliz
throw new ArgumentNullException(nameof(destinationType));
}

if (destinationType == UnderlyingType && value != null && NullableType.GetTypeInfo().IsAssignableFrom(value.GetType().GetTypeInfo()))
if (destinationType == UnderlyingType && value != null && NullableType.IsInstanceOfType(value))
{
return value;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ public virtual TypeConverter Converter
if (attr.ConverterTypeName != null && attr.ConverterTypeName.Length > 0)
{
Type converterType = GetTypeFromName(attr.ConverterTypeName);
if (converterType != null && typeof(TypeConverter).GetTypeInfo().IsAssignableFrom(converterType))
if (converterType != null && typeof(TypeConverter).IsAssignableFrom(converterType))
{
_converter = (TypeConverter)CreateInstance(converterType);
}
Expand Down Expand Up @@ -210,7 +210,7 @@ public override bool Equals(object obj)
protected object CreateInstance(Type type)
{
Type[] typeArgs = new Type[] { typeof(Type) };
ConstructorInfo ctor = type.GetTypeInfo().GetConstructor(typeArgs);
ConstructorInfo ctor = type.GetConstructor(typeArgs);
if (ctor != null)
{
return TypeDescriptor.CreateInstance(null, type, typeArgs, new object[] { PropertyType });
Expand Down Expand Up @@ -408,14 +408,14 @@ protected Type GetTypeFromName(string typeName)
if (ComponentType != null)
{
if ((typeFromGetType == null) ||
(ComponentType.GetTypeInfo().Assembly.FullName.Equals(typeFromGetType.GetTypeInfo().Assembly.FullName)))
(ComponentType.Assembly.FullName.Equals(typeFromGetType.Assembly.FullName)))
{
int comma = typeName.IndexOf(',');

if (comma != -1)
typeName = typeName.Substring(0, comma);

typeFromComponent = ComponentType.GetTypeInfo().Assembly.GetType(typeName);
typeFromComponent = ComponentType.Assembly.GetType(typeName);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public ReflectEventDescriptor(Type componentClass, string name, Type type, Attri
{
throw new ArgumentException(SR.Format(SR.ErrorInvalidEventType, name));
}
Debug.Assert(type.GetTypeInfo().IsSubclassOf(typeof(Delegate)), $"Not a valid ReflectEvent: {componentClass.FullName}. {name} {type.FullName}");
Debug.Assert(type.IsSubclassOf(typeof(Delegate)), $"Not a valid ReflectEvent: {componentClass.FullName}. {name} {type.FullName}");
_componentClass = componentClass;
_type = type;
}
Expand Down Expand Up @@ -261,7 +261,7 @@ private void FillEventInfoAttribute(EventInfo realEventInfo, IList attributes)
while (currentReflectType != typeof(object))
{
depth++;
currentReflectType = currentReflectType.GetTypeInfo().BaseType;
currentReflectType = currentReflectType.BaseType;
}

if (depth > 0)
Expand All @@ -286,7 +286,7 @@ private void FillEventInfoAttribute(EventInfo realEventInfo, IList attributes)

// Ready for the next loop iteration.
//
currentReflectType = currentReflectType.GetTypeInfo().BaseType;
currentReflectType = currentReflectType.BaseType;
}

// Now trawl the attribute stack so that we add attributes
Expand Down Expand Up @@ -322,7 +322,7 @@ private void FillMethods()

if (_addMethod == null || _removeMethod == null)
{
Type start = _componentClass.GetTypeInfo().BaseType;
Type start = _componentClass.BaseType;
while (start != null && start != typeof(object))
{
BindingFlags bindingFlags = BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic;
Expand Down Expand Up @@ -386,7 +386,7 @@ private void FillSingleMethodAttribute(MethodInfo realMethodInfo, IList attribut
while (currentReflectType != null && currentReflectType != typeof(object))
{
depth++;
currentReflectType = currentReflectType.GetTypeInfo().BaseType;
currentReflectType = currentReflectType.BaseType;
}

if (depth > 0)
Expand All @@ -411,7 +411,7 @@ private void FillSingleMethodAttribute(MethodInfo realMethodInfo, IList attribut

// Ready for the next loop iteration.
//
currentReflectType = currentReflectType.GetTypeInfo().BaseType;
currentReflectType = currentReflectType.BaseType;
}

// Now trawl the attribute stack so that we add attributes
Expand Down
Loading

0 comments on commit bda8d3f

Please sign in to comment.