Clean up 'GetTypeInfo()' calls in engine folder (#6634)
'GetTypeInfo()' were added when porting PowerShell to early version of .NET Core (prior .NET Core 1.0). Most properties and methods in 'System.Type' were missing at that time. Now the call is not needed anymore and should be removed.
This commit is contained in:
parent
f9f1bd29ad
commit
11631e7412
|
@ -185,7 +185,7 @@ namespace System.Management.Automation
|
|||
}
|
||||
else
|
||||
{
|
||||
bool isNullable = boolType.GetTypeInfo().IsGenericType &&
|
||||
bool isNullable = boolType.IsGenericType &&
|
||||
boolType.GetGenericTypeDefinition() == typeof(Nullable<>);
|
||||
|
||||
if (!isNullable && LanguagePrimitives.IsBooleanType(boolType))
|
||||
|
|
|
@ -340,7 +340,7 @@ namespace System.Management.Automation
|
|||
|
||||
if (ImplementingType != null)
|
||||
{
|
||||
foreach (object o in ImplementingType.GetTypeInfo().GetCustomAttributes(typeof(OutputTypeAttribute), false))
|
||||
foreach (object o in ImplementingType.GetCustomAttributes(typeof(OutputTypeAttribute), false))
|
||||
{
|
||||
OutputTypeAttribute attr = (OutputTypeAttribute)o;
|
||||
_outputType.AddRange(attr.Type);
|
||||
|
|
|
@ -697,7 +697,7 @@ namespace System.Management.Automation
|
|||
|
||||
// Process the attributes on the cmdlet
|
||||
|
||||
var customAttributes = CommandType.GetTypeInfo().GetCustomAttributes(false);
|
||||
var customAttributes = CommandType.GetCustomAttributes(false);
|
||||
|
||||
foreach (Attribute attribute in customAttributes)
|
||||
{
|
||||
|
|
|
@ -613,7 +613,6 @@ namespace System.Management.Automation
|
|||
{
|
||||
ParameterCollectionType = ParameterCollectionType.NotCollection;
|
||||
Diagnostics.Assert(type != null, "Caller to verify type argument");
|
||||
TypeInfo typeInfo = type.GetTypeInfo();
|
||||
|
||||
// NTRAID#Windows OS Bugs-1009284-2004/05/11-JeffJon
|
||||
// What other collection types should be supported?
|
||||
|
@ -636,8 +635,8 @@ namespace System.Management.Automation
|
|||
}
|
||||
|
||||
Type[] interfaces = type.GetInterfaces();
|
||||
if (interfaces.Any(i => i.GetTypeInfo().IsGenericType && i.GetGenericTypeDefinition() == typeof(IDictionary<,>))
|
||||
|| (typeInfo.IsGenericType && type.GetGenericTypeDefinition() == typeof(IDictionary<,>)))
|
||||
if (interfaces.Any(i => i.IsGenericType && i.GetGenericTypeDefinition() == typeof(IDictionary<,>))
|
||||
|| (type.IsGenericType && type.GetGenericTypeDefinition() == typeof(IDictionary<,>)))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
@ -648,7 +647,7 @@ namespace System.Management.Automation
|
|||
// is more efficient to bind than ICollection<T>. This optimization
|
||||
// retrieves the element type so that we can coerce the elements.
|
||||
// Otherwise they must already be the right type.
|
||||
if (implementsIList && typeInfo.IsGenericType && (type.GetGenericTypeDefinition() == typeof(Collection<>)))
|
||||
if (implementsIList && type.IsGenericType && (type.GetGenericTypeDefinition() == typeof(Collection<>)))
|
||||
{
|
||||
ParameterCollectionType = ParameterCollectionType.IList;
|
||||
// figure out elementType
|
||||
|
@ -666,7 +665,7 @@ namespace System.Management.Automation
|
|||
// to an ICollection<T> is via reflected calls to Add(T),
|
||||
// but the advantage over plain IList is that we can typecast the elements.
|
||||
Type interfaceICollection =
|
||||
interfaces.FirstOrDefault(i => i.GetTypeInfo().IsGenericType && i.GetGenericTypeDefinition() == typeof(ICollection<>));
|
||||
interfaces.FirstOrDefault(i => i.IsGenericType && i.GetGenericTypeDefinition() == typeof(ICollection<>));
|
||||
if (interfaceICollection != null)
|
||||
{
|
||||
// We only deal with the first type for which ICollection<T> is implemented
|
||||
|
|
|
@ -26,7 +26,7 @@ namespace System.Management.Automation
|
|||
/// </param>
|
||||
public FlagsExpression(string expression)
|
||||
{
|
||||
if (!typeof(T).GetTypeInfo().IsEnum)
|
||||
if (!typeof(T).IsEnum)
|
||||
{
|
||||
throw InterpreterError.NewInterpreterException(expression, typeof(RuntimeException),
|
||||
null, "InvalidGenericType", EnumExpressionEvaluatorStrings.InvalidGenericType);
|
||||
|
@ -58,7 +58,7 @@ namespace System.Management.Automation
|
|||
/// </param>
|
||||
public FlagsExpression(object[] expression)
|
||||
{
|
||||
if (!typeof(T).GetTypeInfo().IsEnum)
|
||||
if (!typeof(T).IsEnum)
|
||||
{
|
||||
throw InterpreterError.NewInterpreterException(expression, typeof(RuntimeException),
|
||||
null, "InvalidGenericType", EnumExpressionEvaluatorStrings.InvalidGenericType);
|
||||
|
|
|
@ -1464,7 +1464,7 @@ namespace System.Management.Automation
|
|||
methodContents.Emit(OpCodes.Ldarg, counter);
|
||||
|
||||
// Box the value type if necessary
|
||||
if (parameterTypes[counter - 1].GetTypeInfo().IsValueType)
|
||||
if (parameterTypes[counter - 1].IsValueType)
|
||||
{
|
||||
methodContents.Emit(OpCodes.Box, parameterTypes[counter - 1]);
|
||||
}
|
||||
|
|
|
@ -1472,8 +1472,8 @@ namespace Microsoft.PowerShell.Commands
|
|||
private static PSObject GetParameterType(Type parameterType)
|
||||
{
|
||||
PSObject returnParameterType = new PSObject();
|
||||
bool isEnum = parameterType.GetTypeInfo().IsEnum;
|
||||
bool isArray = parameterType.GetTypeInfo().IsArray;
|
||||
bool isEnum = parameterType.IsEnum;
|
||||
bool isArray = parameterType.IsArray;
|
||||
returnParameterType.Properties.Add(new PSNoteProperty("FullName", parameterType.FullName));
|
||||
returnParameterType.Properties.Add(new PSNoteProperty("IsEnum", isEnum));
|
||||
returnParameterType.Properties.Add(new PSNoteProperty("IsArray", isArray));
|
||||
|
@ -1483,7 +1483,7 @@ namespace Microsoft.PowerShell.Commands
|
|||
returnParameterType.Properties.Add(new PSNoteProperty("EnumValues", enumValues));
|
||||
|
||||
bool hasFlagAttribute = (isArray) ?
|
||||
((parameterType.GetTypeInfo().GetCustomAttributes(typeof(FlagsAttribute), true)).Count() > 0) : false;
|
||||
((parameterType.GetCustomAttributes(typeof(FlagsAttribute), true)).Count() > 0) : false;
|
||||
returnParameterType.Properties.Add(new PSNoteProperty("HasFlagAttribute", hasFlagAttribute));
|
||||
|
||||
// Recurse into array elements.
|
||||
|
|
|
@ -4976,9 +4976,9 @@ if($paths) {
|
|||
return assembly;
|
||||
}
|
||||
|
||||
private static T GetCustomAttribute<T>(TypeInfo decoratedType) where T : Attribute
|
||||
private static T GetCustomAttribute<T>(Type decoratedType) where T : Attribute
|
||||
{
|
||||
var attributes = CustomAttributeExtensions.GetCustomAttributes<T>(decoratedType, false);
|
||||
var attributes = decoratedType.GetCustomAttributes<T>(false);
|
||||
var customAttrs = attributes.ToArray();
|
||||
|
||||
Debug.Assert(customAttrs.Length <= 1, "CmdletAttribute and/or CmdletProviderAttribute cannot normally appear more than once");
|
||||
|
@ -5238,8 +5238,7 @@ if($paths) {
|
|||
|
||||
foreach (Type type in assemblyTypes)
|
||||
{
|
||||
var typeInfo = type.GetTypeInfo();
|
||||
if (!(typeInfo.IsPublic || typeInfo.IsNestedPublic) || typeInfo.IsAbstract)
|
||||
if (!(type.IsPublic || type.IsNestedPublic) || type.IsAbstract)
|
||||
continue;
|
||||
|
||||
// Check for cmdlets
|
||||
|
@ -5247,7 +5246,7 @@ if($paths) {
|
|||
{
|
||||
randomCmdletToCheckLinkDemand = type;
|
||||
|
||||
CmdletAttribute cmdletAttribute = GetCustomAttribute<CmdletAttribute>(typeInfo);
|
||||
CmdletAttribute cmdletAttribute = GetCustomAttribute<CmdletAttribute>(type);
|
||||
if (cmdletAttribute == null)
|
||||
{
|
||||
continue;
|
||||
|
@ -5275,7 +5274,7 @@ if($paths) {
|
|||
}
|
||||
cmdlets.Add(cmdletName, cmdlet);
|
||||
|
||||
var aliasAttribute = GetCustomAttribute<AliasAttribute>(typeInfo);
|
||||
var aliasAttribute = GetCustomAttribute<AliasAttribute>(type);
|
||||
if (aliasAttribute != null)
|
||||
{
|
||||
if (aliases == null)
|
||||
|
@ -5309,7 +5308,7 @@ if($paths) {
|
|||
{
|
||||
randomProviderToCheckLinkDemand = type;
|
||||
|
||||
CmdletProviderAttribute providerAttribute = GetCustomAttribute<CmdletProviderAttribute>(typeInfo);
|
||||
CmdletProviderAttribute providerAttribute = GetCustomAttribute<CmdletProviderAttribute>(type);
|
||||
if (providerAttribute == null)
|
||||
{
|
||||
continue;
|
||||
|
@ -5453,8 +5452,7 @@ if($paths) {
|
|||
for (int i = 0; i < assemblyTypes.Length; i++)
|
||||
{
|
||||
Type type = assemblyTypes[i];
|
||||
TypeInfo typeInfo = type.GetTypeInfo();
|
||||
if (!(typeInfo.IsPublic || typeInfo.IsNestedPublic) || typeInfo.IsAbstract) { continue; }
|
||||
if (!(type.IsPublic || type.IsNestedPublic) || type.IsAbstract) { continue; }
|
||||
|
||||
if (isModuleLoad && typeof(IModuleAssemblyInitializer).IsAssignableFrom(type) && type != typeof(IModuleAssemblyInitializer))
|
||||
{
|
||||
|
|
|
@ -444,7 +444,7 @@ namespace System.Management.Automation
|
|||
}
|
||||
|
||||
CmdletAttribute ca = null;
|
||||
foreach (var attr in cmdletType.GetTypeInfo().GetCustomAttributes(true))
|
||||
foreach (var attr in cmdletType.GetCustomAttributes(true))
|
||||
{
|
||||
ca = attr as CmdletAttribute;
|
||||
if (ca != null)
|
||||
|
|
|
@ -2407,8 +2407,7 @@ namespace Microsoft.PowerShell
|
|||
return String.Empty;
|
||||
|
||||
string result;
|
||||
TypeInfo typeinfo = type.GetTypeInfo();
|
||||
if (typeinfo.IsGenericType && !typeinfo.IsGenericTypeDefinition)
|
||||
if (type.IsGenericType && !type.IsGenericTypeDefinition)
|
||||
{
|
||||
string genericDefinition = Type(type.GetGenericTypeDefinition(), dropNamespaces);
|
||||
// For regular generic types, we find the backtick character, for example:
|
||||
|
@ -2417,12 +2416,12 @@ namespace Microsoft.PowerShell
|
|||
// For nested generic types, we find the left bracket character, for example:
|
||||
// System.Collections.Generic.Dictionary`2+Enumerator[TKey, TValue] ->
|
||||
// System.Collections.Generic.Dictionary`2+Enumerator[string,string]
|
||||
int backtickOrLeftBracketIndex = genericDefinition.LastIndexOf(typeinfo.IsNested ? '[' : '`');
|
||||
int backtickOrLeftBracketIndex = genericDefinition.LastIndexOf(type.IsNested ? '[' : '`');
|
||||
var sb = new StringBuilder(genericDefinition, 0, backtickOrLeftBracketIndex, 512);
|
||||
AddGenericArguments(sb, type.GetGenericArguments(), dropNamespaces);
|
||||
result = sb.ToString();
|
||||
}
|
||||
else if (typeinfo.IsArray)
|
||||
else if (type.IsArray)
|
||||
{
|
||||
string elementDefinition = Type(type.GetElementType(), dropNamespaces);
|
||||
var sb = new StringBuilder(elementDefinition, elementDefinition.Length + 10);
|
||||
|
@ -2445,7 +2444,7 @@ namespace Microsoft.PowerShell
|
|||
}
|
||||
if (dropNamespaces)
|
||||
{
|
||||
if (typeinfo.IsNested)
|
||||
if (type.IsNested)
|
||||
{
|
||||
// For nested types, we should return OuterType+InnerType. For example,
|
||||
// System.Environment+SpecialFolder -> Environment+SpecialFolder
|
||||
|
@ -2468,10 +2467,10 @@ namespace Microsoft.PowerShell
|
|||
|
||||
// We can't round trip anything with a generic parameter.
|
||||
// We also can't round trip if we're dropping the namespace.
|
||||
if (!typeinfo.IsGenericParameter
|
||||
&& !typeinfo.ContainsGenericParameters
|
||||
if (!type.IsGenericParameter
|
||||
&& !type.ContainsGenericParameters
|
||||
&& !dropNamespaces
|
||||
&& !typeinfo.Assembly.GetCustomAttributes(typeof(DynamicClassImplementationAssemblyAttribute)).Any())
|
||||
&& !type.Assembly.GetCustomAttributes(typeof(DynamicClassImplementationAssemblyAttribute)).Any())
|
||||
{
|
||||
Type roundTripType;
|
||||
TypeResolver.TryResolveType(result, out roundTripType);
|
||||
|
|
|
@ -850,7 +850,7 @@ namespace System.Management.Automation
|
|||
{
|
||||
return parameterType == null ||
|
||||
isDefaultValue ||
|
||||
(!parameterType.GetTypeInfo().IsValueType &&
|
||||
(!parameterType.IsValueType &&
|
||||
parameterType != typeof(string));
|
||||
}
|
||||
|
||||
|
@ -1245,14 +1245,13 @@ namespace System.Management.Automation
|
|||
// we don't want to attempt to bind a collection to a scalar unless
|
||||
// the parameter type is Object or PSObject or enum.
|
||||
|
||||
TypeInfo toTypeInfo = toType.GetTypeInfo();
|
||||
if (GetIList(currentValue) != null &&
|
||||
toType != typeof(Object) &&
|
||||
toType != typeof(PSObject) &&
|
||||
toType != typeof(PSListModifier) &&
|
||||
(!toTypeInfo.IsGenericType || toTypeInfo.GetGenericTypeDefinition() != typeof(PSListModifier<>)) &&
|
||||
(!toTypeInfo.IsGenericType || toTypeInfo.GetGenericTypeDefinition() != typeof(FlagsExpression<>)) &&
|
||||
!toTypeInfo.IsEnum)
|
||||
(!toType.IsGenericType || toType.GetGenericTypeDefinition() != typeof(PSListModifier<>)) &&
|
||||
(!toType.IsGenericType || toType.GetGenericTypeDefinition() != typeof(FlagsExpression<>)) &&
|
||||
!toType.IsEnum)
|
||||
{
|
||||
throw new NotSupportedException();
|
||||
}
|
||||
|
|
|
@ -242,7 +242,7 @@ namespace System.Management.Automation
|
|||
var propertyExpr = GetPropertyOrFieldExpr(type, property, Expression.Convert(target, type));
|
||||
|
||||
Expression expr = Expression.Assign(propertyExpr, Expression.Convert(value, propertyExpr.Type));
|
||||
if (propertyExpr.Type.GetTypeInfo().IsValueType && Nullable.GetUnderlyingType(propertyExpr.Type) == null)
|
||||
if (propertyExpr.Type.IsValueType && Nullable.GetUnderlyingType(propertyExpr.Type) == null)
|
||||
{
|
||||
var throwInvalidCastExceptionExpr =
|
||||
Expression.Call(Language.CachedReflectionInfo.LanguagePrimitives_ThrowInvalidCastException,
|
||||
|
|
|
@ -2285,7 +2285,7 @@ namespace System.Management.Automation
|
|||
{
|
||||
mi = providerType.GetMethod("GetChildItemsDynamicParameters",
|
||||
BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.DeclaredOnly);
|
||||
providerType = providerType.GetTypeInfo().BaseType;
|
||||
providerType = providerType.BaseType;
|
||||
} while (
|
||||
(mi == null) &&
|
||||
(providerType != null) &&
|
||||
|
|
|
@ -279,7 +279,7 @@ namespace System.Management.Automation
|
|||
|
||||
Collection<string> types = new Collection<String>();
|
||||
|
||||
for (Type type = baseObject.GetType(); type != null; type = type.GetTypeInfo().BaseType)
|
||||
for (Type type = baseObject.GetType(); type != null; type = type.BaseType)
|
||||
{
|
||||
types.Add(type.FullName);
|
||||
}
|
||||
|
|
|
@ -256,7 +256,7 @@ namespace System.Management.Automation
|
|||
if (String.IsNullOrEmpty(resourceId))
|
||||
throw PSTraceSource.NewArgumentNullException("resourceId");
|
||||
|
||||
ResourceManager manager = ResourceManagerCache.GetResourceManager(this.GetType().GetTypeInfo().Assembly, baseName);
|
||||
ResourceManager manager = ResourceManagerCache.GetResourceManager(this.GetType().Assembly, baseName);
|
||||
string retValue = null;
|
||||
|
||||
try
|
||||
|
|
|
@ -5308,7 +5308,7 @@ namespace System.Management.Automation
|
|||
else
|
||||
{
|
||||
Type gt = source.GetType();
|
||||
if (gt.GetTypeInfo().IsGenericType)
|
||||
if (gt.IsGenericType)
|
||||
{
|
||||
if (DerivesFromGenericType(gt, typeof(Stack<>)))
|
||||
{
|
||||
|
@ -5382,14 +5382,14 @@ namespace System.Management.Automation
|
|||
Dbg.Assert(baseType != null, "caller should validate the parameter");
|
||||
while (derived != null)
|
||||
{
|
||||
if (derived.GetTypeInfo().IsGenericType)
|
||||
if (derived.IsGenericType)
|
||||
derived = derived.GetGenericTypeDefinition();
|
||||
|
||||
if (derived == baseType)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
derived = derived.GetTypeInfo().BaseType;
|
||||
derived = derived.BaseType;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue