Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mark some ReflectionUtils methods as Obsolete and remove their usages #216

Merged
merged 2 commits into from
Sep 28, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions Src/Microsoft.Dynamic/Actions/ActionBinder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,11 @@ protected ActionBinder(ScriptDomainManager manager) {
/// </summary>
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;
}
Expand Down Expand Up @@ -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);
}

Expand Down
2 changes: 1 addition & 1 deletion Src/Microsoft.Dynamic/Actions/Calls/OutArgBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
Expand Down
6 changes: 3 additions & 3 deletions Src/Microsoft.Dynamic/Actions/Calls/OverloadResolver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -590,7 +590,7 @@ private static bool IsOverloadedOnParameter(int argIndex, int argCount, IList<Ap
return true;
}
parameterType = lastParameter.Type.GetElementType();
} else if (parameter.Type.ContainsGenericParameters()) {
} else if (parameter.Type.ContainsGenericParameters) {
return true;
} else {
parameterType = parameter.Type;
Expand Down Expand Up @@ -873,11 +873,11 @@ public virtual bool CanConvertFrom(Type fromType, DynamicMetaObject fromArgument
return false;
}

if (toType.IsGenericType() && toType.GetGenericTypeDefinition() == typeof(Nullable<>)) {
if (toType.IsGenericType && toType.GetGenericTypeDefinition() == typeof(Nullable<>)) {
return true;
}

if (!toType.IsValueType()) {
if (!toType.IsValueType) {
return true;
}
}
Expand Down
2 changes: 1 addition & 1 deletion Src/Microsoft.Dynamic/Actions/Calls/ParameterMapping.cs
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,7 @@ private static List<MemberInfo> GetBindableMembers(Type returnType, List<string>
break;
}

curType = curType.GetBaseType();
curType = curType.BaseType;
}

if (mis.Length == 1) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ private Func<string[], object[], object> GetCreationDelegate(Type dictType) {

if (dictType == typeof(IDictionary)) {
func = BinderOps.MakeDictionary<object, object>;
} else if (dictType.IsGenericType()) {
} else if (dictType.IsGenericType) {
Type[] genArgs = dictType.GetGenericTypeArguments();
if (dictType.GetGenericTypeDefinition() == typeof(IDictionary<,>) ||
dictType.GetGenericTypeDefinition() == typeof(Dictionary<,>)) {
Expand Down
20 changes: 10 additions & 10 deletions Src/Microsoft.Dynamic/Actions/Calls/TypeInferer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ private static List<ArgBuilder> 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) {
Expand Down Expand Up @@ -243,7 +243,7 @@ private static Dictionary<Type, List<Type>> 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);
}
}
Expand All @@ -256,7 +256,7 @@ private static void AddNestedDependencies(Dictionary<Type, List<Type>> 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);
}
}
Expand Down Expand Up @@ -295,7 +295,7 @@ private static void AddDependency(Dictionary<Type, List<Type>> dependencies, Typ
/// Adds any additional ArgumentInputs entries for the given object and parameter type.
/// </summary>
private static void AddOneInput(Dictionary<Type, ArgumentInputs> inputs, DynamicMetaObject arg, Type paramType) {
if (paramType.ContainsGenericParameters()) {
if (paramType.ContainsGenericParameters) {
List<Type> containedGenArgs = new List<Type>();
CollectGenericParameters(paramType, containedGenArgs);

Expand All @@ -319,7 +319,7 @@ private static void CollectGenericParameters(Type type, List<Type> 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 {
Expand Down Expand Up @@ -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);
}

Expand All @@ -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;
Expand All @@ -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<Type, Type>/*!*/ 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;
}
Expand Down
33 changes: 13 additions & 20 deletions Src/Microsoft.Dynamic/Actions/DefaultBinder.Conversions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -60,7 +60,7 @@ public DynamicMetaObject ConvertTo(Type toType, ConversionResultKind kind, Dynam
/// </summary>
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);
}

Expand All @@ -87,7 +87,7 @@ private DynamicMetaObject TryAllConversions(OverloadResolverFactory factory, Typ
/// </summary>
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);
}
Expand Down Expand Up @@ -180,7 +180,7 @@ private static DynamicMetaObject TryExtensibleConversion(Type toType, Type type,
/// </summary>
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];
}

Expand All @@ -205,7 +205,7 @@ private static DynamicMetaObject TryImplicitNumericConversion(Type toType, Type
/// Checks if there's a conversion to/from Nullable of T.
/// </summary>
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<T>
return MakeNullToNullableOfTTarget(toType, restrictions);
Expand All @@ -230,7 +230,7 @@ private DynamicMetaObject TryNullableConversion(OverloadResolverFactory factory,
/// Checks to see if there's a conversion of null to a reference type
/// </summary>
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;
Expand Down Expand Up @@ -455,19 +455,12 @@ private DynamicMetaObject MakeConvertingToTToNullableOfTTarget(OverloadResolverF
}

/// <summary>
/// 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.
/// </summary>
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);

/// <summary>
/// Helper to extract the Value of an Extensible of T from the
Expand All @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion Src/Microsoft.Dynamic/Actions/DefaultBinder.GetMember.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion Src/Microsoft.Dynamic/Actions/DefaultBinder.Invoke.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions Src/Microsoft.Dynamic/Actions/DefaultBinder.Operations.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
8 changes: 4 additions & 4 deletions Src/Microsoft.Dynamic/Actions/DefaultBinder.SetMember.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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(
Expand Down
2 changes: 1 addition & 1 deletion Src/Microsoft.Dynamic/Actions/DefaultBinder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ public MethodInfo GetMethod(Type type, string name) {
return mi;
}

curType = curType.GetBaseType();
curType = curType.BaseType;
} while (curType != null);

return null;
Expand Down
8 changes: 4 additions & 4 deletions Src/Microsoft.Dynamic/Actions/FieldTracker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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);
}
Expand All @@ -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(
Expand Down
Loading