diff --git a/Src/Microsoft.Dynamic/Actions/ActionBinder.cs b/Src/Microsoft.Dynamic/Actions/ActionBinder.cs index eec305d4..37795365 100644 --- a/Src/Microsoft.Dynamic/Actions/ActionBinder.cs +++ b/Src/Microsoft.Dynamic/Actions/ActionBinder.cs @@ -50,11 +50,11 @@ protected ActionBinder(ScriptDomainManager manager) { /// public virtual object Convert(object obj, Type toType) { if (obj == null) { - if (!toType.IsValueType()) { + if (!toType.IsValueType) { return null; } } else { - if (toType.IsValueType()) { + if (toType.IsValueType) { if (toType == obj.GetType()) { return obj; } @@ -89,7 +89,7 @@ public virtual Expression ConvertExpression(Expression expr, Type toType, Conver Type exprType = expr.Type; if (toType == typeof(object)) { - if (exprType.IsValueType()) { + if (exprType.IsValueType) { return AstUtils.Convert(expr, toType); } diff --git a/Src/Microsoft.Dynamic/Actions/Calls/OutArgBuilder.cs b/Src/Microsoft.Dynamic/Actions/Calls/OutArgBuilder.cs index db197c53..bd640aeb 100644 --- a/Src/Microsoft.Dynamic/Actions/Calls/OutArgBuilder.cs +++ b/Src/Microsoft.Dynamic/Actions/Calls/OutArgBuilder.cs @@ -49,7 +49,7 @@ internal override Expression ToReturnExpression(OverloadResolver resolver) { internal override Expression ByRefArgument => _isRef ? _tmp : null; private Expression GetDefaultValue() { - if (_parameterType.IsValueType()) { + if (_parameterType.IsValueType) { // default(T) return AstUtils.Constant(Activator.CreateInstance(_parameterType)); } diff --git a/Src/Microsoft.Dynamic/Actions/Calls/OverloadResolver.cs b/Src/Microsoft.Dynamic/Actions/Calls/OverloadResolver.cs index 70ceb117..4cb08023 100644 --- a/Src/Microsoft.Dynamic/Actions/Calls/OverloadResolver.cs +++ b/Src/Microsoft.Dynamic/Actions/Calls/OverloadResolver.cs @@ -590,7 +590,7 @@ private static bool IsOverloadedOnParameter(int argIndex, int argCount, IList)) { + if (toType.IsGenericType && toType.GetGenericTypeDefinition() == typeof(Nullable<>)) { return true; } - if (!toType.IsValueType()) { + if (!toType.IsValueType) { return true; } } diff --git a/Src/Microsoft.Dynamic/Actions/Calls/ParameterMapping.cs b/Src/Microsoft.Dynamic/Actions/Calls/ParameterMapping.cs index 170e809e..9d472f58 100644 --- a/Src/Microsoft.Dynamic/Actions/Calls/ParameterMapping.cs +++ b/Src/Microsoft.Dynamic/Actions/Calls/ParameterMapping.cs @@ -337,7 +337,7 @@ private static List GetBindableMembers(Type returnType, List break; } - curType = curType.GetBaseType(); + curType = curType.BaseType; } if (mis.Length == 1) { diff --git a/Src/Microsoft.Dynamic/Actions/Calls/ParamsDictArgBuilder.cs b/Src/Microsoft.Dynamic/Actions/Calls/ParamsDictArgBuilder.cs index 2306ea10..b1ab5c1b 100644 --- a/Src/Microsoft.Dynamic/Actions/Calls/ParamsDictArgBuilder.cs +++ b/Src/Microsoft.Dynamic/Actions/Calls/ParamsDictArgBuilder.cs @@ -89,7 +89,7 @@ private Func GetCreationDelegate(Type dictType) { if (dictType == typeof(IDictionary)) { func = BinderOps.MakeDictionary; - } else if (dictType.IsGenericType()) { + } else if (dictType.IsGenericType) { Type[] genArgs = dictType.GetGenericTypeArguments(); if (dictType.GetGenericTypeDefinition() == typeof(IDictionary<,>) || dictType.GetGenericTypeDefinition() == typeof(Dictionary<,>)) { diff --git a/Src/Microsoft.Dynamic/Actions/Calls/TypeInferer.cs b/Src/Microsoft.Dynamic/Actions/Calls/TypeInferer.cs index 289049bd..2e5f9ec7 100644 --- a/Src/Microsoft.Dynamic/Actions/Calls/TypeInferer.cs +++ b/Src/Microsoft.Dynamic/Actions/Calls/TypeInferer.cs @@ -108,7 +108,7 @@ private static List CreateNewArgBuilders(MethodCandidate candidate, foreach (ArgBuilder oldArgBuilder in candidate.ArgBuilders) { var pi = oldArgBuilder.ParameterInfo; - if (pi != null && (pi.ParameterType.IsGenericParameter || pi.ParameterType.ContainsGenericParameters())) { + if (pi != null && (pi.ParameterType.IsGenericParameter || pi.ParameterType.ContainsGenericParameters)) { ArgBuilder replacement = oldArgBuilder.Clone(newOverload.Parameters[pi.Position]); if (replacement == null) { @@ -243,7 +243,7 @@ private static Dictionary> GetDependencyMapping(OverloadInfo in foreach (Type t in constraints) { if (t.IsGenericParameter) { AddDependency(dependencies, genArg, t); - } else if (t.ContainsGenericParameters()) { + } else if (t.ContainsGenericParameters) { AddNestedDependencies(dependencies, genArg, t); } } @@ -256,7 +256,7 @@ private static void AddNestedDependencies(Dictionary> dependenc foreach (Type innerArg in innerArgs) { if (innerArg.IsGenericParameter) { AddDependency(dependencies, genArg, innerArg); - } else if (innerArg.ContainsGenericParameters()) { + } else if (innerArg.ContainsGenericParameters) { AddNestedDependencies(dependencies, genArg, innerArg); } } @@ -295,7 +295,7 @@ private static void AddDependency(Dictionary> dependencies, Typ /// Adds any additional ArgumentInputs entries for the given object and parameter type. /// private static void AddOneInput(Dictionary inputs, DynamicMetaObject arg, Type paramType) { - if (paramType.ContainsGenericParameters()) { + if (paramType.ContainsGenericParameters) { List containedGenArgs = new List(); CollectGenericParameters(paramType, containedGenArgs); @@ -319,7 +319,7 @@ private static void CollectGenericParameters(Type type, List containedGenA if (!containedGenArgs.Contains(type)) { containedGenArgs.Add(type); } - } else if (type.ContainsGenericParameters()) { + } else if (type.ContainsGenericParameters) { if (type.IsArray || type.IsByRef) { CollectGenericParameters(type.GetElementType(), containedGenArgs); } else { @@ -446,7 +446,7 @@ public static Type GetInferedType(Type/*!*/ genericParameter, Type/*!*/ paramete return inputType; } - if (parameterType.IsInterface()) { + if (parameterType.IsInterface) { return GetInferedTypeForInterface(genericParameter, parameterType, inputType, binding); } @@ -464,11 +464,11 @@ public static Type GetInferedType(Type/*!*/ genericParameter, Type/*!*/ paramete // see if we're anywhere in our base class hierarchy Type genType = parameterType.GetGenericTypeDefinition(); while (argType != typeof(object)) { - if (argType.IsGenericType() && argType.GetGenericTypeDefinition() == genType) { + if (argType.IsGenericType && argType.GetGenericTypeDefinition() == genType) { // TODO: Merge w/ the interface logic? return binding[genericParameter] = MatchGenericParameter(genericParameter, argType, parameterType, binding); } - argType = argType.GetBaseType(); + argType = argType.BaseType; } return null; @@ -482,12 +482,12 @@ public static Type GetInferedType(Type/*!*/ genericParameter, Type/*!*/ paramete // Unless X == Y we can't infer T. // private static Type GetInferedTypeForInterface(Type/*!*/ genericParameter, Type/*!*/ interfaceType, Type inputType, Dictionary/*!*/ binding) { - Debug.Assert(interfaceType.IsInterface()); + Debug.Assert(interfaceType.IsInterface); Type match = null; Type genTypeDef = interfaceType.GetGenericTypeDefinition(); foreach (Type ifaceType in inputType.GetInterfaces()) { - if (ifaceType.IsGenericType() && ifaceType.GetGenericTypeDefinition() == genTypeDef) { + if (ifaceType.IsGenericType && ifaceType.GetGenericTypeDefinition() == genTypeDef) { if (!MatchGenericParameter(genericParameter, ifaceType, interfaceType, binding, ref match)) { return null; } diff --git a/Src/Microsoft.Dynamic/Actions/DefaultBinder.Conversions.cs b/Src/Microsoft.Dynamic/Actions/DefaultBinder.Conversions.cs index 63075749..140afcd7 100644 --- a/Src/Microsoft.Dynamic/Actions/DefaultBinder.Conversions.cs +++ b/Src/Microsoft.Dynamic/Actions/DefaultBinder.Conversions.cs @@ -41,7 +41,7 @@ public DynamicMetaObject ConvertTo(Type toType, ConversionResultKind kind, Dynam errorSuggestion ?? MakeErrorTarget(toType, kind, typeRestrictions, arg); - if ((kind == ConversionResultKind.ExplicitTry || kind == ConversionResultKind.ImplicitTry) && toType.IsValueType()) { + if ((kind == ConversionResultKind.ExplicitTry || kind == ConversionResultKind.ImplicitTry) && toType.IsValueType) { res = new DynamicMetaObject( AstUtils.Convert( res.Expression, @@ -60,7 +60,7 @@ public DynamicMetaObject ConvertTo(Type toType, ConversionResultKind kind, Dynam /// private static DynamicMetaObject TryConvertToObject(Type toType, Type knownType, DynamicMetaObject arg, BindingRestrictions restrictions) { if (toType == typeof(object)) { - if (knownType.IsValueType()) { + if (knownType.IsValueType) { return MakeBoxingTarget(arg, restrictions); } @@ -87,7 +87,7 @@ private DynamicMetaObject TryAllConversions(OverloadResolverFactory factory, Typ /// private static DynamicMetaObject TryAssignableConversion(Type toType, Type type, BindingRestrictions restrictions, DynamicMetaObject arg) { if (toType.IsAssignableFrom(type) || - (type == typeof(DynamicNull) && (toType.IsClass() || toType.IsInterface()))) { + (type == typeof(DynamicNull) && (toType.IsClass || toType.IsInterface))) { // MakeSimpleConversionTarget handles the ConversionResultKind check return MakeSimpleConversionTarget(toType, restrictions, arg); } @@ -180,7 +180,7 @@ private static DynamicMetaObject TryExtensibleConversion(Type toType, Type type, /// private static DynamicMetaObject TryImplicitNumericConversion(Type toType, Type type, BindingRestrictions restrictions, DynamicMetaObject arg) { Type checkType = type; - if (type.IsGenericType() && type.GetGenericTypeDefinition() == typeof(Extensible<>)) { + if (type.IsGenericType && type.GetGenericTypeDefinition() == typeof(Extensible<>)) { checkType = type.GetGenericArguments()[0]; } @@ -205,7 +205,7 @@ private static DynamicMetaObject TryImplicitNumericConversion(Type toType, Type /// Checks if there's a conversion to/from Nullable of T. /// private DynamicMetaObject TryNullableConversion(OverloadResolverFactory factory, Type toType, ConversionResultKind kind, Type knownType, BindingRestrictions restrictions, DynamicMetaObject arg) { - if (toType.IsGenericType() && toType.GetGenericTypeDefinition() == typeof(Nullable<>)) { + if (toType.IsGenericType && toType.GetGenericTypeDefinition() == typeof(Nullable<>)) { if (knownType == typeof(DynamicNull)) { // null -> Nullable return MakeNullToNullableOfTTarget(toType, restrictions); @@ -230,7 +230,7 @@ private DynamicMetaObject TryNullableConversion(OverloadResolverFactory factory, /// Checks to see if there's a conversion of null to a reference type /// private static DynamicMetaObject TryNullConversion(Type toType, Type knownType, BindingRestrictions restrictions) { - if (knownType == typeof(DynamicNull) && !toType.IsValueType()) { + if (knownType == typeof(DynamicNull) && !toType.IsValueType) { return MakeNullTarget(toType, restrictions); } return null; @@ -455,19 +455,12 @@ private DynamicMetaObject MakeConvertingToTToNullableOfTTarget(OverloadResolverF } /// - /// Returns a value which indicates failure when a OldConvertToAction of ImplicitTry or - /// ExplicitTry. + /// Returns a value which indicates failure when a OldConvertToAction of ImplicitTry or ExplicitTry. /// - public static Expression GetTryConvertReturnValue(Type type) { - Expression res; - if (type.IsInterface() || type.IsClass()) { - res = AstUtils.Constant(null, type); - } else { - res = AstUtils.Constant(null); - } - - return res; - } + public static Expression GetTryConvertReturnValue(Type type) => + type.IsInterface || type.IsClass + ? AstUtils.Constant(null, type) + : AstUtils.Constant(null); /// /// Helper to extract the Value of an Extensible of T from the @@ -492,10 +485,10 @@ private static Expression GetExtensibleValue(Type extType, DynamicMetaObject arg private static Type GetUnderlyingType(Type fromType) { Type curType = fromType; do { - if (curType.IsGenericType() && curType.GetGenericTypeDefinition() == typeof(Extensible<>)) { + if (curType.IsGenericType && curType.GetGenericTypeDefinition() == typeof(Extensible<>)) { fromType = curType.GetGenericArguments()[0]; } - curType = curType.GetBaseType(); + curType = curType.BaseType; } while (curType != null); return fromType; } diff --git a/Src/Microsoft.Dynamic/Actions/DefaultBinder.GetMember.cs b/Src/Microsoft.Dynamic/Actions/DefaultBinder.GetMember.cs index f3062f00..0a5d3ace 100644 --- a/Src/Microsoft.Dynamic/Actions/DefaultBinder.GetMember.cs +++ b/Src/Microsoft.Dynamic/Actions/DefaultBinder.GetMember.cs @@ -195,7 +195,7 @@ private DynamicMetaObject MakeGetMemberTarget(GetMemberInfo getMemInfo, DynamicM // Throws an exception if we don't have a non-generic type, and if we do report an error now. This matches // the rule version of the default binder but should probably be removed long term. EnsureTrackerRepresentsNonGenericType((TypeTracker)target.Value); - } else if (targetType.IsInterface()) { + } else if (targetType.IsInterface) { // all interfaces have object members targetType = typeof(object); members = GetMember(MemberRequestKind.Get, targetType, getMemInfo.Name); diff --git a/Src/Microsoft.Dynamic/Actions/DefaultBinder.Invoke.cs b/Src/Microsoft.Dynamic/Actions/DefaultBinder.Invoke.cs index 6d176d8a..e8966fc4 100644 --- a/Src/Microsoft.Dynamic/Actions/DefaultBinder.Invoke.cs +++ b/Src/Microsoft.Dynamic/Actions/DefaultBinder.Invoke.cs @@ -68,7 +68,7 @@ public DynamicMetaObject Call(CallSignature signature, DynamicMetaObject errorSu if (targetInfo != null) { // we're calling a well-known MethodBase DynamicMetaObject res = MakeMetaMethodCall(signature, resolverFactory, targetInfo); - if (res.Expression.Type.IsValueType()) { + if (res.Expression.Type.IsValueType) { res = new DynamicMetaObject( AstUtils.Convert(res.Expression, typeof(object)), res.Restrictions diff --git a/Src/Microsoft.Dynamic/Actions/DefaultBinder.Operations.cs b/Src/Microsoft.Dynamic/Actions/DefaultBinder.Operations.cs index 551f1d2e..fe45498d 100644 --- a/Src/Microsoft.Dynamic/Actions/DefaultBinder.Operations.cs +++ b/Src/Microsoft.Dynamic/Actions/DefaultBinder.Operations.cs @@ -254,7 +254,7 @@ private static DynamicMetaObject TryNullComparisonRule(DynamicMetaObject[] args) BindingRestrictions restrictions = BindingRestrictionsHelpers.GetRuntimeTypeRestriction(args[0].Expression, args[0].GetLimitType()).Merge(BindingRestrictions.Combine(args)); if (args[0].GetLimitType() == typeof(DynamicNull)) { - if (!otherType.IsValueType()) { + if (!otherType.IsValueType) { return new DynamicMetaObject( Expression.Equal(args[0].Expression, AstUtils.Constant(null)), restrictions @@ -268,7 +268,7 @@ private static DynamicMetaObject TryNullComparisonRule(DynamicMetaObject[] args) ); } } else if (otherType == typeof(DynamicNull)) { - if (!args[0].GetLimitType().IsValueType()) { + if (!args[0].GetLimitType().IsValueType) { return new DynamicMetaObject( Expression.Equal(args[0].Expression, AstUtils.Constant(null)), restrictions diff --git a/Src/Microsoft.Dynamic/Actions/DefaultBinder.SetMember.cs b/Src/Microsoft.Dynamic/Actions/DefaultBinder.SetMember.cs index 36155f8f..4ee24071 100644 --- a/Src/Microsoft.Dynamic/Actions/DefaultBinder.SetMember.cs +++ b/Src/Microsoft.Dynamic/Actions/DefaultBinder.SetMember.cs @@ -267,7 +267,7 @@ private void MakePropertyRule(SetOrDeleteMemberInfo memInfo, DynamicMetaObject i memInfo.Body.FinishCondition( MakeGenericPropertyExpression(memInfo) ); - } else if (setter.IsPublic && !setter.DeclaringType.IsValueType()) { + } else if (setter.IsPublic && !setter.DeclaringType.IsValueType) { if (instance == null) { memInfo.Body.FinishCondition( Expression.Block( @@ -327,7 +327,7 @@ private void MakeFieldRule(SetOrDeleteMemberInfo memInfo, DynamicMetaObject inst FieldTracker field = (FieldTracker)fields[0]; // TODO: Tmp variable for target - if (instance != null && field.DeclaringType.IsGenericType() && field.DeclaringType.GetGenericTypeDefinition() == typeof(StrongBox<>)) { + if (instance != null && field.DeclaringType.IsGenericType && field.DeclaringType.GetGenericTypeDefinition() == typeof(StrongBox<>)) { // work around a CLR bug where we can't access generic fields from dynamic methods. Type[] generic = field.DeclaringType.GetGenericArguments(); memInfo.Body.FinishCondition( @@ -356,14 +356,14 @@ private void MakeFieldRule(SetOrDeleteMemberInfo memInfo, DynamicMetaObject inst typeof(object) ) ); - } else if (field.DeclaringType.IsValueType() && !field.IsStatic) { + } else if (field.DeclaringType.IsValueType && !field.IsStatic) { memInfo.Body.FinishError( errorSuggestion ?? MakeError( MakeSetValueTypeFieldError(field, instance, target), typeof(object) ) ); - } else if (field.IsPublic && field.DeclaringType.IsVisible()) { + } else if (field.IsPublic && field.DeclaringType.IsVisible) { if (!field.IsStatic && instance == null) { memInfo.Body.FinishError( Expression.Throw( diff --git a/Src/Microsoft.Dynamic/Actions/DefaultBinder.cs b/Src/Microsoft.Dynamic/Actions/DefaultBinder.cs index af5ac0bb..f7837fd6 100644 --- a/Src/Microsoft.Dynamic/Actions/DefaultBinder.cs +++ b/Src/Microsoft.Dynamic/Actions/DefaultBinder.cs @@ -172,7 +172,7 @@ public MethodInfo GetMethod(Type type, string name) { return mi; } - curType = curType.GetBaseType(); + curType = curType.BaseType; } while (curType != null); return null; diff --git a/Src/Microsoft.Dynamic/Actions/FieldTracker.cs b/Src/Microsoft.Dynamic/Actions/FieldTracker.cs index 9694426d..9d907344 100644 --- a/Src/Microsoft.Dynamic/Actions/FieldTracker.cs +++ b/Src/Microsoft.Dynamic/Actions/FieldTracker.cs @@ -58,11 +58,11 @@ public override DynamicMetaObject GetValue(OverloadResolverFactory resolverFacto return binder.ReturnMemberTracker(type, this); } - if (Field.DeclaringType.ContainsGenericParameters()) { + if (Field.DeclaringType.ContainsGenericParameters) { return null; } - if (IsPublic && DeclaringType.IsPublic()) { + if (IsPublic && DeclaringType.IsPublic) { return new DynamicMetaObject( Expression.Convert(Expression.Field(null, Field), typeof(object)), BindingRestrictions.Empty @@ -82,7 +82,7 @@ public override DynamicMetaObject GetValue(OverloadResolverFactory resolverFacto public override ErrorInfo GetError(ActionBinder binder, Type instanceType) { // FieldTracker only has one error - accessing a static field from // a generic type. - Debug.Assert(Field.DeclaringType.ContainsGenericParameters()); + Debug.Assert(Field.DeclaringType.ContainsGenericParameters); return binder.MakeContainsGenericParametersError(this); } @@ -92,7 +92,7 @@ public override ErrorInfo GetError(ActionBinder binder, Type instanceType) { #region Internal expression builders protected internal override DynamicMetaObject GetBoundValue(OverloadResolverFactory resolverFactory, ActionBinder binder, Type type, DynamicMetaObject instance) { - if (IsPublic && DeclaringType.IsVisible()) { + if (IsPublic && DeclaringType.IsVisible) { return new DynamicMetaObject( AstUtils.Convert( Expression.Field( diff --git a/Src/Microsoft.Dynamic/Actions/MethodTracker.cs b/Src/Microsoft.Dynamic/Actions/MethodTracker.cs index a10d16ea..ef9f6461 100644 --- a/Src/Microsoft.Dynamic/Actions/MethodTracker.cs +++ b/Src/Microsoft.Dynamic/Actions/MethodTracker.cs @@ -57,7 +57,7 @@ protected internal override DynamicMetaObject GetBoundValue(OverloadResolverFact } internal override DynamicMetaObject Call(OverloadResolverFactory resolverFactory, ActionBinder binder, params DynamicMetaObject[] arguments) { - if (Method.IsPublic && Method.DeclaringType.IsVisible()) { + if (Method.IsPublic && Method.DeclaringType.IsVisible) { return binder.MakeCallExpression(resolverFactory, Method, arguments); } diff --git a/Src/Microsoft.Dynamic/Actions/NamespaceTracker.cs b/Src/Microsoft.Dynamic/Actions/NamespaceTracker.cs index f7f45e96..e7520883 100644 --- a/Src/Microsoft.Dynamic/Actions/NamespaceTracker.cs +++ b/Src/Microsoft.Dynamic/Actions/NamespaceTracker.cs @@ -210,7 +210,7 @@ private MemberTracker CheckForUnlistedType(string nameString) { continue; } - bool publishType = type.IsPublic() || _topPackage.DomainManager.Configuration.PrivateBinding; + bool publishType = type.IsPublic || _topPackage.DomainManager.Configuration.PrivateBinding; if (!publishType) { continue; } diff --git a/Src/Microsoft.Dynamic/Actions/NestedTypeTracker.cs b/Src/Microsoft.Dynamic/Actions/NestedTypeTracker.cs index 601230ac..9d233fe9 100644 --- a/Src/Microsoft.Dynamic/Actions/NestedTypeTracker.cs +++ b/Src/Microsoft.Dynamic/Actions/NestedTypeTracker.cs @@ -20,11 +20,11 @@ public NestedTypeTracker(Type type) { public override string Name => _type.Name; - public override bool IsPublic => _type.IsPublic(); + public override bool IsPublic => _type.IsPublic; public override Type Type => _type; - public override bool IsGenericType => _type.IsGenericType(); + public override bool IsGenericType => _type.IsGenericType; public override string ToString() { return _type.ToString(); diff --git a/Src/Microsoft.Dynamic/Actions/PropertyTracker.cs b/Src/Microsoft.Dynamic/Actions/PropertyTracker.cs index f584b704..7c019462 100644 --- a/Src/Microsoft.Dynamic/Actions/PropertyTracker.cs +++ b/Src/Microsoft.Dynamic/Actions/PropertyTracker.cs @@ -58,7 +58,7 @@ public override DynamicMetaObject GetValue(OverloadResolverFactory resolverFacto return null; } - if (getter.IsPublic && getter.DeclaringType.IsPublic()) { + if (getter.IsPublic && getter.DeclaringType.IsPublic) { return binder.MakeCallExpression(resolverFactory, getter); } diff --git a/Src/Microsoft.Dynamic/Actions/TypeGroup.cs b/Src/Microsoft.Dynamic/Actions/TypeGroup.cs index 1d83bb20..2ddf23f9 100644 --- a/Src/Microsoft.Dynamic/Actions/TypeGroup.cs +++ b/Src/Microsoft.Dynamic/Actions/TypeGroup.cs @@ -117,11 +117,11 @@ public static TypeTracker UpdateTypeEntity(TypeTracker existingTypeEntity, TypeT /// Gets the arity of generic parameters private static int GetGenericArity(Type type) { - if (!type.IsGenericType()) { + if (!type.IsGenericType) { return 0; } - Debug.Assert(type.IsGenericTypeDefinition()); + Debug.Assert(type.IsGenericTypeDefinition); return type.GetGenericArguments().Length; } @@ -178,7 +178,7 @@ private Type SampleType { /// This will return the result only for the non-generic type if one exists, and will throw /// an exception if all types in the TypeGroup are generic /// - public override bool IsPublic => GetNonGenericType().IsPublic(); + public override bool IsPublic => GetNonGenericType().IsPublic; #endregion } diff --git a/Src/Microsoft.Dynamic/Ast/GeneratorExpression.cs b/Src/Microsoft.Dynamic/Ast/GeneratorExpression.cs index 0a6bf153..bb51beca 100644 --- a/Src/Microsoft.Dynamic/Ast/GeneratorExpression.cs +++ b/Src/Microsoft.Dynamic/Ast/GeneratorExpression.cs @@ -105,7 +105,7 @@ public static GeneratorExpression Generator(string name, LabelTarget label, Expr // Generator type must be one of: IEnumerable, IEnumerator, // IEnumerable, or IEnumerator, where T is label.Ttpe - if (type.IsGenericType()) { + if (type.IsGenericType) { Type genType = type.GetGenericTypeDefinition(); if (genType != typeof(IEnumerable<>) && genType != typeof(IEnumerator<>) || type.GetGenericArguments()[0] != label.Type) { @@ -127,7 +127,7 @@ private static ArgumentException GeneratorTypeMustBeEnumerableOfT(Type type) { internal static bool IsEnumerableType(Type type) { return type == typeof(IEnumerable) || - type.IsGenericType() && type.GetGenericTypeDefinition() == typeof(IEnumerable<>); + type.IsGenericType && type.GetGenericTypeDefinition() == typeof(IEnumerable<>); } #region Generator lambda factories diff --git a/Src/Microsoft.Dynamic/Ast/MethodCallExpression.cs b/Src/Microsoft.Dynamic/Ast/MethodCallExpression.cs index f644ad35..664a32ab 100644 --- a/Src/Microsoft.Dynamic/Ast/MethodCallExpression.cs +++ b/Src/Microsoft.Dynamic/Ast/MethodCallExpression.cs @@ -102,7 +102,7 @@ private static Expression ArgumentConvertHelper(Expression argument, Type type) private static bool CompatibleParameterTypes(Type parameter, Type argument) { if (parameter == argument || - (!parameter.IsValueType() && !argument.IsValueType() && parameter.IsAssignableFrom(argument))) { + (!parameter.IsValueType && !argument.IsValueType && parameter.IsAssignableFrom(argument))) { return true; } if (parameter.IsByRef && parameter.GetElementType() == argument) { diff --git a/Src/Microsoft.Dynamic/Generation/CompilerHelpers.cs b/Src/Microsoft.Dynamic/Generation/CompilerHelpers.cs index 31c17761..5a46edc2 100644 --- a/Src/Microsoft.Dynamic/Generation/CompilerHelpers.cs +++ b/Src/Microsoft.Dynamic/Generation/CompilerHelpers.cs @@ -39,18 +39,18 @@ public static object GetMissingValue(Type type) { ContractUtils.RequiresNotNull(type, nameof(type)); if (type.IsByRef) type = type.GetElementType(); - if (type.IsEnum()) return Activator.CreateInstance(type); + if (type.IsEnum) return Activator.CreateInstance(type); switch (type.GetTypeCode()) { default: case TypeCode.Object: // struct - if (type.IsSealed() && type.IsValueType()) { + if (type.IsSealed && type.IsValueType) { return Activator.CreateInstance(type); } else if (type == typeof(object)) { // parameter of type object receives the actual Missing value return Missing.Value; - } else if (!type.IsValueType()) { + } else if (!type.IsValueType) { return null; } else { throw Error.CantCreateDefaultTypeFor(type); @@ -160,7 +160,7 @@ public static bool CanOptimizeMethod(MethodBase method) { if (method.ContainsGenericParameters || method.IsProtected() || method.IsPrivate || - !method.DeclaringType.IsVisible()) { + !method.DeclaringType.IsVisible) { return false; } return true; @@ -174,14 +174,14 @@ public static bool CanOptimizeMethod(MethodBase method) { /// Returns the original method if the method if a public version cannot be found. /// public static MethodInfo TryGetCallableMethod(Type targetType, MethodInfo method) { - if (method.DeclaringType == null || method.DeclaringType.IsVisible()) { + if (method.DeclaringType == null || method.DeclaringType.IsVisible) { return method; } // first try and get it from the base type we're overriding... MethodInfo baseMethod = method.GetRuntimeBaseDefinition(); - if (baseMethod.DeclaringType.IsVisible() || baseMethod.DeclaringType.IsInterface()) { + if (baseMethod.DeclaringType.IsVisible || baseMethod.DeclaringType.IsInterface) { // We need to instantiate the method as GetBaseDefinition might return a generic definition of the base method: if (baseMethod.IsGenericMethodDefinition) { baseMethod = baseMethod.MakeGenericMethod(method.GetGenericArguments()); @@ -191,8 +191,8 @@ public static MethodInfo TryGetCallableMethod(Type targetType, MethodInfo method // maybe we can get it from an interface on the type this // method came from... - foreach (Type iface in targetType.GetImplementedInterfaces()) { - if (iface.IsPublic()) { + foreach (Type iface in targetType.GetInterfaces()) { + if (iface.IsPublic) { InterfaceMapping mapping = targetType.GetInterfaceMap(iface); for (int i = 0; i < mapping.TargetMethods.Length; i++) { MethodInfo targetMethod = mapping.TargetMethods[i]; @@ -213,7 +213,7 @@ public static MethodInfo TryGetCallableMethod(Type targetType, MethodInfo method /// If no correct visible type can be found then the member is not visible and we won't call it. /// public static IEnumerable FilterNonVisibleMembers(Type targetType, IEnumerable members) { - if (targetType.IsVisible()) { + if (targetType.IsVisible) { return members; } @@ -301,11 +301,11 @@ public static bool MemberEquals(this MemberInfo self, MemberInfo other) { } public static bool IsVisible(MethodBase info) { - return info.IsPublic && (info.DeclaringType == null || info.DeclaringType.IsVisible()); + return info.IsPublic && (info.DeclaringType == null || info.DeclaringType.IsVisible); } public static bool IsVisible(FieldInfo info) { - return info.IsPublic && (info.DeclaringType == null || info.DeclaringType.IsVisible()); + return info.IsPublic && (info.DeclaringType == null || info.DeclaringType.IsVisible); } public static bool IsProtected(this MethodBase info) { @@ -325,8 +325,8 @@ public static Type GetVisibleType(object value) { } public static Type GetVisibleType(Type t) { - while (!t.IsVisible()) { - t = t.GetBaseType(); + while (!t.IsVisible) { + t = t.BaseType; } return t; } @@ -354,7 +354,7 @@ public static MethodBase[] GetConstructors(Type t, bool privateBinding, bool inc ctors = FilterConstructorsToPublicAndProtected(ctors); } - if (t.IsValueType()) { + if (t.IsValueType) { try { // certain types (e.g. ArgIterator) will fail with BadImageFormatException MethodBase structDefaultCtor = GetStructDefaultCtor(t); @@ -397,7 +397,7 @@ public static MethodInfo GetExplicitConverter(Type fromType, Type toType) { private static MethodInfo GetConverter(Type type, Type fromType, Type toType, string opMethodName) { foreach (MethodInfo mi in type.GetInheritedMembers(opMethodName).WithBindingFlags(BindingFlags.Public | BindingFlags.Static)) { - if ((mi.DeclaringType == null || mi.DeclaringType.IsVisible()) && mi.IsPublic && + if ((mi.DeclaringType == null || mi.DeclaringType.IsVisible) && mi.IsPublic && mi.ReturnType == toType && mi.GetParameters()[0].ParameterType.IsAssignableFrom(fromType)) { return mi; } @@ -415,7 +415,7 @@ public static bool TryImplicitConversion(Object value, Type to, out object resul if (CompilerHelpers.TryImplicitConvert(value, to, curType.GetInheritedMethods("op_Implicit").WithBindingFlags(BindingFlags.Public | BindingFlags.Static), out result)) { return true; } - curType = curType.GetBaseType(); + curType = curType.BaseType; } while (curType != null); return false; @@ -423,7 +423,7 @@ public static bool TryImplicitConversion(Object value, Type to, out object resul private static bool TryImplicitConvert(Object value, Type to, IEnumerable implicitConv, out object result) { foreach (MethodInfo mi in implicitConv) { - if (to.IsValueType() == mi.ReturnType.IsValueType() && to.IsAssignableFrom(mi.ReturnType)) { + if (to.IsValueType == mi.ReturnType.IsValueType && to.IsAssignableFrom(mi.ReturnType)) { if (mi.IsStatic) { result = mi.Invoke(null, new object[] { value }); } else { @@ -444,7 +444,7 @@ public static bool IsStrongBox(object target) { } public static bool IsStrongBox(Type t) { - return t.IsGenericType() && t.GetGenericTypeDefinition() == typeof(StrongBox<>); + return t.IsGenericType && t.GetGenericTypeDefinition() == typeof(StrongBox<>); } /// diff --git a/Src/Microsoft.Dynamic/Generation/ILGen.cs b/Src/Microsoft.Dynamic/Generation/ILGen.cs index 00e1a798..50dbfe24 100644 --- a/Src/Microsoft.Dynamic/Generation/ILGen.cs +++ b/Src/Microsoft.Dynamic/Generation/ILGen.cs @@ -361,7 +361,7 @@ public void EmitStoreArg(int index) { public void EmitLoadValueIndirect(Type type) { ContractUtils.RequiresNotNull(type, nameof(type)); - if (type.IsValueType()) { + if (type.IsValueType) { if (type == typeof(int)) { Emit(OpCodes.Ldind_I4); } else if (type == typeof(uint)) { @@ -397,7 +397,7 @@ public void EmitLoadValueIndirect(Type type) { public void EmitStoreValueIndirect(Type type) { ContractUtils.RequiresNotNull(type, nameof(type)); - if (type.IsValueType()) { + if (type.IsValueType) { if (type == typeof(int)) { Emit(OpCodes.Stind_I4); } else if (type == typeof(short)) { @@ -427,9 +427,9 @@ public void EmitStoreValueIndirect(Type type) { public void EmitLoadElement(Type type) { ContractUtils.RequiresNotNull(type, nameof(type)); - if (!type.IsValueType()) { + if (!type.IsValueType) { Emit(OpCodes.Ldelem_Ref); - } else if (type.IsEnum()) { + } else if (type.IsEnum) { Emit(OpCodes.Ldelem, type); } else { switch (type.GetTypeCode()) { @@ -476,7 +476,7 @@ public void EmitLoadElement(Type type) { public void EmitStoreElement(Type type) { ContractUtils.RequiresNotNull(type, nameof(type)); - if (type.IsEnum()) { + if (type.IsEnum) { Emit(OpCodes.Stelem, type); return; } @@ -506,7 +506,7 @@ public void EmitStoreElement(Type type) { Emit(OpCodes.Stelem_R8); break; default: - if (type.IsValueType()) { + if (type.IsValueType) { Emit(OpCodes.Stelem, type); } else { Emit(OpCodes.Stelem_Ref); @@ -585,7 +585,7 @@ public void EmitFieldSet(FieldInfo fi) { public void EmitNew(ConstructorInfo ci) { ContractUtils.RequiresNotNull(ci, nameof(ci)); - if (ci.DeclaringType.ContainsGenericParameters()) { + if (ci.DeclaringType.ContainsGenericParameters) { throw Error.IllegalNew_GenericParams(ci.DeclaringType); } @@ -605,7 +605,7 @@ public void EmitNew(Type type, Type[] paramTypes) { public void EmitCall(MethodInfo mi) { ContractUtils.RequiresNotNull(mi, nameof(mi)); - if (mi.IsVirtual && !mi.DeclaringType.IsValueType()) { + if (mi.IsVirtual && !mi.DeclaringType.IsValueType) { Emit(OpCodes.Callvirt, mi); } else { Emit(OpCodes.Call, mi); @@ -807,7 +807,7 @@ public static bool ShouldLdtoken(Type t) { return true; } #endif - return t.IsGenericParameter || t.IsVisible(); + return t.IsGenericParameter || t.IsVisible; } public static bool ShouldLdtoken(MethodBase mb) { @@ -915,19 +915,19 @@ private bool TryEmitCast(Type from, Type to, bool implicitOnly) { } } - if (from.IsValueType()) { + if (from.IsValueType) { if (to == typeof(object)) { EmitBoxing(from); return true; } } - if (to.IsInterface()) { + if (to.IsInterface) { Emit(OpCodes.Box, from); return true; } - if (from.IsEnum() && to == typeof(Enum)) { + if (from.IsEnum && to == typeof(Enum)) { Emit(OpCodes.Box, from); return true; } @@ -941,7 +941,7 @@ private bool TryEmitCast(Type from, Type to, bool implicitOnly) { return true; } - if (to.IsValueType() && from == typeof(object)) { + if (to.IsValueType && from == typeof(object)) { if (implicitOnly) { return false; } @@ -949,11 +949,11 @@ private bool TryEmitCast(Type from, Type to, bool implicitOnly) { return true; } - if (to.IsValueType() != from.IsValueType()) { + if (to.IsValueType != from.IsValueType) { return false; } - if (!to.IsValueType()) { + if (!to.IsValueType) { if (implicitOnly) { return false; } @@ -961,10 +961,10 @@ private bool TryEmitCast(Type from, Type to, bool implicitOnly) { return true; } - if (to.IsEnum()) { + if (to.IsEnum) { to = Enum.GetUnderlyingType(to); } - if (from.IsEnum()) { + if (from.IsEnum) { from = Enum.GetUnderlyingType(from); } @@ -1051,7 +1051,7 @@ public bool EmitNumericCast(Type from, Type to, bool implicitOnly) { public void EmitBoxing(Type type) { ContractUtils.RequiresNotNull(type, nameof(type)); - if (type.IsValueType()) { + if (type.IsValueType) { if (type == typeof(void)) { Emit(OpCodes.Ldnull); } else if (type == typeof(int)) { @@ -1106,8 +1106,8 @@ internal void EmitConvertToType(Type typeFrom, Type typeTo, bool isChecked) { Type nnExprType = typeFrom.GetNonNullableType(); Type nnType = typeTo.GetNonNullableType(); - if (typeFrom.IsInterface() || // interface cast - typeTo.IsInterface() || + if (typeFrom.IsInterface || // interface cast + typeTo.IsInterface || typeFrom == typeof(object) || // boxing cast typeTo == typeof(object)) { EmitCastToType(typeFrom, typeTo); @@ -1129,14 +1129,14 @@ internal void EmitConvertToType(Type typeFrom, Type typeTo, bool isChecked) { //CONFORMING private void EmitCastToType(Type typeFrom, Type typeTo) { - if (!typeFrom.IsValueType() && typeTo.IsValueType()) { + if (!typeFrom.IsValueType && typeTo.IsValueType) { Emit(OpCodes.Unbox_Any, typeTo); - } else if (typeFrom.IsValueType() && !typeTo.IsValueType()) { + } else if (typeFrom.IsValueType && !typeTo.IsValueType) { EmitBoxing(typeFrom); if (typeTo != typeof(object)) { Emit(OpCodes.Castclass, typeTo); } - } else if (!typeFrom.IsValueType() && !typeTo.IsValueType()) { + } else if (!typeFrom.IsValueType && !typeTo.IsValueType) { Emit(OpCodes.Castclass, typeTo); } else { throw Error.InvalidCast(typeFrom, typeTo); @@ -1321,7 +1321,7 @@ private void EmitNonNullableToNullableConversion(Type typeFrom, Type typeTo, boo private void EmitNullableToNonNullableConversion(Type typeFrom, Type typeTo, bool isChecked) { Debug.Assert(TypeUtils.IsNullableType(typeFrom)); Debug.Assert(!TypeUtils.IsNullableType(typeTo)); - if (typeTo.IsValueType()) + if (typeTo.IsValueType) EmitNullableToNonNullableStructConversion(typeFrom, typeTo, isChecked); else EmitNullableToReferenceConversion(typeFrom); @@ -1331,7 +1331,7 @@ private void EmitNullableToNonNullableConversion(Type typeFrom, Type typeTo, boo private void EmitNullableToNonNullableStructConversion(Type typeFrom, Type typeTo, bool isChecked) { Debug.Assert(TypeUtils.IsNullableType(typeFrom)); Debug.Assert(!TypeUtils.IsNullableType(typeTo)); - Debug.Assert(typeTo.IsValueType()); + Debug.Assert(typeTo.IsValueType); LocalBuilder locFrom = null; locFrom = DeclareLocal(typeFrom); Emit(OpCodes.Stloc, locFrom); @@ -1365,21 +1365,21 @@ private void EmitNullableConversion(Type typeFrom, Type typeTo, bool isChecked) //CONFORMING internal void EmitHasValue(Type nullableType) { MethodInfo mi = nullableType.GetMethod("get_HasValue", BindingFlags.Instance | BindingFlags.Public); - Debug.Assert(nullableType.IsValueType()); + Debug.Assert(nullableType.IsValueType); Emit(OpCodes.Call, mi); } //CONFORMING internal void EmitGetValue(Type nullableType) { MethodInfo mi = nullableType.GetMethod("get_Value", BindingFlags.Instance | BindingFlags.Public); - Debug.Assert(nullableType.IsValueType()); + Debug.Assert(nullableType.IsValueType); Emit(OpCodes.Call, mi); } //CONFORMING internal void EmitGetValueOrDefault(Type nullableType) { MethodInfo mi = nullableType.GetMethod("GetValueOrDefault", ReflectionUtils.EmptyTypes); - Debug.Assert(nullableType.IsValueType()); + Debug.Assert(nullableType.IsValueType); Emit(OpCodes.Call, mi); } @@ -1486,10 +1486,10 @@ internal void EmitDefault(Type type) { switch (type.GetTypeCode()) { case TypeCode.Object: case TypeCode.DateTime: - if (type.IsValueType()) { + if (type.IsValueType) { // Type.GetTypeCode on an enum returns the underlying // integer TypeCode, so we won't get here. - Debug.Assert(!type.IsEnum()); + Debug.Assert(!type.IsEnum); // This is the IL for default(T) if T is a generic type // parameter, so it should work for any type. It's also @@ -1554,10 +1554,10 @@ public void EmitMissingValue(Type type) { if (type == typeof(object)) { // parameter of type object receives the actual Missing value Emit(OpCodes.Ldsfld, typeof(Missing).GetDeclaredField("Value")); - } else if (!type.IsValueType()) { + } else if (!type.IsValueType) { // reference type EmitNull(); - } else if (type.IsSealed() && !type.IsEnum()) { + } else if (type.IsSealed && !type.IsEnum) { lb = DeclareLocal(type); Emit(OpCodes.Ldloca, lb); Emit(OpCodes.Initobj, type); diff --git a/Src/Microsoft.Dynamic/Interpreter/Instructions/CallInstruction.Generated.cs b/Src/Microsoft.Dynamic/Interpreter/Instructions/CallInstruction.Generated.cs index e22bb187..d7db3bba 100644 --- a/Src/Microsoft.Dynamic/Interpreter/Instructions/CallInstruction.Generated.cs +++ b/Src/Microsoft.Dynamic/Interpreter/Instructions/CallInstruction.Generated.cs @@ -87,10 +87,10 @@ private static CallInstruction FastCreate(MethodInfo target, ParameterInfo[] pi) return new ActionCallInstruction(target); } - if (t.IsEnum()) return SlowCreate(target, pi); + if (t.IsEnum) return SlowCreate(target, pi); switch (t.GetTypeCode()) { case TypeCode.Object: { - if (t != typeof(object) && (IndexIsNotReturnType(0, target, pi) || t.IsValueType())) { + if (t != typeof(object) && (IndexIsNotReturnType(0, target, pi) || t.IsValueType)) { // if we're on the return type relaxed delegates makes it ok to use object goto default; } @@ -124,10 +124,10 @@ private static CallInstruction FastCreate(MethodInfo target, ParameterInfo[] return new FuncCallInstruction(target); } - if (t.IsEnum()) return SlowCreate(target, pi); + if (t.IsEnum) return SlowCreate(target, pi); switch (t.GetTypeCode()) { case TypeCode.Object: { - if (t != typeof(object) && (IndexIsNotReturnType(1, target, pi) || t.IsValueType())) { + if (t != typeof(object) && (IndexIsNotReturnType(1, target, pi) || t.IsValueType)) { // if we're on the return type relaxed delegates makes it ok to use object goto default; } @@ -161,11 +161,11 @@ private static CallInstruction FastCreate(MethodInfo target, ParameterIn return new FuncCallInstruction(target); } - if (t.IsEnum()) return SlowCreate(target, pi); + if (t.IsEnum) return SlowCreate(target, pi); switch (t.GetTypeCode()) { case TypeCode.Object: { Debug.Assert(pi.Length == 2); - if (t.IsValueType()) goto default; + if (t.IsValueType) goto default; return new FuncCallInstruction(target); } diff --git a/Src/Microsoft.Dynamic/Interpreter/Instructions/CallInstruction.cs b/Src/Microsoft.Dynamic/Interpreter/Instructions/CallInstruction.cs index 7f0d47c5..01c903f5 100644 --- a/Src/Microsoft.Dynamic/Interpreter/Instructions/CallInstruction.cs +++ b/Src/Microsoft.Dynamic/Interpreter/Instructions/CallInstruction.cs @@ -43,7 +43,7 @@ public static CallInstruction Create(MethodInfo info, ParameterInfo[] parameters return GetArrayAccessor(info, argumentCount); } - if (ReflectionUtils.IsDynamicMethod(info) || !info.IsStatic && info.DeclaringType.IsValueType()) { + if (ReflectionUtils.IsDynamicMethod(info) || !info.IsStatic && info.DeclaringType.IsValueType) { return new MethodInfoCallInstruction(info, argumentCount); } diff --git a/Src/Microsoft.Dynamic/Interpreter/Instructions/EqualInstruction.cs b/Src/Microsoft.Dynamic/Interpreter/Instructions/EqualInstruction.cs index 86490cf2..951ef68f 100644 --- a/Src/Microsoft.Dynamic/Interpreter/Instructions/EqualInstruction.cs +++ b/Src/Microsoft.Dynamic/Interpreter/Instructions/EqualInstruction.cs @@ -111,7 +111,7 @@ public override int Run(InterpretedFrame frame) { [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Maintainability", "CA1502:AvoidExcessiveComplexity")] public static Instruction Create(Type type) { // Boxed enums can be unboxed as their underlying types: - switch ((type.IsEnum() ? Enum.GetUnderlyingType(type) : type).GetTypeCode()) { + switch ((type.IsEnum ? Enum.GetUnderlyingType(type) : type).GetTypeCode()) { case TypeCode.Boolean: return _Boolean ?? (_Boolean = new EqualBoolean()); case TypeCode.SByte: return _SByte ?? (_SByte = new EqualSByte()); case TypeCode.Byte: return _Byte ?? (_Byte = new EqualByte()); @@ -128,7 +128,7 @@ public static Instruction Create(Type type) { case TypeCode.Double: return _Double ?? (_Double = new EqualDouble()); case TypeCode.Object: - if (!type.IsValueType()) { + if (!type.IsValueType) { return _Reference ?? (_Reference = new EqualReference()); } // TODO: Nullable @@ -143,4 +143,4 @@ public override string ToString() { return "Equal()"; } } -} \ No newline at end of file +} diff --git a/Src/Microsoft.Dynamic/Interpreter/Instructions/GreaterThanInstruction.cs b/Src/Microsoft.Dynamic/Interpreter/Instructions/GreaterThanInstruction.cs index a2e569b7..e9feba0c 100644 --- a/Src/Microsoft.Dynamic/Interpreter/Instructions/GreaterThanInstruction.cs +++ b/Src/Microsoft.Dynamic/Interpreter/Instructions/GreaterThanInstruction.cs @@ -106,7 +106,7 @@ public override int Run(InterpretedFrame frame) { } public static Instruction Create(Type type) { - Debug.Assert(!type.IsEnum()); + Debug.Assert(!type.IsEnum); switch (type.GetTypeCode()) { case TypeCode.SByte: return _SByte ?? (_SByte = new GreaterThanSByte()); case TypeCode.Byte: return _Byte ?? (_Byte = new GreaterThanByte()); diff --git a/Src/Microsoft.Dynamic/Interpreter/Instructions/InstructionList.cs b/Src/Microsoft.Dynamic/Interpreter/Instructions/InstructionList.cs index b3a58eb8..98958d16 100644 --- a/Src/Microsoft.Dynamic/Interpreter/Instructions/InstructionList.cs +++ b/Src/Microsoft.Dynamic/Interpreter/Instructions/InstructionList.cs @@ -571,7 +571,7 @@ public void EmitNewRuntimeVariables(int count) { public void EmitGetArrayItem(Type arrayType) { Type elementType = arrayType.GetElementType(); - if (elementType.IsClass() || elementType.IsInterface()) { + if (elementType.IsClass || elementType.IsInterface) { Emit(InstructionFactory.Factory.GetArrayItem()); } else { Emit(InstructionFactory.GetFactory(elementType).GetArrayItem()); @@ -580,7 +580,7 @@ public void EmitGetArrayItem(Type arrayType) { public void EmitSetArrayItem(Type arrayType) { Type elementType = arrayType.GetElementType(); - if (elementType.IsClass() || elementType.IsInterface()) { + if (elementType.IsClass || elementType.IsInterface) { Emit(InstructionFactory.Factory.SetArrayItem()); } else { Emit(InstructionFactory.GetFactory(elementType).SetArrayItem()); diff --git a/Src/Microsoft.Dynamic/Interpreter/Instructions/NotEqualInstruction.cs b/Src/Microsoft.Dynamic/Interpreter/Instructions/NotEqualInstruction.cs index de3512c3..97739777 100644 --- a/Src/Microsoft.Dynamic/Interpreter/Instructions/NotEqualInstruction.cs +++ b/Src/Microsoft.Dynamic/Interpreter/Instructions/NotEqualInstruction.cs @@ -111,7 +111,7 @@ public override int Run(InterpretedFrame frame) { [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Maintainability", "CA1502:AvoidExcessiveComplexity")] public static Instruction Create(Type type) { // Boxed enums can be unboxed as their underlying types: - switch ((type.IsEnum() ? Enum.GetUnderlyingType(type) : type).GetTypeCode()) { + switch ((type.IsEnum ? Enum.GetUnderlyingType(type) : type).GetTypeCode()) { case TypeCode.Boolean: return _Boolean ?? (_Boolean = new NotEqualBoolean()); case TypeCode.SByte: return _SByte ?? (_SByte = new NotEqualSByte()); case TypeCode.Byte: return _Byte ?? (_Byte = new NotEqualByte()); @@ -128,7 +128,7 @@ public static Instruction Create(Type type) { case TypeCode.Double: return _Double ?? (_Double = new NotEqualDouble()); case TypeCode.Object: - if (!type.IsValueType()) { + if (!type.IsValueType) { return _Reference ?? (_Reference = new NotEqualReference()); } // TODO: Nullable diff --git a/Src/Microsoft.Dynamic/Interpreter/LightCompiler.cs b/Src/Microsoft.Dynamic/Interpreter/LightCompiler.cs index 91430727..2454bf07 100644 --- a/Src/Microsoft.Dynamic/Interpreter/LightCompiler.cs +++ b/Src/Microsoft.Dynamic/Interpreter/LightCompiler.cs @@ -243,7 +243,7 @@ private void CompileDefaultExpression(Expression expr) { private void CompileDefaultExpression(Type type) { if (type == typeof(void)) return; - if (type.IsValueType()) { + if (type.IsValueType) { object value = ScriptingRuntimeHelpers.GetPrimitiveDefaultValue(type); if (value != null) { Instructions.EmitLoad(value); @@ -554,14 +554,14 @@ private void CompileBinaryExpression(Expression expr) { } private void CompileEqual(Expression left, Expression right) { - Debug.Assert(left.Type == right.Type || !left.Type.IsValueType() && !right.Type.IsValueType()); + Debug.Assert(left.Type == right.Type || !left.Type.IsValueType && !right.Type.IsValueType); Compile(left); Compile(right); Instructions.EmitEqual(left.Type); } private void CompileNotEqual(Expression left, Expression right) { - Debug.Assert(left.Type == right.Type || !left.Type.IsValueType() && !right.Type.IsValueType()); + Debug.Assert(left.Type == right.Type || !left.Type.IsValueType && !right.Type.IsValueType); Compile(left); Compile(right); Instructions.EmitNotEqual(left.Type); @@ -1168,7 +1168,7 @@ private void CompileMethodCallExpression(Expression expr) { // also could be a mutable value type, Delegate.CreateDelegate and MethodInfo.Invoke both can't handle this, we // need to generate code. if (!CollectionUtils.TrueForAll(parameters, (p) => !p.ParameterType.IsByRef) || - (!node.Method.IsStatic && node.Method.DeclaringType.IsValueType() && !node.Method.DeclaringType.IsPrimitive())) { + (!node.Method.IsStatic && node.Method.DeclaringType.IsValueType && !node.Method.DeclaringType.IsPrimitive)) { _forceCompile = true; } @@ -1227,7 +1227,7 @@ private void CompileNewExpression(Expression expr) { } Instructions.EmitNew(node.Constructor); } else { - Debug.Assert(expr.Type.IsValueType()); + Debug.Assert(expr.Type.IsValueType); Instructions.EmitDefaultValue(node.Type); } } @@ -1413,7 +1413,7 @@ private void CompileTypeIsExpression(Expression expr) { Compile(node.Expression); // use TypeEqual for sealed types: - if (node.TypeOperand.IsSealed()) { + if (node.TypeOperand.IsSealed) { Instructions.EmitLoad(node.TypeOperand); Instructions.EmitTypeEquals(); } else { diff --git a/Src/Microsoft.Dynamic/Runtime/Cast.Generated.cs b/Src/Microsoft.Dynamic/Runtime/Cast.Generated.cs index 782c1af6..47b4e581 100644 --- a/Src/Microsoft.Dynamic/Runtime/Cast.Generated.cs +++ b/Src/Microsoft.Dynamic/Runtime/Cast.Generated.cs @@ -58,7 +58,7 @@ public static Byte ExplicitCastToByte(object o) { return (Byte)(Char)o; } else if (type == DecimalType) { return (Byte)(Decimal)o; - } else if (type.IsEnum()) { + } else if (type.IsEnum) { return (Byte)ExplicitCastEnumToByte(o); } else if (type == NullableInt32Type) { return (Byte)(Nullable)o; @@ -116,7 +116,7 @@ public static Char ExplicitCastToChar(object o) { return (Char)(Char)o; } else if (type == DecimalType) { return (Char)(Decimal)o; - } else if (type.IsEnum()) { + } else if (type.IsEnum) { return (Char)ExplicitCastEnumToInt32(o); } else if (type == NullableInt32Type) { return (Char)(Nullable)o; @@ -174,7 +174,7 @@ public static Decimal ExplicitCastToDecimal(object o) { return (Decimal)(Char)o; } else if (type == DecimalType) { return (Decimal)(Decimal)o; - } else if (type.IsEnum()) { + } else if (type.IsEnum) { return (Decimal)ExplicitCastEnumToInt64(o); } else if (type == NullableInt32Type) { return (Decimal)(Nullable)o; @@ -232,7 +232,7 @@ public static Double ExplicitCastToDouble(object o) { return (Double)(Char)o; } else if (type == DecimalType) { return (Double)(Decimal)o; - } else if (type.IsEnum()) { + } else if (type.IsEnum) { return (Double)ExplicitCastEnumToInt64(o); } else if (type == NullableInt32Type) { return (Double)(Nullable)o; @@ -290,7 +290,7 @@ public static Int16 ExplicitCastToInt16(object o) { return (Int16)(Char)o; } else if (type == DecimalType) { return (Int16)(Decimal)o; - } else if (type.IsEnum()) { + } else if (type.IsEnum) { return (Int16)ExplicitCastEnumToInt16(o); } else if (type == NullableInt32Type) { return (Int16)(Nullable)o; @@ -348,7 +348,7 @@ public static Int32 ExplicitCastToInt32(object o) { return (Int32)(Char)o; } else if (type == DecimalType) { return (Int32)(Decimal)o; - } else if (type.IsEnum()) { + } else if (type.IsEnum) { return (Int32)ExplicitCastEnumToInt32(o); } else if (type == NullableInt32Type) { return (Int32)(Nullable)o; @@ -406,7 +406,7 @@ public static Int64 ExplicitCastToInt64(object o) { return (Int64)(Char)o; } else if (type == DecimalType) { return (Int64)(Decimal)o; - } else if (type.IsEnum()) { + } else if (type.IsEnum) { return (Int64)ExplicitCastEnumToInt64(o); } else if (type == NullableInt32Type) { return (Int64)(Nullable)o; @@ -465,7 +465,7 @@ public static SByte ExplicitCastToSByte(object o) { return (SByte)(Char)o; } else if (type == DecimalType) { return (SByte)(Decimal)o; - } else if (type.IsEnum()) { + } else if (type.IsEnum) { return (SByte)ExplicitCastEnumToSByte(o); } else if (type == NullableInt32Type) { return (SByte)(Nullable)o; @@ -523,7 +523,7 @@ public static Single ExplicitCastToSingle(object o) { return (Single)(Char)o; } else if (type == DecimalType) { return (Single)(Decimal)o; - } else if (type.IsEnum()) { + } else if (type.IsEnum) { return (Single)ExplicitCastEnumToInt64(o); } else if (type == NullableInt32Type) { return (Single)(Nullable)o; @@ -582,7 +582,7 @@ public static UInt16 ExplicitCastToUInt16(object o) { return (UInt16)(Char)o; } else if (type == DecimalType) { return (UInt16)(Decimal)o; - } else if (type.IsEnum()) { + } else if (type.IsEnum) { return (UInt16)ExplicitCastEnumToUInt16(o); } else if (type == NullableInt32Type) { return (UInt16)(Nullable)o; @@ -641,7 +641,7 @@ public static UInt32 ExplicitCastToUInt32(object o) { return (UInt32)(Char)o; } else if (type == DecimalType) { return (UInt32)(Decimal)o; - } else if (type.IsEnum()) { + } else if (type.IsEnum) { return (UInt32)ExplicitCastEnumToUInt32(o); } else if (type == NullableInt32Type) { return (UInt32)(Nullable)o; @@ -700,7 +700,7 @@ public static UInt64 ExplicitCastToUInt64(object o) { return (UInt64)(Char)o; } else if (type == DecimalType) { return (UInt64)(Decimal)o; - } else if (type.IsEnum()) { + } else if (type.IsEnum) { return (UInt64)ExplicitCastEnumToUInt64(o); } else if (type == NullableInt32Type) { return (UInt64)(Nullable)o; @@ -773,7 +773,7 @@ public static Nullable ExplicitCastToNullableByte(object o) { return (Nullable)(Char)o; } else if (type == DecimalType) { return (Nullable)(Decimal)o; - } else if (type.IsEnum()) { + } else if (type.IsEnum) { return (Nullable)ExplicitCastEnumToByte(o); } else if (type == NullableInt32Type) { return (Nullable)(Nullable)o; @@ -832,7 +832,7 @@ public static Nullable ExplicitCastToNullableChar(object o) { return (Nullable)(Char)o; } else if (type == DecimalType) { return (Nullable)(Decimal)o; - } else if (type.IsEnum()) { + } else if (type.IsEnum) { return (Nullable)ExplicitCastEnumToInt32(o); } else if (type == NullableInt32Type) { return (Nullable)(Nullable)o; @@ -891,7 +891,7 @@ public static Nullable ExplicitCastToNullableDecimal(object o) { return (Nullable)(Char)o; } else if (type == DecimalType) { return (Nullable)(Decimal)o; - } else if (type.IsEnum()) { + } else if (type.IsEnum) { return (Nullable)ExplicitCastEnumToInt64(o); } else if (type == NullableInt32Type) { return (Nullable)(Nullable)o; @@ -950,7 +950,7 @@ public static Nullable ExplicitCastToNullableDouble(object o) { return (Nullable)(Char)o; } else if (type == DecimalType) { return (Nullable)(Decimal)o; - } else if (type.IsEnum()) { + } else if (type.IsEnum) { return (Nullable)ExplicitCastEnumToInt64(o); } else if (type == NullableInt32Type) { return (Nullable)(Nullable)o; @@ -1009,7 +1009,7 @@ public static Nullable ExplicitCastToNullableInt16(object o) { return (Nullable)(Char)o; } else if (type == DecimalType) { return (Nullable)(Decimal)o; - } else if (type.IsEnum()) { + } else if (type.IsEnum) { return (Nullable)ExplicitCastEnumToInt16(o); } else if (type == NullableInt32Type) { return (Nullable)(Nullable)o; @@ -1068,7 +1068,7 @@ public static Nullable ExplicitCastToNullableInt32(object o) { return (Nullable)(Char)o; } else if (type == DecimalType) { return (Nullable)(Decimal)o; - } else if (type.IsEnum()) { + } else if (type.IsEnum) { return (Nullable)ExplicitCastEnumToInt32(o); } else if (type == NullableInt32Type) { return (Nullable)(Nullable)o; @@ -1127,7 +1127,7 @@ public static Nullable ExplicitCastToNullableInt64(object o) { return (Nullable)(Char)o; } else if (type == DecimalType) { return (Nullable)(Decimal)o; - } else if (type.IsEnum()) { + } else if (type.IsEnum) { return (Nullable)ExplicitCastEnumToInt64(o); } else if (type == NullableInt32Type) { return (Nullable)(Nullable)o; @@ -1187,7 +1187,7 @@ public static Nullable ExplicitCastToNullableSByte(object o) { return (Nullable)(Char)o; } else if (type == DecimalType) { return (Nullable)(Decimal)o; - } else if (type.IsEnum()) { + } else if (type.IsEnum) { return (Nullable)ExplicitCastEnumToSByte(o); } else if (type == NullableInt32Type) { return (Nullable)(Nullable)o; @@ -1246,7 +1246,7 @@ public static Nullable ExplicitCastToNullableSingle(object o) { return (Nullable)(Char)o; } else if (type == DecimalType) { return (Nullable)(Decimal)o; - } else if (type.IsEnum()) { + } else if (type.IsEnum) { return (Nullable)ExplicitCastEnumToInt64(o); } else if (type == NullableInt32Type) { return (Nullable)(Nullable)o; @@ -1306,7 +1306,7 @@ public static Nullable ExplicitCastToNullableUInt16(object o) { return (Nullable)(Char)o; } else if (type == DecimalType) { return (Nullable)(Decimal)o; - } else if (type.IsEnum()) { + } else if (type.IsEnum) { return (Nullable)ExplicitCastEnumToUInt16(o); } else if (type == NullableInt32Type) { return (Nullable)(Nullable)o; @@ -1366,7 +1366,7 @@ public static Nullable ExplicitCastToNullableUInt32(object o) { return (Nullable)(Char)o; } else if (type == DecimalType) { return (Nullable)(Decimal)o; - } else if (type.IsEnum()) { + } else if (type.IsEnum) { return (Nullable)ExplicitCastEnumToUInt32(o); } else if (type == NullableInt32Type) { return (Nullable)(Nullable)o; @@ -1426,7 +1426,7 @@ public static Nullable ExplicitCastToNullableUInt64(object o) { return (Nullable)(Char)o; } else if (type == DecimalType) { return (Nullable)(Decimal)o; - } else if (type.IsEnum()) { + } else if (type.IsEnum) { return (Nullable)ExplicitCastEnumToUInt64(o); } else if (type == NullableInt32Type) { return (Nullable)(Nullable)o; diff --git a/Src/Microsoft.Dynamic/Runtime/Cast.cs b/Src/Microsoft.Dynamic/Runtime/Cast.cs index 1075b219..b8bc1e27 100644 --- a/Src/Microsoft.Dynamic/Runtime/Cast.cs +++ b/Src/Microsoft.Dynamic/Runtime/Cast.cs @@ -19,8 +19,8 @@ public static partial class Cast { public static object Explicit(object o, Type to) { if (o == null) { // Null objects can be only cast to Nullable or any reference type - if (to.IsValueType()) { - if (to.IsGenericType() && to.GetGenericTypeDefinition() == NullableType) { + if (to.IsValueType) { + if (to.IsGenericType && to.GetGenericTypeDefinition() == NullableType) { return NewNullableInstance(to.GetGenericArguments()[0]); } @@ -36,7 +36,7 @@ public static object Explicit(object o, Type to) { return null; } - if (to.IsValueType()) { + if (to.IsValueType) { return ExplicitCastToValueType(o, to); } diff --git a/Src/Microsoft.Dynamic/Runtime/MetaObjectExtensions.cs b/Src/Microsoft.Dynamic/Runtime/MetaObjectExtensions.cs index ed6ca25d..8374dc05 100644 --- a/Src/Microsoft.Dynamic/Runtime/MetaObjectExtensions.cs +++ b/Src/Microsoft.Dynamic/Runtime/MetaObjectExtensions.cs @@ -18,7 +18,7 @@ public static bool NeedsDeferral(this DynamicMetaObject self) { return false; } - if (self.Expression.Type.IsSealed()) { + if (self.Expression.Type.IsSealed) { return typeof(IDynamicMetaObjectProvider).IsAssignableFrom(self.Expression.Type); } @@ -34,7 +34,7 @@ public static DynamicMetaObject Restrict(this DynamicMetaObject self, Type type) } if (type == self.Expression.Type) { - if (type.IsSealed() || + if (type.IsSealed || self.Expression.NodeType == ExpressionType.New || self.Expression.NodeType == ExpressionType.NewArrayBounds || self.Expression.NodeType == ExpressionType.NewArrayInit) { @@ -53,7 +53,7 @@ public static DynamicMetaObject Restrict(this DynamicMetaObject self, Type type) // if we're converting to a value type just unbox to preserve // object identity. If we're converting from Enum then we're // going to a specific enum value and an unbox is not allowed. - if (type.IsValueType() && self.Expression.Type != typeof(Enum)) { + if (type.IsValueType && self.Expression.Type != typeof(Enum)) { converted = Expression.Unbox( self.Expression, CompilerHelpers.GetVisibleType(type) diff --git a/Src/Microsoft.Dynamic/Runtime/ReturnFixer.cs b/Src/Microsoft.Dynamic/Runtime/ReturnFixer.cs index af3f2b56..a96d91d1 100644 --- a/Src/Microsoft.Dynamic/Runtime/ReturnFixer.cs +++ b/Src/Microsoft.Dynamic/Runtime/ReturnFixer.cs @@ -18,7 +18,7 @@ internal sealed class ReturnFixer { private readonly Type _argType; private ReturnFixer(LocalBuilder refSlot, int argIndex, Type argType) { - Debug.Assert(refSlot.LocalType.IsGenericType() && refSlot.LocalType.GetGenericTypeDefinition() == typeof(StrongBox<>)); + Debug.Assert(refSlot.LocalType.IsGenericType && refSlot.LocalType.GetGenericTypeDefinition() == typeof(StrongBox<>)); _refSlot = refSlot; _argIndex = argIndex; _argType = argType; diff --git a/Src/Microsoft.Dynamic/Utils/ReflectionUtils.cs b/Src/Microsoft.Dynamic/Utils/ReflectionUtils.cs index 4da3d5a4..8adc8cb2 100644 --- a/Src/Microsoft.Dynamic/Utils/ReflectionUtils.cs +++ b/Src/Microsoft.Dynamic/Utils/ReflectionUtils.cs @@ -244,7 +244,7 @@ public static IEnumerable WithSignature(this IEnumerable WithSignature(this IEnumerable WithSignature(this IEnumerable GetInheritedMethods(this Type type, string name = null, bool flattenHierarchy = false) { while (type.IsGenericParameter) { - type = type.GetBaseType(); + type = type.BaseType; } var baseDefinitions = new HashSet(ReferenceEqualityComparer.Instance); @@ -290,7 +290,7 @@ private static bool IncludeMethod(MethodInfo member, Type reflectedType, HashSet public static IEnumerable GetInheritedProperties(this Type type, string name = null, bool flattenHierarchy = false) { while (type.IsGenericParameter) { - type = type.GetBaseType(); + type = type.BaseType; } var baseDefinitions = new HashSet(ReferenceEqualityComparer.Instance); @@ -314,7 +314,7 @@ public static IEnumerable GetInheritedProperties(this Type type, s // ------------------------- // [Note: The CLS (see Partition I) refers to instance, virtual, and static properties. // The signature of a property (from the Type column) can be used to distinguish a static property, - // since instance and virtual properties will have the “HASTHIS” bit set in the signature (§23.2.1) + // since instance and virtual properties will have the "HASTHIS" bit set in the signature (§23.2.1) // while a static property will not. The distinction between an instance and a virtual property // depends on the signature of the getter and setter methods, which the CLS requires to be either // both virtual or both instance. end note] @@ -346,7 +346,7 @@ private static bool IncludeProperty(PropertyInfo member, Type reflectedType, Has public static IEnumerable GetInheritedEvents(this Type type, string name = null, bool flattenHierarchy = false) { while (type.IsGenericParameter) { - type = type.GetBaseType(); + type = type.BaseType; } var baseDefinitions = new HashSet(ReferenceEqualityComparer.Instance); @@ -396,7 +396,7 @@ private static bool IncludeEvent(EventInfo member, Type reflectedType, HashSet GetInheritedFields(this Type type, string name = null, bool flattenHierarchy = false) { while (type.IsGenericParameter) { - type = type.GetBaseType(); + type = type.BaseType; } foreach (var ancestor in type.Ancestors()) { @@ -514,10 +514,12 @@ public static Type[] GetGenericTypeParameters(this Type type) { return type.IsGenericTypeDefinition ? type.GetGenericArguments() : null; } + [Obsolete("Use Assembly.GetModules directly instead.")] public static IEnumerable GetModules(this Assembly assembly) { return assembly.GetModules(); } + [Obsolete("Use Type.GetInterfaces directly instead.")] public static IEnumerable GetImplementedInterfaces(this Type type) { return type.GetInterfaces(); } @@ -542,58 +544,72 @@ public static T GetCustomAttribute(this MemberInfo member, bool inherit = fal return (T)Attribute.GetCustomAttribute(member, typeof(T), inherit); } + [Obsolete("Use Type.ContainsGenericParameters directly instead.")] public static bool ContainsGenericParameters(this Type type) { return type.ContainsGenericParameters; } + [Obsolete("Use Type.IsInterface directly instead.")] public static bool IsInterface(this Type type) { return type.IsInterface; } + [Obsolete("Use Type.IsClass directly instead.")] public static bool IsClass(this Type type) { return type.IsClass; } + [Obsolete("Use Type.IsGenericType directly instead.")] public static bool IsGenericType(this Type type) { return type.IsGenericType; } + [Obsolete("Use Type.IsGenericTypeDefinition directly instead.")] public static bool IsGenericTypeDefinition(this Type type) { return type.IsGenericTypeDefinition; } + [Obsolete("Use Type.IsSealed directly instead.")] public static bool IsSealed(this Type type) { return type.IsSealed; } + [Obsolete("Use Type.IsAbstract directly instead.")] public static bool IsAbstract(this Type type) { return type.IsAbstract; } + [Obsolete("Use Type.IsPublic directly instead.")] public static bool IsPublic(this Type type) { return type.IsPublic; } + [Obsolete("Use Type.IsVisible directly instead.")] public static bool IsVisible(this Type type) { return type.IsVisible; } + [Obsolete("Use Type.BaseType directly instead.")] public static Type GetBaseType(this Type type) { return type.BaseType; } + [Obsolete("Use Type.IsValueType directly instead.")] public static bool IsValueType(this Type type) { return type.IsValueType; } + [Obsolete("Use Type.IsEnum directly instead.")] public static bool IsEnum(this Type type) { return type.IsEnum; } + [Obsolete("Use Type.IsPrimitive directly instead.")] public static bool IsPrimitive(this Type type) { return type.IsPrimitive; } + [Obsolete("Use Type.GenericParameterAttributes directly instead.")] public static GenericParameterAttributes GetGenericParameterAttributes(this Type type) { return type.GenericParameterAttributes; } @@ -606,7 +622,7 @@ public static object GetRawConstantValue(this FieldInfo field) { } object value = field.GetValue(null); - return field.FieldType.IsEnum() ? UnwrapEnumValue(value) : value; + return field.FieldType.IsEnum ? UnwrapEnumValue(value) : value; } /// @@ -736,14 +752,14 @@ public static StringBuilder FormatTypeName(StringBuilder result, Type type, Func ContractUtils.RequiresNotNull(result, nameof(result)); ContractUtils.RequiresNotNull(type, nameof(type)); ContractUtils.RequiresNotNull(nameDispenser, nameof(nameDispenser)); - if (type.IsGenericType()) { + if (type.IsGenericType) { Type genType = type.GetGenericTypeDefinition(); string genericName = nameDispenser(genType).Replace('+', '.'); int tickIndex = genericName.IndexOf('`'); result.Append(tickIndex != -1 ? genericName.Substring(0, tickIndex) : genericName); Type[] typeArgs = type.GetGenericArguments(); - if (type.IsGenericTypeDefinition()) { + if (type.IsGenericTypeDefinition) { result.Append('<'); result.Append(',', typeArgs.Length - 1); result.Append('>'); @@ -797,7 +813,7 @@ internal static string ToValidTypeName(string str) { public static string GetNormalizedTypeName(Type type) { string name = type.Name; - if (type.IsGenericType()) { + if (type.IsGenericType) { return GetNormalizedTypeName(name); } return name; @@ -1022,7 +1038,7 @@ public static IEnumerable Ancestors(this Type type) { /// and not its parents. /// public static List GetDeclaredInterfaces(Type type) { - IEnumerable baseInterfaces = (type.GetBaseType() != null) ? type.GetBaseType().GetInterfaces() : EmptyTypes; + IEnumerable baseInterfaces = (type.BaseType != null) ? type.BaseType.GetInterfaces() : EmptyTypes; List interfaces = new List(); foreach (Type iface in type.GetInterfaces()) { if (!baseInterfaces.Contains(iface)) { @@ -1166,13 +1182,13 @@ private static void CopyGenericMethodAttributes(MethodInfo from, MethodBuilder t var builders = to.DefineGenericParameters(names); for (int i = 0; i < args.Length; i++) { // Copy template parameter attributes - builders[i].SetGenericParameterAttributes(args[i].GetGenericParameterAttributes()); + builders[i].SetGenericParameterAttributes(args[i].GenericParameterAttributes); // Copy template parameter constraints Type[] constraints = args[i].GetGenericParameterConstraints(); List interfaces = new List(constraints.Length); foreach (Type constraint in constraints) { - if (constraint.IsInterface()) { + if (constraint.IsInterface) { interfaces.Add(constraint); } else { builders[i].SetBaseTypeConstraint(constraint); @@ -1257,7 +1273,7 @@ public static IEnumerable> Dictionary> result = null; foreach (MethodInfo method in GetVisibleExtensionMethodsSlow(assembly)) { - if (method.DeclaringType == null || method.DeclaringType.IsGenericTypeDefinition()) { + if (method.DeclaringType == null || method.DeclaringType.IsGenericTypeDefinition) { continue; } @@ -1339,7 +1355,7 @@ internal static bool BindGenericParameters(Type/*!*/ openType, Type/*!*/ closedT return BindGenericParameters(openType.GetElementType(), closedType.GetElementType(), binder); } - if (!openType.IsGenericType() || !closedType.IsGenericType()) { + if (!openType.IsGenericType || !closedType.IsGenericType) { return openType == closedType; } @@ -1370,19 +1386,19 @@ internal static bool ConstraintsViolated(Dictionary/*!*/ binding, bo } internal static bool ConstraintsViolated(Type/*!*/ genericParameter, Type/*!*/ closedType, Dictionary/*!*/ binding, bool ignoreUnboundParameters) { - if ((genericParameter.GetGenericParameterAttributes() & GenericParameterAttributes.ReferenceTypeConstraint) != 0 && closedType.IsValueType()) { + if ((genericParameter.GenericParameterAttributes & GenericParameterAttributes.ReferenceTypeConstraint) != 0 && closedType.IsValueType) { // value type to parameter type constrained as class return true; } - if ((genericParameter.GetGenericParameterAttributes() & GenericParameterAttributes.NotNullableValueTypeConstraint) != 0 && - (!closedType.IsValueType() || (closedType.IsGenericType() && closedType.GetGenericTypeDefinition() == typeof(Nullable<>)))) { + if ((genericParameter.GenericParameterAttributes & GenericParameterAttributes.NotNullableValueTypeConstraint) != 0 && + (!closedType.IsValueType || (closedType.IsGenericType && closedType.GetGenericTypeDefinition() == typeof(Nullable<>)))) { // nullable or class/interface to parameter type constrained as struct return true; } - if ((genericParameter.GetGenericParameterAttributes() & GenericParameterAttributes.DefaultConstructorConstraint) != 0 && - (!closedType.IsValueType() && closedType.GetConstructor(EmptyTypes) == null)) { + if ((genericParameter.GenericParameterAttributes & GenericParameterAttributes.DefaultConstructorConstraint) != 0 && + (!closedType.IsValueType && closedType.GetConstructor(EmptyTypes) == null)) { // reference type w/o a default constructor to type constrianed as new() return true; } @@ -1408,8 +1424,8 @@ internal static bool ConstraintsViolated(Type/*!*/ genericParameter, Type/*!*/ c } internal static Type InstantiateConstraint(Type/*!*/ constraint, Dictionary/*!*/ binding) { - Debug.Assert(!constraint.IsArray && !constraint.IsByRef && !constraint.IsGenericTypeDefinition()); - if (!constraint.ContainsGenericParameters()) { + Debug.Assert(!constraint.IsArray && !constraint.IsByRef && !constraint.IsGenericTypeDefinition); + if (!constraint.ContainsGenericParameters) { return constraint; } diff --git a/Src/Microsoft.Dynamic/Utils/TypeUtils.cs b/Src/Microsoft.Dynamic/Utils/TypeUtils.cs index 57315fea..90cd8067 100644 --- a/Src/Microsoft.Dynamic/Utils/TypeUtils.cs +++ b/Src/Microsoft.Dynamic/Utils/TypeUtils.cs @@ -115,8 +115,8 @@ internal static bool IsIntegerOrBool(this Type type) { internal static bool CanAssign(Type to, Expression from) { if (CanAssign(to, from.Type)) return true; - if (to.IsValueType() && - to.IsGenericType() && + if (to.IsValueType && + to.IsGenericType && to.GetGenericTypeDefinition() == typeof(Nullable<>) && ConstantCheck.Check(from, null)) { return true; @@ -130,7 +130,7 @@ internal static bool CanAssign(Type to, Type from) { return true; } // Reference types - if (!to.IsValueType() && !from.IsValueType()) { + if (!to.IsValueType && !from.IsValueType) { if (to.IsAssignableFrom(from)) { return true; } @@ -145,13 +145,12 @@ internal static bool CanAssign(Type to, Type from) { return false; } - internal static bool IsGeneric(Type type) { - return type.ContainsGenericParameters() || type.IsGenericTypeDefinition(); - } + internal static bool IsGeneric(Type type) => + type.ContainsGenericParameters || type.IsGenericTypeDefinition; internal static bool CanCompareToNull(Type type) { // This is a bit too conservative. - return !type.IsValueType(); + return !type.IsValueType; } /// @@ -197,13 +196,13 @@ internal static bool IsImplicitlyConvertible(int fromX, int fromY, int toX, int internal static bool HasBuiltinEquality(Type left, Type right) { // Reference type can be compared to interfaces - if (left.IsInterface() && !right.IsValueType() || - right.IsInterface() && !left.IsValueType()) { + if (left.IsInterface && !right.IsValueType || + right.IsInterface && !left.IsValueType) { return true; } // Reference types compare if they are assignable - if (!left.IsValueType() && !right.IsValueType()) { + if (!left.IsValueType && !right.IsValueType) { if (CanAssign(left, right) || CanAssign(right, left)) { return true; } @@ -218,7 +217,7 @@ internal static bool HasBuiltinEquality(Type left, Type right) { return false; } - if (left == typeof(bool) || IsNumeric(left) || left.IsEnum()) { + if (left == typeof(bool) || IsNumeric(left) || left.IsEnum) { return true; } @@ -244,7 +243,7 @@ internal static bool AreReferenceAssignable(Type dest, Type src) { if (dest == src) { return true; } - if (!dest.IsValueType() && !src.IsValueType() && AreAssignable(dest, src)) { + if (!dest.IsValueType && !src.IsValueType && AreAssignable(dest, src)) { return true; } return false; @@ -261,7 +260,7 @@ internal static bool AreAssignable(Type dest, Type src) { if (dest.IsArray && src.IsArray && dest.GetArrayRank() == src.GetArrayRank() && AreReferenceAssignable(dest.GetElementType(), src.GetElementType())) { return true; } - if (src.IsArray && dest.IsGenericType() && + if (src.IsArray && dest.IsGenericType && (dest.GetGenericTypeDefinition() == typeof(System.Collections.Generic.IEnumerable<>) || dest.GetGenericTypeDefinition() == typeof(System.Collections.Generic.IList<>) || dest.GetGenericTypeDefinition() == typeof(System.Collections.Generic.ICollection<>)) @@ -274,15 +273,15 @@ internal static bool AreAssignable(Type dest, Type src) { // keep in sync with System.Core version internal static Type GetConstantType(Type type) { // If it's a visible type, we're done - if (type.IsVisible()) { + if (type.IsVisible) { return type; } // Get the visible base type Type bt = type; do { - bt = bt.GetBaseType(); - } while (!bt.IsVisible()); + bt = bt.BaseType; + } while (!bt.IsVisible); // If it's one of the known reflection types, // return the known type. @@ -301,7 +300,7 @@ internal static Type GetConstantType(Type type) { internal static bool IsConvertible(Type type) { type = GetNonNullableType(type); - if (type.IsEnum()) { + if (type.IsEnum) { return true; } switch (type.GetTypeCode()) {