From 5a759bdd3d68ec446344e809a581ff4b9e04d80c Mon Sep 17 00:00:00 2001 From: gpetrou Date: Sat, 28 Sep 2019 13:27:28 +0100 Subject: [PATCH] Remove the usage of some ReflectionUtils methods --- .../Compiler/UncollectableCompilationMode.cs | 8 +++--- .../Runtime/Binding/BindingHelpers.cs | 2 +- .../Runtime/Binding/ConversionBinder.cs | 6 ++-- .../Runtime/Binding/MetaBuiltinFunction.cs | 18 ++++++------ .../Runtime/Binding/MetaOldInstance.cs | 4 +-- .../Runtime/Binding/MetaPythonType.Calls.cs | 2 +- .../Runtime/Binding/MetaUserObject.Members.cs | 2 +- .../Runtime/Binding/MetaUserObject.cs | 2 +- .../Binding/PythonBinaryOperationBinder.cs | 8 +++--- .../Runtime/Binding/PythonBinder.cs | 6 ++-- .../Runtime/Binding/PythonExtensionBinder.cs | 2 +- .../Runtime/Binding/PythonGetMemberBinder.cs | 4 +-- .../Runtime/Binding/PythonOverloadResolver.cs | 4 +-- .../Binding/PythonProtocol.Operations.cs | 2 +- Src/IronPython/Runtime/Converter.cs | 16 +++++------ .../Runtime/Operations/InstanceOps.cs | 6 ++-- .../Runtime/Operations/PythonOps.cs | 4 +-- .../Runtime/Operations/PythonTypeOps.cs | 12 ++++---- .../Runtime/PythonDocumentationProvider.cs | 4 +-- .../Runtime/Types/BuiltinFunction.cs | 2 +- Src/IronPython/Runtime/Types/NewTypeInfo.cs | 4 +-- Src/IronPython/Runtime/Types/NewTypeMaker.cs | 14 +++++----- Src/IronPython/Runtime/Types/PythonType.cs | 22 +++++++-------- .../Runtime/Types/PythonTypeInfo.cs | 28 +++++++++---------- .../Runtime/Types/ReflectedField.cs | 4 +-- 25 files changed, 93 insertions(+), 93 deletions(-) diff --git a/Src/IronPython/Compiler/UncollectableCompilationMode.cs b/Src/IronPython/Compiler/UncollectableCompilationMode.cs index 987e59de2..a84d326ce 100644 --- a/Src/IronPython/Compiler/UncollectableCompilationMode.cs +++ b/Src/IronPython/Compiler/UncollectableCompilationMode.cs @@ -55,7 +55,7 @@ public override LightLambdaExpression ReduceAst(PythonAst instance, string name) // going to a call site which can be strongly typed. We need to coordinate // more with whoever consumes the values. if (CompilerHelpers.CanEmitConstant(value, CompilerHelpers.GetType(value)) && - !CompilerHelpers.GetType(value).IsValueType()) { + !CompilerHelpers.GetType(value).IsValueType) { return Utils.Constant(value); } @@ -71,7 +71,7 @@ public override LightLambdaExpression ReduceAst(PythonAst instance, string name) } public override Type GetConstantType(object value) { - if (value == null || value.GetType().IsValueType()) { + if (value == null || value.GetType().IsValueType) { return typeof(object); } @@ -429,7 +429,7 @@ public override int FieldCount { public override Type/*!*/ Type { get { Type returnType = _value.GetType(); - if (!returnType.IsValueType()) { + if (!returnType.IsValueType) { return returnType; } else { return typeof(object); @@ -444,7 +444,7 @@ public object Value { } public override MSAst.Expression Reduce() { - if (_value.GetType().IsValueType()) { + if (_value.GetType().IsValueType) { return base.Reduce(); } else { return MSAst.Expression.Convert(base.Reduce(), _value.GetType()); diff --git a/Src/IronPython/Runtime/Binding/BindingHelpers.cs b/Src/IronPython/Runtime/Binding/BindingHelpers.cs index 71fde3b17..625711815 100644 --- a/Src/IronPython/Runtime/Binding/BindingHelpers.cs +++ b/Src/IronPython/Runtime/Binding/BindingHelpers.cs @@ -379,7 +379,7 @@ internal static bool IsDataMember(object p) { } internal static DynamicMetaObject AddPythonBoxing(DynamicMetaObject res) { - if (res.Expression.Type.IsValueType()) { + if (res.Expression.Type.IsValueType) { // Use Python boxing rules if we're return a value type res = new DynamicMetaObject( AddPythonBoxing(res.Expression), diff --git a/Src/IronPython/Runtime/Binding/ConversionBinder.cs b/Src/IronPython/Runtime/Binding/ConversionBinder.cs index 901ebdcd1..1a51c76f7 100644 --- a/Src/IronPython/Runtime/Binding/ConversionBinder.cs +++ b/Src/IronPython/Runtime/Binding/ConversionBinder.cs @@ -95,7 +95,7 @@ public override Type ReturnType { return (_kind == ConversionResultKind.ExplicitCast || _kind == ConversionResultKind.ImplicitCast) ? Type : - _type.IsValueType() ? + _type.IsValueType ? typeof(object) : _type; } @@ -215,7 +215,7 @@ internal DynamicMetaObject FallbackConvert(Type returnType, DynamicMetaObject se break; } - if (type.IsEnum() && Enum.GetUnderlyingType(type) == self.GetLimitType()) { + if (type.IsEnum && Enum.GetUnderlyingType(type) == self.GetLimitType()) { // numeric type to enum, this is ok if the value is zero object value = Activator.CreateInstance(type); @@ -701,7 +701,7 @@ private DynamicMetaObject TryToCharConversion(DynamicMetaObject/*!*/ self) { } else if (typeof(IStrongBox).IsAssignableFrom(self.GetLimitType())) { // Explictly block conversion of References to bool res = MakeStrongBoxToBoolConversionError(self); - } else if (self.GetLimitType().IsPrimitive() || self.GetLimitType().IsEnum()) { + } else if (self.GetLimitType().IsPrimitive || self.GetLimitType().IsEnum) { // optimization - rather than doing a method call for primitives and enums generate // the comparison to zero directly. res = MakePrimitiveToBoolComparison(self); diff --git a/Src/IronPython/Runtime/Binding/MetaBuiltinFunction.cs b/Src/IronPython/Runtime/Binding/MetaBuiltinFunction.cs index 4720faf9b..0211a2cf9 100644 --- a/Src/IronPython/Runtime/Binding/MetaBuiltinFunction.cs +++ b/Src/IronPython/Runtime/Binding/MetaBuiltinFunction.cs @@ -216,7 +216,7 @@ out target if (CompilerHelpers.IsStrongBox(instanceValue)) { instance = ReadStrongBoxValue(instance); instanceValue = ((IStrongBox)instanceValue).Value; - } else if (!testType.IsEnum()) { + } else if (!testType.IsEnum) { // We need to deal w/ wierd types like MarshalByRefObject. // We could have an MBRO whos DeclaringType is completely different. // Therefore we special case it here and cast to the declaring type @@ -224,15 +224,15 @@ out target Type selfType = CompilerHelpers.GetType(Value.BindingSelf); selfType = CompilerHelpers.GetVisibleType(selfType); - if (selfType == typeof(object) && Value.DeclaringType.IsInterface()) { + if (selfType == typeof(object) && Value.DeclaringType.IsInterface) { selfType = Value.DeclaringType; Type genericTypeDefinition = null; // the behavior is different on Mono, it sets FullName for the DeclaringType - if (Value.DeclaringType.IsGenericType() && + if (Value.DeclaringType.IsGenericType && (ClrModule.IsMono || Value.DeclaringType.FullName == null) && - Value.DeclaringType.ContainsGenericParameters() && - !Value.DeclaringType.IsGenericTypeDefinition()) { + Value.DeclaringType.ContainsGenericParameters && + !Value.DeclaringType.IsGenericTypeDefinition) { // from MSDN: If the current type contains generic type parameters that have not been replaced by // specific types (that is, the ContainsGenericParameters property returns true), but the type // is not a generic type definition (that is, the IsGenericTypeDefinition property returns false), @@ -251,7 +251,7 @@ out target if (hasOnlyGenerics) { genericTypeDefinition = Value.DeclaringType.GetGenericTypeDefinition(); } - } else if (Value.DeclaringType.IsGenericTypeDefinition()) { + } else if (Value.DeclaringType.IsGenericTypeDefinition) { genericTypeDefinition = Value.DeclaringType; } @@ -261,7 +261,7 @@ out target // the concrete selfType. var interfaces = CompilerHelpers.GetType(Value.BindingSelf).GetInterfaces(); foreach (var iface in interfaces) { - if (iface.IsGenericType() && iface.GetGenericTypeDefinition() == genericTypeDefinition) { + if (iface.IsGenericType && iface.GetGenericTypeDefinition() == genericTypeDefinition) { selfType = iface; break; } @@ -269,11 +269,11 @@ out target } } - if (Value.DeclaringType.IsInterface() && selfType.IsValueType()) { + if (Value.DeclaringType.IsInterface && selfType.IsValueType) { // explicit interface implementation dispatch on a value type, don't // unbox the value type before the dispatch. instance = AstUtils.Convert(instance, Value.DeclaringType); - } else if (selfType.IsValueType()) { + } else if (selfType.IsValueType) { // We might be calling a a mutating method (like // Rectangle.Intersect). If so, we want it to mutate // the boxed value directly diff --git a/Src/IronPython/Runtime/Binding/MetaOldInstance.cs b/Src/IronPython/Runtime/Binding/MetaOldInstance.cs index 24a72a68a..6ec159b41 100644 --- a/Src/IronPython/Runtime/Binding/MetaOldInstance.cs +++ b/Src/IronPython/Runtime/Binding/MetaOldInstance.cs @@ -108,7 +108,7 @@ public DynamicMetaObject BindConvert(PythonConversionBinder binder) { } public DynamicMetaObject ConvertWorker(DynamicMetaObjectBinder binder, Type type, Type retType, ConversionResultKind kind) { - if (!type.IsEnum()) { + if (!type.IsEnum) { switch (type.GetTypeCode()) { case TypeCode.Boolean: return MakeConvertToBool(binder); @@ -127,7 +127,7 @@ public DynamicMetaObject ConvertWorker(DynamicMetaObjectBinder binder, Type type return MakeConvertToIEnumerable(binder); } else if (type == typeof(IEnumerator)) { return MakeConvertToIEnumerator(binder); - } else if (type.IsGenericType() && type.GetGenericTypeDefinition() == typeof(IEnumerable<>)) { + } else if (type.IsGenericType && type.GetGenericTypeDefinition() == typeof(IEnumerable<>)) { return MakeConvertToIEnumerable(binder, type, type.GetGenericArguments()[0]); } else if (type.IsSubclassOf(typeof(Delegate))) { return MakeDelegateTarget(binder, type, Restrict(typeof(OldInstance))); diff --git a/Src/IronPython/Runtime/Binding/MetaPythonType.Calls.cs b/Src/IronPython/Runtime/Binding/MetaPythonType.Calls.cs index af9dfaf13..aa1cab3b3 100644 --- a/Src/IronPython/Runtime/Binding/MetaPythonType.Calls.cs +++ b/Src/IronPython/Runtime/Binding/MetaPythonType.Calls.cs @@ -148,7 +148,7 @@ partial class MetaPythonType : MetaPythonObject, IPythonInvokable { if (TooManyArgsForDefaultNew(call, args)) { return MakeIncorrectArgumentsForCallError(call, ai, valInfo); - } else if (Value.UnderlyingSystemType.IsGenericTypeDefinition()) { + } else if (Value.UnderlyingSystemType.IsGenericTypeDefinition) { return MakeGenericTypeDefinitionError(call, ai, valInfo); } else if (Value.HasAbstractMethods(PythonContext.GetPythonContext(call).SharedContext)) { return MakeAbstractInstantiationError(call, ai, valInfo); diff --git a/Src/IronPython/Runtime/Binding/MetaUserObject.Members.cs b/Src/IronPython/Runtime/Binding/MetaUserObject.Members.cs index 73eb6aa54..8c72b385e 100644 --- a/Src/IronPython/Runtime/Binding/MetaUserObject.Members.cs +++ b/Src/IronPython/Runtime/Binding/MetaUserObject.Members.cs @@ -999,7 +999,7 @@ protected override DynamicMetaObject Finish() { _target.Restrict(Instance.GetType()).Restrictions.Merge(_result.Restrictions) ); - Debug.Assert(!_result.Expression.Type.IsValueType()); + Debug.Assert(!_result.Expression.Type.IsValueType); return BindingHelpers.AddDynamicTestAndDefer( _info.Action, diff --git a/Src/IronPython/Runtime/Binding/MetaUserObject.cs b/Src/IronPython/Runtime/Binding/MetaUserObject.cs index a3d8694ec..67e63d87f 100644 --- a/Src/IronPython/Runtime/Binding/MetaUserObject.cs +++ b/Src/IronPython/Runtime/Binding/MetaUserObject.cs @@ -169,7 +169,7 @@ private DynamicMetaObject InvokeFallback(DynamicMetaObjectBinder action, Express #region Conversions private DynamicMetaObject TryPythonConversion(DynamicMetaObjectBinder conversion, Type type) { - if (!type.IsEnum()) { + if (!type.IsEnum) { switch (type.GetTypeCode()) { case TypeCode.Object: if (type == typeof(Complex)) { diff --git a/Src/IronPython/Runtime/Binding/PythonBinaryOperationBinder.cs b/Src/IronPython/Runtime/Binding/PythonBinaryOperationBinder.cs index f67cebdf7..469aa9f9b 100644 --- a/Src/IronPython/Runtime/Binding/PythonBinaryOperationBinder.cs +++ b/Src/IronPython/Runtime/Binding/PythonBinaryOperationBinder.cs @@ -272,7 +272,7 @@ private T BindAdd(CallSite site, object[] args) where T : class { return (T)(object)new Func(TupleAdd); } - } else if (!t.IsEnum()) { + } else if (!t.IsEnum) { switch (t.GetTypeCode()) { case TypeCode.Double: if(typeof(T) == typeof(Func)) { @@ -295,7 +295,7 @@ private T BindAdd(CallSite site, object[] args) where T : class { private T BindSubtract(CallSite site, object[] args) where T : class { Type t = args[0].GetType(); - if (!t.IsEnum()) { + if (!t.IsEnum) { switch (t.GetTypeCode()) { case TypeCode.Double: if (typeof(T) == typeof(Func)) { @@ -326,7 +326,7 @@ private T BindEqual(CallSite site, object[] args) where T : class { } else if (typeof(T) == typeof(Func)) { return (T)(object)new Func(StringEqual); } - } else if (!t.IsEnum() && typeof(T) == typeof(Func)) { + } else if (!t.IsEnum && typeof(T) == typeof(Func)) { switch (t.GetTypeCode()) { case TypeCode.Double: return (T)(object)new Func(DoubleEqual); @@ -347,7 +347,7 @@ private T BindNotEqual(CallSite site, object[] args) where T : class { } else if (typeof(T) == typeof(Func)) { return (T)(object)new Func(StringNotEqual); } - } else if (!t.IsEnum() && typeof(T) == typeof(Func)) { + } else if (!t.IsEnum && typeof(T) == typeof(Func)) { switch (t.GetTypeCode()) { case TypeCode.Double: return (T)(object)new Func(DoubleNotEqual); diff --git a/Src/IronPython/Runtime/Binding/PythonBinder.cs b/Src/IronPython/Runtime/Binding/PythonBinder.cs index 1a1d1fe0c..502417dc9 100644 --- a/Src/IronPython/Runtime/Binding/PythonBinder.cs +++ b/Src/IronPython/Runtime/Binding/PythonBinder.cs @@ -68,7 +68,7 @@ public PythonBinder(PythonBinder binder) { Type exprType = expr.Type; if (toType == typeof(object)) { - if (exprType.IsValueType()) { + if (exprType.IsValueType) { return AstUtils.Convert(expr, toType); } else { return expr; @@ -98,7 +98,7 @@ public PythonBinder(PythonBinder binder) { } internal static MethodInfo GetGenericConvertMethod(Type toType) { - if (toType.IsValueType()) { + if (toType.IsValueType) { if (toType.IsGenericType() && toType.GetGenericTypeDefinition() == typeof(Nullable<>)) { return typeof(Converter).GetMethod("ConvertToNullableType"); } else { @@ -821,7 +821,7 @@ private void DomainManager_AssemblyLoaded(object sender, AssemblyLoadedEventArgs if (attrs.Any()) { lock (_dlrExtensionTypes) { foreach (ExtensionTypeAttribute attr in attrs) { - if (attr.Extends.IsInterface()) { + if (attr.Extends.IsInterface) { _registeredInterfaceExtensions = true; } diff --git a/Src/IronPython/Runtime/Binding/PythonExtensionBinder.cs b/Src/IronPython/Runtime/Binding/PythonExtensionBinder.cs index 3e3e5698d..19546f2ea 100644 --- a/Src/IronPython/Runtime/Binding/PythonExtensionBinder.cs +++ b/Src/IronPython/Runtime/Binding/PythonExtensionBinder.cs @@ -48,7 +48,7 @@ public override MemberGroup GetMember(MemberRequestKind actionKind, Type type, s internal static bool IsApplicableExtensionMethod(Type instanceType, Type extensionMethodThisType) { - if (extensionMethodThisType.ContainsGenericParameters()) { + if (extensionMethodThisType.ContainsGenericParameters) { Dictionary binding = new Dictionary(); if (extensionMethodThisType.IsArray) { diff --git a/Src/IronPython/Runtime/Binding/PythonGetMemberBinder.cs b/Src/IronPython/Runtime/Binding/PythonGetMemberBinder.cs index 52e892885..b7ace6ebb 100644 --- a/Src/IronPython/Runtime/Binding/PythonGetMemberBinder.cs +++ b/Src/IronPython/Runtime/Binding/PythonGetMemberBinder.cs @@ -328,7 +328,7 @@ private Func MakeGetMemberTarget args public override bool CanConvertFrom(Type fromType, DynamicMetaObject fromArg, ParameterWrapper toParameter, NarrowingLevel level) { if ((fromType == typeof(List) || fromType.IsSubclassOf(typeof(List)))) { - if (toParameter.Type.IsGenericType() && + if (toParameter.Type.IsGenericType && toParameter.Type.GetGenericTypeDefinition() == typeof(IList<>) && (toParameter.ParameterInfo.IsDefined(typeof(BytesConversionAttribute), false) || toParameter.ParameterInfo.IsDefined(typeof(BytesConversionNoStringAttribute), false))) { @@ -141,7 +141,7 @@ public override Type GetGenericInferenceType(DynamicMetaObject dynamicObject) { Type res = PythonTypeOps.GetFinalSystemType(dynamicObject.LimitType); if (res == typeof(ExtensibleString) || res == typeof(ExtensibleComplex) || - (res.IsGenericType() && res.GetGenericTypeDefinition() == typeof(Extensible<>))) { + (res.IsGenericType && res.GetGenericTypeDefinition() == typeof(Extensible<>))) { return typeof(object); } diff --git a/Src/IronPython/Runtime/Binding/PythonProtocol.Operations.cs b/Src/IronPython/Runtime/Binding/PythonProtocol.Operations.cs index 720aa8741..8ac2c506e 100644 --- a/Src/IronPython/Runtime/Binding/PythonProtocol.Operations.cs +++ b/Src/IronPython/Runtime/Binding/PythonProtocol.Operations.cs @@ -1257,7 +1257,7 @@ private static void DoCoerce(PythonContext/*!*/ pyContext, ConditionalBuilder/*! AstUtils.Constant(0), BindingRestrictions.Combine(types) ); - } else if (yType.UnderlyingSystemType.IsPrimitive() || yType.UnderlyingSystemType == typeof(BigInteger)) { + } else if (yType.UnderlyingSystemType.IsPrimitive || yType.UnderlyingSystemType == typeof(BigInteger)) { return new DynamicMetaObject( AstUtils.Constant(-1), BindingRestrictions.Combine(types) diff --git a/Src/IronPython/Runtime/Converter.cs b/Src/IronPython/Runtime/Converter.cs index f3a254fdd..db2178392 100644 --- a/Src/IronPython/Runtime/Converter.cs +++ b/Src/IronPython/Runtime/Converter.cs @@ -281,8 +281,8 @@ internal static object Convert(object value, Type to) { } object res = site.Target(site, value); - if (to.IsValueType() && res == null && - (!to.IsGenericType() || to.GetGenericTypeDefinition() != typeof(Nullable<>))) { + if (to.IsValueType && res == null && + (!to.IsGenericType || to.GetGenericTypeDefinition() != typeof(Nullable<>))) { throw MakeTypeError(to, value); } return res; @@ -565,7 +565,7 @@ private static TypeConverter GetTypeConverter(TypeConverterAttribute tca) { #endif private static bool HasImplicitNumericConversion(Type fromType, Type toType) { - if (fromType.IsEnum()) return false; + if (fromType.IsEnum) return false; if (fromType == typeof(BigInteger)) { if (toType == typeof(double)) return true; @@ -804,7 +804,7 @@ private static bool HasNarrowingConversion(Type fromType, Type toType, Narrowing if (toType == typeof(IEnumerator)) { if (IsPythonType(fromType)) return true; - } else if (toType.IsGenericType()) { + } else if (toType.IsGenericType) { Type genTo = toType.GetGenericTypeDefinition(); if (genTo == IEnumerableOfTType) { return IEnumerableOfObjectType.IsAssignableFrom(fromType) || @@ -824,7 +824,7 @@ private static bool HasNarrowingConversion(Type fromType, Type toType, Narrowing if (toType == BigIntegerType && HasPythonProtocol(fromType, "__long__")) return true; } - if (toType.IsGenericType()) { + if (toType.IsGenericType) { Type genTo = toType.GetGenericTypeDefinition(); if (genTo == IListOfTType) { return IListOfObjectType.IsAssignableFrom(fromType); @@ -838,7 +838,7 @@ private static bool HasNarrowingConversion(Type fromType, Type toType, Narrowing } if (fromType == BigIntegerType && toType == Int64Type) return true; - if (toType.IsEnum() && fromType == Enum.GetUnderlyingType(toType)) return true; + if (toType.IsEnum && fromType == Enum.GetUnderlyingType(toType)) return true; return false; } @@ -858,7 +858,7 @@ private static bool HasImplicitConversionWorker(Type lookupType, Type fromType, return true; } } - lookupType = lookupType.GetBaseType(); + lookupType = lookupType.BaseType; } return false; } @@ -896,7 +896,7 @@ private static bool HasImplicitConversionWorker(Type lookupType, Type fromType, } internal static bool IsNumeric(Type t) { - if (t.IsEnum()) return false; + if (t.IsEnum) return false; const TypeCode TypeCodeDbNull = (TypeCode)2; // TypeCode.DBNull switch (t.GetTypeCode()) { diff --git a/Src/IronPython/Runtime/Operations/InstanceOps.cs b/Src/IronPython/Runtime/Operations/InstanceOps.cs index 6f358a9c3..2fb403ed1 100644 --- a/Src/IronPython/Runtime/Operations/InstanceOps.cs +++ b/Src/IronPython/Runtime/Operations/InstanceOps.cs @@ -691,7 +691,7 @@ public static void ExitMethod(IDisposable/*!*/ self, object exc_type, object exc [PropertyMethod, StaticExtensionMethod] public static List/*!*/ Get__all__(CodeContext/*!*/ context) { - Debug.Assert(typeof(T).IsSealed() && typeof(T).IsAbstract(), "__all__ should only be produced for static members"); + Debug.Assert(typeof(T).IsSealed && typeof(T).IsAbstract(), "__all__ should only be produced for static members"); PythonType pt = DynamicHelpers.GetPythonTypeFromType(typeof(T)); @@ -730,13 +730,13 @@ private static bool IsStaticTypeMemberInAll(CodeContext/*!*/ context, PythonType } BuiltinMethodDescriptor method = pts as BuiltinMethodDescriptor; - if (method != null && (!method.DeclaringType.IsSealed() || !method.DeclaringType.IsAbstract())) { + if (method != null && (!method.DeclaringType.IsSealed || !method.DeclaringType.IsAbstract())) { // inherited object member on a static class (GetHashCode, Equals, etc...) return false; } BuiltinFunction bf = pts as BuiltinFunction; - if (bf != null && (!bf.DeclaringType.IsSealed() || !bf.DeclaringType.IsAbstract())) { + if (bf != null && (!bf.DeclaringType.IsSealed || !bf.DeclaringType.IsAbstract())) { // __new__/ReferenceEquals inherited from object return false; } diff --git a/Src/IronPython/Runtime/Operations/PythonOps.cs b/Src/IronPython/Runtime/Operations/PythonOps.cs index 1f051d64f..463497b67 100644 --- a/Src/IronPython/Runtime/Operations/PythonOps.cs +++ b/Src/IronPython/Runtime/Operations/PythonOps.cs @@ -1904,8 +1904,8 @@ public static void ImportStar(CodeContext/*!*/ context, string fullName, int lev PythonType pt = newmod as PythonType; if (pt != null && - !pt.UnderlyingSystemType.IsEnum() && - (!pt.UnderlyingSystemType.IsAbstract() || !pt.UnderlyingSystemType.IsSealed())) { + !pt.UnderlyingSystemType.IsEnum && + (!pt.UnderlyingSystemType.IsAbstract || !pt.UnderlyingSystemType.IsSealed)) { // from type import * only allowed on static classes (and enums) throw PythonOps.ImportError("no module named {0}", pt.Name); } diff --git a/Src/IronPython/Runtime/Operations/PythonTypeOps.cs b/Src/IronPython/Runtime/Operations/PythonTypeOps.cs index 2798b0b43..2baced94f 100644 --- a/Src/IronPython/Runtime/Operations/PythonTypeOps.cs +++ b/Src/IronPython/Runtime/Operations/PythonTypeOps.cs @@ -344,7 +344,7 @@ private static BuiltinFunction GetConstructorFunction(Type t, bool privateBindin internal static MethodBase[] GetConstructors(Type t, bool privateBinding, bool includeProtected = false) { MethodBase[] ctors = CompilerHelpers.GetConstructors(t, privateBinding, includeProtected); - if (t.IsEnum()) { + if (t.IsEnum) { var enumCtor = typeof(PythonTypeOps).GetDeclaredMethods(nameof(CreateEnum)).Single().MakeGenericMethod(t); ctors = ctors.Concat(new[] { enumCtor }).ToArray(); } @@ -396,7 +396,7 @@ internal static BuiltinFunction GetConstructorFunction(Type type, string name) { } } - if (type.IsValueType() && !hasDefaultConstructor && type != typeof(void)) { + if (type.IsValueType && !hasDefaultConstructor && type != typeof(void)) { try { methods.Add(typeof(ScriptingRuntimeHelpers).GetMethod("CreateInstance", ReflectionUtils.EmptyTypes).MakeGenericMethod(type)); } catch (BadImageFormatException) { @@ -549,8 +549,8 @@ private static Type GetCommonBaseType(Type xType, Type yType) { return xType; } - Type xBase = xType.GetBaseType(); - Type yBase = yType.GetBaseType(); + Type xBase = xType.BaseType; + Type yBase = yType.BaseType; if (xBase != null) { Type res = GetCommonBaseType(xBase, yType); if (res != null) { @@ -913,7 +913,7 @@ internal static PythonTuple EnsureBaseType(PythonTuple bases) { PythonType dt = baseClass as PythonType; - if (!dt.UnderlyingSystemType.IsInterface()) { + if (!dt.UnderlyingSystemType.IsInterface) { return bases; } else { hasInterface = true; @@ -930,7 +930,7 @@ internal static PythonTuple EnsureBaseType(PythonTuple bases) { internal static Type GetFinalSystemType(Type type) { while (typeof(IPythonObject).IsAssignableFrom(type) && !type.IsDefined(typeof(DynamicBaseTypeAttribute), false)) { - type = type.GetBaseType(); + type = type.BaseType; } return type; } diff --git a/Src/IronPython/Runtime/PythonDocumentationProvider.cs b/Src/IronPython/Runtime/PythonDocumentationProvider.cs index 5786c2673..b1475125e 100644 --- a/Src/IronPython/Runtime/PythonDocumentationProvider.cs +++ b/Src/IronPython/Runtime/PythonDocumentationProvider.cs @@ -119,7 +119,7 @@ private static MemberDoc MakeMemberDoc(string name, object value, bool fromClass kind = MemberKind.Method; } else if (value is PythonType) { var pt = value as PythonType; - if (pt.IsSystemType && pt.UnderlyingSystemType.IsEnum()) { + if (pt.IsSystemType && pt.UnderlyingSystemType.IsEnum) { kind = MemberKind.Enum; } else { kind = MemberKind.Class; @@ -132,7 +132,7 @@ private static MemberDoc MakeMemberDoc(string name, object value, bool fromClass kind = MemberKind.Event; } else if (value is ReflectedField) { kind = MemberKind.Field; - } else if (value != null && value.GetType().IsEnum()) { + } else if (value != null && value.GetType().IsEnum) { kind = MemberKind.EnumMember; } else if (value is PythonType || value is OldClass) { kind = MemberKind.Class; diff --git a/Src/IronPython/Runtime/Types/BuiltinFunction.cs b/Src/IronPython/Runtime/Types/BuiltinFunction.cs index 8d01bfb15..158491e54 100644 --- a/Src/IronPython/Runtime/Types/BuiltinFunction.cs +++ b/Src/IronPython/Runtime/Types/BuiltinFunction.cs @@ -441,7 +441,7 @@ public BindingResult(BindingTarget target, DynamicMetaObject meta) { // The function can return something typed to boolean or int. // If that happens, we need to apply Python's boxing rules. - if (res.Expression.Type.IsValueType()) { + if (res.Expression.Type.IsValueType) { res = BindingHelpers.AddPythonBoxing(res); } else if (res.Expression.Type == typeof(void)) { res = new DynamicMetaObject( diff --git a/Src/IronPython/Runtime/Types/NewTypeInfo.cs b/Src/IronPython/Runtime/Types/NewTypeInfo.cs index 4d53ece48..1c326e43b 100644 --- a/Src/IronPython/Runtime/Types/NewTypeInfo.cs +++ b/Src/IronPython/Runtime/Types/NewTypeInfo.cs @@ -61,11 +61,11 @@ public static NewTypeInfo GetTypeInfo(string typeName, PythonTuple bases) { if (curTypeToExtend == null || typeof(BuiltinFunction).IsAssignableFrom(curTypeToExtend) || typeof(PythonFunction).IsAssignableFrom(curTypeToExtend)) throw PythonOps.TypeError(typeName + ": {0} is not an acceptable base type", curBasePythonType.Name); - if (curTypeToExtend.ContainsGenericParameters()) + if (curTypeToExtend.ContainsGenericParameters) throw PythonOps.TypeError(typeName + ": cannot inhert from open generic instantiation {0}. Only closed instantiations are supported.", curBasePythonType); foreach (Type interfaceType in baseInterfaces) { - if (interfaceType.ContainsGenericParameters()) + if (interfaceType.ContainsGenericParameters) throw PythonOps.TypeError(typeName + ": cannot inhert from open generic instantiation {0}. Only closed instantiations are supported.", interfaceType); // collecting all the interfaces because we override them all. diff --git a/Src/IronPython/Runtime/Types/NewTypeMaker.cs b/Src/IronPython/Runtime/Types/NewTypeMaker.cs index 51ccea0c8..bf1a9d4d3 100644 --- a/Src/IronPython/Runtime/Types/NewTypeMaker.cs +++ b/Src/IronPython/Runtime/Types/NewTypeMaker.cs @@ -88,9 +88,9 @@ private NewTypeMaker(NewTypeInfo typeInfo) { NewTypeInfo typeInfo = NewTypeInfo.GetTypeInfo(typeName, bases); - if (typeInfo.BaseType.IsValueType()) { + if (typeInfo.BaseType.IsValueType) { throw PythonOps.TypeError("cannot derive from {0} because it is a value type", typeInfo.BaseType.FullName); - } else if (typeInfo.BaseType.IsSealed()) { + } else if (typeInfo.BaseType.IsSealed) { throw PythonOps.TypeError("cannot derive from {0} because it is sealed", typeInfo.BaseType.FullName); } @@ -209,7 +209,7 @@ public static void LoadNewTypes(Assembly/*!*/ asm) { var typeInfo = (CachedNewTypeInfo[])mi.Invoke(null, new object[0]); foreach (var v in typeInfo) { _newTypes.GetOrCreateValue( - new NewTypeInfo(v.Type.GetBaseType(), v.InterfaceTypes), + new NewTypeInfo(v.Type.BaseType, v.InterfaceTypes), () => { // type wasn't already created, go ahead and publish // the info and return the type. @@ -911,7 +911,7 @@ private void OverrideMethods(Type type, Dictionary specialName } } - if (type.IsAbstract() && !type.IsInterface()) { + if (type.IsAbstract() && !type.IsInterface) { // abstract types can define interfaces w/o implementations foreach (Type iface in type.GetInterfaces()) { InterfaceMapping mapping = type.GetInterfaceMap(iface); @@ -1113,7 +1113,7 @@ private PythonType GetBaseTypeForMethod(MethodInfo mi) { basePythonType = DynamicHelpers.GetPythonTypeFromType(_baseType); } else { // We must be inherting from an interface - Debug.Assert(mi.DeclaringType.IsInterface()); + Debug.Assert(mi.DeclaringType.IsInterface); basePythonType = DynamicHelpers.GetPythonTypeFromType(mi.DeclaringType); } return basePythonType; @@ -1668,7 +1668,7 @@ private static void StoreOverriddenMethod(MethodInfo mi, string newName) { } private static void StoreOverriddenProperty(MethodInfo mi, string newName) { - Type baseType = mi.DeclaringType.GetBaseType(); + Type baseType = mi.DeclaringType.BaseType; lock (PythonTypeOps._propertyCache) { string propName = newName.Substring(4); // get_ or set_ @@ -1782,7 +1782,7 @@ sealed class ReturnFixer { private readonly int _index; private ReturnFixer(LocalBuilder reference, ParameterInfo parameter, int index) { - Debug.Assert(reference.LocalType.IsGenericType() && reference.LocalType.GetGenericTypeDefinition() == typeof(StrongBox<>)); + Debug.Assert(reference.LocalType.IsGenericType && reference.LocalType.GetGenericTypeDefinition() == typeof(StrongBox<>)); Debug.Assert(parameter.ParameterType.IsByRef); _parameter = parameter; diff --git a/Src/IronPython/Runtime/Types/PythonType.cs b/Src/IronPython/Runtime/Types/PythonType.cs index 247682062..e1d3bf2c1 100644 --- a/Src/IronPython/Runtime/Types/PythonType.cs +++ b/Src/IronPython/Runtime/Types/PythonType.cs @@ -639,7 +639,7 @@ public PythonType this[params Type[] args] { throw PythonOps.TypeError("expected one argument to make array type, got {0}", args.Length); } - if (!UnderlyingSystemType.IsGenericTypeDefinition()) { + if (!UnderlyingSystemType.IsGenericTypeDefinition) { throw new InvalidOperationException("MakeGenericType on non-generic type"); } @@ -790,7 +790,7 @@ public virtual bool __subclasscheck__(PythonType sub) { } private bool SubclassImpl(PythonType sub) { - if (UnderlyingSystemType.IsInterface()) { + if (UnderlyingSystemType.IsInterface) { // interfaces aren't in bases, and therefore IsSubclassOf doesn't do this check. if (UnderlyingSystemType.IsAssignableFrom(sub.UnderlyingSystemType)) { return true; @@ -1108,7 +1108,7 @@ internal Type/*!*/ FinalSystemType { /// internal Type/*!*/ ExtensionType { get { - if (!_underlyingSystemType.IsEnum()) { + if (!_underlyingSystemType.IsEnum) { switch (_underlyingSystemType.GetTypeCode()) { case TypeCode.String: return typeof(ExtensibleString); case TypeCode.Int32: return typeof(Extensible); @@ -1170,7 +1170,7 @@ internal bool IsSubclassOf(PythonType other) { } //Python doesn't have value types inheriting from ValueType, but we fake this for interop - if (other.UnderlyingSystemType == typeof(ValueType) && UnderlyingSystemType.IsValueType()) { + if (other.UnderlyingSystemType == typeof(ValueType) && UnderlyingSystemType.IsValueType) { return true; } @@ -1349,7 +1349,7 @@ internal bool TryResolveSlot(CodeContext context, string name, out PythonTypeSlo // don't look at interfaces - users can inherit from them, but we resolve members // via methods implemented on types and defined by Python. - if (dt.IsSystemType && !dt.UnderlyingSystemType.IsInterface()) { + if (dt.IsSystemType && !dt.UnderlyingSystemType.IsInterface) { return PythonBinder.GetBinder(context).TryResolveSlot(context, dt, this, name, out slot); } @@ -1358,7 +1358,7 @@ internal bool TryResolveSlot(CodeContext context, string name, out PythonTypeSlo } } - if (UnderlyingSystemType.IsInterface()) { + if (UnderlyingSystemType.IsInterface) { return TypeCache.Object.TryResolveSlot(context, name, out slot); } @@ -2424,15 +2424,15 @@ private void AddSystemBases() { if (_underlyingSystemType == typeof(bool)) { // bool inherits from int in python baseType = typeof(int); - } else if (_underlyingSystemType.GetBaseType() == typeof(ValueType)) { + } else if (_underlyingSystemType.BaseType == typeof(ValueType)) { // hide ValueType, it doesn't exist in Python baseType = typeof(object); } else { - baseType = _underlyingSystemType.GetBaseType(); + baseType = _underlyingSystemType.BaseType; } while (baseType.IsDefined(typeof(PythonHiddenBaseClassAttribute), false)) { - baseType = baseType.GetBaseType(); + baseType = baseType.BaseType; } _bases = new PythonType[] { GetPythonType(baseType) }; @@ -2445,13 +2445,13 @@ private void AddSystemBases() { } else if(!curType.IsDefined(typeof(PythonHiddenBaseClassAttribute), false)) { mro.Add(DynamicHelpers.GetPythonTypeFromType(curType)); } - curType = curType.GetBaseType(); + curType = curType.BaseType; } if (!IsPythonType) { AddSystemInterfaces(mro); } - } else if (_underlyingSystemType.IsInterface()) { + } else if (_underlyingSystemType.IsInterface) { // add interfaces to MRO & create bases list Type[] interfaces = _underlyingSystemType.GetInterfaces(); PythonType[] bases = new PythonType[interfaces.Length]; diff --git a/Src/IronPython/Runtime/Types/PythonTypeInfo.cs b/Src/IronPython/Runtime/Types/PythonTypeInfo.cs index 6f7f0ec09..7a2c0a15d 100644 --- a/Src/IronPython/Runtime/Types/PythonTypeInfo.cs +++ b/Src/IronPython/Runtime/Types/PythonTypeInfo.cs @@ -318,7 +318,7 @@ public ComparisonResolver(Type/*!*/ comparable, string/*!*/ helperPrefix) { // Do not map IComparable if this is a primitive builtin type. if (_excludePrimitiveTypes) { - if (type.IsPrimitive() || type == typeof(BigInteger) || + if (type.IsPrimitive || type == typeof(BigInteger) || type == typeof(string) || type == typeof(decimal)) { return MemberGroup.EmptyGroup; } @@ -343,7 +343,7 @@ public ComparisonResolver(Type/*!*/ comparable, string/*!*/ helperPrefix) { /// private class OperatorResolver : MemberResolver { public override MemberGroup/*!*/ ResolveMember(MemberBinder/*!*/ binder, MemberRequestKind/*!*/ action, Type/*!*/ type, string/*!*/ name) { - if (type.IsSealed() && type.IsAbstract()) { + if (type.IsSealed && type.IsAbstract) { // static types don't have PythonOperationKind return MemberGroup.EmptyGroup; } @@ -793,7 +793,7 @@ private class ProtectedMemberResolver : MemberResolver { // __repr__ for normal .NET types is special, if we're a Python type then // we'll use one of the built-in reprs (from object or from the type) if (!PythonBinder.IsPythonType(type) && - (!type.IsSealed() || !type.IsAbstract())) { // static types don't get __repr__ + (!type.IsSealed || !type.IsAbstract)) { // static types don't get __repr__ // check and see if __repr__ has been overridden by the base type. foreach (Type t in binder.GetContributingTypes(type)) { if (t == typeof(ObjectOps) && type != typeof(object)) { @@ -852,7 +852,7 @@ private static bool TypeOverridesMethod(MemberBinder/*!*/ binder, Type/*!*/ typ /// Provides a resolution for __hash__ looking for IStructuralEquatable.GetHashCode. /// private static MemberGroup/*!*/ HashResolver(MemberBinder/*!*/ binder, Type/*!*/ type) { - if (typeof(IStructuralEquatable).IsAssignableFrom(type) && !type.IsInterface()) { + if (typeof(IStructuralEquatable).IsAssignableFrom(type) && !type.IsInterface) { // check and see if __hash__ has been overridden by the base type. foreach (Type t in binder.GetContributingTypes(type)) { // if it's defined on object, it's not overridden @@ -881,7 +881,7 @@ private static bool TypeOverridesMethod(MemberBinder/*!*/ binder, Type/*!*/ typ /// TODO: Can we just always fallback to object.__new__? If not why not? /// private static MemberGroup/*!*/ NewResolver(MemberBinder/*!*/ binder, Type/*!*/ type) { - if (type.IsSealed() && type.IsAbstract()) { + if (type.IsSealed && type.IsAbstract) { // static types don't have __new__ return MemberGroup.EmptyGroup; } @@ -954,7 +954,7 @@ internal static MemberGroup GetExtensionMemberGroup(Type type, MemberInfo[] news } foreach (Type t in binder.GetInterfaces(type)) { - if (t.IsGenericType() && t.GetGenericTypeDefinition() == typeof(ICollection<>)) { + if (t.IsGenericType && t.GetGenericTypeDefinition() == typeof(ICollection<>)) { MethodInfo genMeth = typeof(InstanceOps).GetMethod("GenericLengthMethod"); return new MemberGroup( MethodTracker.FromMemberInfo(genMeth.MakeGenericMethod(t.GetGenericArguments()), type) @@ -1046,7 +1046,7 @@ internal static MemberGroup GetExtensionMemberGroup(Type type, MemberInfo[] news private static MemberGroup/*!*/ AllResolver(MemberBinder/*!*/ binder, Type/*!*/ type) { // static types are like modules and define __all__. - if (type.IsAbstract() && type.IsSealed()) { + if (type.IsAbstract() && type.IsSealed) { return new MemberGroup(new ExtensionPropertyTracker("__all__", typeof(InstanceOps).GetMethod("Get__all__").MakeGenericMethod(type), null, null, type)); } @@ -1158,7 +1158,7 @@ internal override bool TrySetValue(CodeContext context, object instance, PythonT // search for IDictionary first because it's ICollection> and we want to call ContainsKey foreach (Type t in intf) { - if (t.IsGenericType() && t.GetGenericTypeDefinition() == typeof(IDictionary<,>)) { + if (t.IsGenericType && t.GetGenericTypeDefinition() == typeof(IDictionary<,>)) { if (t.GetGenericArguments()[0] == typeof(object)) { hasObjectContains = true; } @@ -1174,7 +1174,7 @@ internal override bool TrySetValue(CodeContext context, object instance, PythonT if (containsMembers == null) { // then look for ICollection for generic __contains__ first if we're not an IDictionary foreach (Type t in intf) { - if (t.IsGenericType() && t.GetGenericTypeDefinition() == typeof(ICollection<>)) { + if (t.IsGenericType && t.GetGenericTypeDefinition() == typeof(ICollection<>)) { if (t.GetGenericArguments()[0] == typeof(object)) { hasObjectContains = true; } @@ -1224,7 +1224,7 @@ internal override bool TrySetValue(CodeContext context, object instance, PythonT /// private static void GetEnumeratorContains(Type type, IList intf, ref List containsMembers, ref bool hasObjectContains, Type ienumOfT, Type ienum, string name) { foreach (Type t in intf) { - if (t.IsGenericType() && t.GetGenericTypeDefinition() == ienumOfT) { + if (t.IsGenericType && t.GetGenericTypeDefinition() == ienumOfT) { if (t.GetGenericArguments()[0] == typeof(object)) { hasObjectContains = true; } @@ -1265,7 +1265,7 @@ public OneOffOperatorBinder(string/*!*/ methodName, string/*!*/ pythonName, Pyth } public MemberGroup/*!*/ Resolver(MemberBinder/*!*/ binder, Type/*!*/ type) { - if (type.IsSealed() && type.IsAbstract()) { + if (type.IsSealed && type.IsAbstract) { // static types don't have PythonOperationKind return MemberGroup.EmptyGroup; } @@ -1292,7 +1292,7 @@ public OneOffPowerBinder(string/*!*/ pythonName, PythonOperationKind op) { } public MemberGroup/*!*/ Resolver(MemberBinder/*!*/ binder, Type/*!*/ type) { - if (type.IsSealed() && type.IsAbstract()) { + if (type.IsSealed && type.IsAbstract) { // static types don't have PythonOperationKind return MemberGroup.EmptyGroup; } @@ -1462,7 +1462,7 @@ public ResolveBinder(PythonBinder/*!*/ binder) res.AddRange(Binder.GetExtensionTypesInternal(pt.UnderlyingSystemType)); } - if (t.IsInterface()) { + if (t.IsInterface) { foreach (Type iface in t.GetInterfaces()) { res.Add(iface); } @@ -1485,7 +1485,7 @@ public LookupBinder(PythonBinder/*!*/ binder) } public override IList/*!*/ GetInterfaces(Type/*!*/ t) { - if (t.IsInterface()) { + if (t.IsInterface) { return t.GetInterfaces(); } diff --git a/Src/IronPython/Runtime/Types/ReflectedField.cs b/Src/IronPython/Runtime/Types/ReflectedField.cs index 65e916715..c4de94c4a 100644 --- a/Src/IronPython/Runtime/Types/ReflectedField.cs +++ b/Src/IronPython/Runtime/Types/ReflectedField.cs @@ -168,7 +168,7 @@ internal override bool IsAlwaysVisible { } internal override void MakeGetExpression(PythonBinder/*!*/ binder, Expression/*!*/ codeContext, DynamicMetaObject instance, DynamicMetaObject/*!*/ owner, ConditionalBuilder/*!*/ builder) { - if (!_info.IsPublic || _info.DeclaringType.ContainsGenericParameters()) { + if (!_info.IsPublic || _info.DeclaringType.ContainsGenericParameters) { // fallback to reflection base.MakeGetExpression(binder, codeContext, instance, owner, builder); } else if (instance == null) { @@ -203,7 +203,7 @@ private void DoSet(CodeContext context, object instance, object val, bool suppre PerfTrack.NoteEvent(PerfTrack.Categories.Fields, this); if (_info.IsInitOnly || _info.IsLiteral) { throw PythonOps.AttributeErrorForReadonlyAttribute(_info.DeclaringType.Name, _info.Name); - } else if (!suppressWarning && instance != null && instance.GetType().IsValueType()) { + } else if (!suppressWarning && instance != null && instance.GetType().IsValueType) { PythonOps.Warn(context, PythonExceptions.RuntimeWarning, UpdateValueTypeFieldWarning, _info.Name, _info.DeclaringType.Name); }