Clean up 'GetTypeInfo()' calls in other engine sub-folders (#6635)

'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:
Dongbo Wang
2018-04-13 15:07:35 -07:00
committed by GitHub
parent 6125c0f456
commit f9f1bd29ad
14 changed files with 27 additions and 31 deletions
@@ -782,7 +782,7 @@ namespace System.Management.Automation
private static string GetOperatorDescription(string op)
{
return ResourceManagerCache.GetResourceString(typeof(CompletionCompleters).GetTypeInfo().Assembly,
return ResourceManagerCache.GetResourceString(typeof(CompletionCompleters).Assembly,
"System.Management.Automation.resources.TabCompletionStrings",
op + "OperatorDescription");
}
@@ -1639,7 +1639,7 @@ namespace System.Management.Automation
parameterType = parameterType.GetElementType();
}
if (parameterType.GetTypeInfo().IsEnum)
if (parameterType.IsEnum)
{
RemoveLastNullCompletionResult(result);
@@ -5468,15 +5468,13 @@ namespace System.Management.Automation
protected string GetTooltipPrefix()
{
TypeInfo typeInfo = Type.GetTypeInfo();
if (typeof(Delegate).IsAssignableFrom(Type))
return "Delegate ";
if (typeInfo.IsInterface)
if (Type.IsInterface)
return "Interface ";
if (typeInfo.IsClass)
if (Type.IsClass)
return "Class ";
if (typeInfo.IsEnum)
if (Type.IsEnum)
return "Enum ";
if (typeof(ValueType).IsAssignableFrom(Type))
return "Struct ";
@@ -6337,7 +6335,7 @@ namespace System.Management.Automation
if (strValue == null)
{
object baseObj = PSObject.Base(value);
if (baseObj is string || baseObj.GetType().GetTypeInfo().IsPrimitive)
if (baseObj is string || baseObj.GetType().IsPrimitive)
{
strValue = LanguagePrimitives.ConvertTo<string>(value);
}
@@ -4796,7 +4796,7 @@ namespace Microsoft.PowerShell.Commands
ProviderInfo pi = pl.Value[i];
// If it was implemented by this module, remove it
string implAssemblyLocation = pi.ImplementingType.GetTypeInfo().Assembly.Location;
string implAssemblyLocation = pi.ImplementingType.Assembly.Location;
if (implAssemblyLocation.Equals(module.Path, StringComparison.OrdinalIgnoreCase))
{
// Remove all drives from the top level session state
@@ -259,7 +259,7 @@ namespace Microsoft.PowerShell.Commands
Dbg.Assert(pList.Value != null, "There should never be a null list of entries in the provider table");
foreach (ProviderInfo pInfo in pList.Value)
{
string implTypeAssemblyLocation = pInfo.ImplementingType.GetTypeInfo().Assembly.Location;
string implTypeAssemblyLocation = pInfo.ImplementingType.Assembly.Location;
if (implTypeAssemblyLocation.Equals(module.Path, StringComparison.OrdinalIgnoreCase))
{
foreach (PSDriveInfo dInfo in Context.TopLevelSessionState.GetDrivesForProvider(pInfo.FullName))
@@ -34,7 +34,7 @@ namespace System.Management.Automation
// TypeAttributes.WindowsRuntime is part of CLR 4.5. Inorder to build PowerShell for
// CLR 4.0, a string comparison for the for the existence of TypeAttributes.WindowsRuntime
// in the Attributes flag is performed rather than the actual bitwise comparison.
return type.GetTypeInfo().Attributes.ToString().Contains("WindowsRuntime");
return type.Attributes.ToString().Contains("WindowsRuntime");
}
}
}
@@ -1614,7 +1614,7 @@ namespace System.Management.Automation
{
if (null == value)
{
if (typeof(T).GetTypeInfo().IsValueType)
if (typeof(T).IsValueType)
{
throw PSTraceSource.NewArgumentNullException("value", PSDataBufferStrings.ValueNullReference);
}
@@ -440,7 +440,7 @@ namespace System.Management.Automation
Type lvalType = lval != null ? lval.GetType() : null;
Type rvalType = rval != null ? rval.GetType() : null;
Type opType;
if (lvalType == null || (lvalType.GetTypeInfo().IsPrimitive))
if (lvalType == null || (lvalType.IsPrimitive))
{
// Prefer the LHS type when looking for the operator, but attempt the right
// the lhs can't have an operator.
@@ -449,7 +449,7 @@ namespace System.Management.Automation
// would look for overloads in both types, but this logic covers the most common
// cases.
opType = (rvalType == null || rvalType.GetTypeInfo().IsPrimitive) ? null : rvalType;
opType = (rvalType == null || rvalType.IsPrimitive) ? null : rvalType;
}
else
{
@@ -1649,7 +1649,7 @@ namespace System.Management.Automation
throw PSTraceSource.NewArgumentNullException("propertyName");
}
if (typeof(T).GetTypeInfo().IsEnum)
if (typeof(T).IsEnum)
{
if (propertyValue is string)
{
@@ -1698,14 +1698,12 @@ namespace System.Management.Automation
}
else if (propertyValue == null)
{
TypeInfo typeInfo = typeof(T).GetTypeInfo();
if (!typeInfo.IsValueType)
if (!typeof(T).IsValueType)
{
return default(T);
}
if (typeInfo.IsGenericType && typeof(T).GetGenericTypeDefinition().Equals(typeof(Nullable<>)))
if (typeof(T).IsGenericType && typeof(T).GetGenericTypeDefinition().Equals(typeof(Nullable<>)))
{
return default(T);
}
@@ -107,7 +107,7 @@ namespace System.Management.Automation.Remoting
/// </summary>
private static bool IsCollection(Type type)
{
return type.GetTypeInfo().IsGenericType && type.GetGenericTypeDefinition().Equals(typeof(Collection<>));
return type.IsGenericType && type.GetGenericTypeDefinition().Equals(typeof(Collection<>));
}
private static bool IsGenericIEnumerableOfInt(Type type)
@@ -155,7 +155,7 @@ namespace System.Management.Automation.Remoting
/// </summary>
private static bool IsDictionary(Type type)
{
return type.GetTypeInfo().IsGenericType && type.GetGenericTypeDefinition().Equals(typeof(Dictionary<,>));
return type.IsGenericType && type.GetGenericTypeDefinition().Equals(typeof(Dictionary<,>));
}
/// <summary>
@@ -335,7 +335,7 @@ namespace System.Management.Automation.Remoting
{
return obj;
}
else if (type.GetTypeInfo().IsEnum)
else if (type.IsEnum)
{
return (int)obj;
}
@@ -449,7 +449,7 @@ namespace System.Management.Automation.Remoting
}
return cred;
}
else if (obj is int && type.GetTypeInfo().IsEnum)
else if (obj is int && type.IsEnum)
{
return Enum.ToObject(type, (int)obj);
}
@@ -1547,7 +1547,7 @@ namespace System.Management.Automation.Provider
ResourceManager manager =
ResourceManagerCache.GetResourceManager(
this.GetType().GetTypeInfo().Assembly,
this.GetType().Assembly,
baseName);
string retValue = null;
@@ -901,7 +901,7 @@ namespace System.Management.Automation
// the assemblies is patched. ie., all monad assemblies should have the
// same version number.
Assembly currentAssembly = typeof(PSSnapInReader).GetTypeInfo().Assembly;
Assembly currentAssembly = typeof(PSSnapInReader).Assembly;
assemblyVersion = currentAssembly.GetName().Version;
byte[] publicTokens = currentAssembly.GetName().GetPublicKeyToken();
if (publicTokens.Length == 0)
@@ -101,7 +101,7 @@ namespace System.Management.Automation.Runspaces
// no useful information anyway.
if (!String.IsNullOrEmpty(_PSSnapin) && !String.IsNullOrEmpty(_reason))
{
Assembly currentAssembly = typeof(PSSnapInException).GetTypeInfo().Assembly;
Assembly currentAssembly = typeof(PSSnapInException).Assembly;
if (_warning)
{
@@ -99,12 +99,12 @@ namespace System.Management.Automation
internal static bool IsNumericOrPrimitive(this Type type)
{
return type.GetTypeInfo().IsPrimitive || LanguagePrimitives.IsNumeric(LanguagePrimitives.GetTypeCode(type));
return type.IsPrimitive || LanguagePrimitives.IsNumeric(LanguagePrimitives.GetTypeCode(type));
}
internal static bool IsSafePrimitive(this Type type)
{
return type.GetTypeInfo().IsPrimitive && (type != typeof(IntPtr)) && (type != typeof(UIntPtr));
return type.IsPrimitive && (type != typeof(IntPtr)) && (type != typeof(UIntPtr));
}
internal static bool IsFloating(this Type type)
@@ -126,7 +126,7 @@ namespace System.Management.Automation
internal static IEnumerable<T> GetCustomAttributes<T>(this Type type, bool inherit)
where T : Attribute
{
return from attr in type.GetTypeInfo().GetCustomAttributes(typeof(T), inherit)
return from attr in type.GetCustomAttributes(typeof(T), inherit)
where attr is T
select (T)attr;
}
@@ -27,7 +27,7 @@ namespace System.Management.Automation.Internal
// We build against CLR4.5 so we can run on Win7/Win8, but we want to use apis added to CLR 4.6.
// So we use reflection, and if that fails, we just silently skip logging our telemetry.
var diagnosticsTracingAssembly = typeof(EventSource).GetTypeInfo().Assembly;
var diagnosticsTracingAssembly = typeof(EventSource).Assembly;
Type eventSourceSettingsType = diagnosticsTracingAssembly.GetType("System.Diagnostics.Tracing.EventSourceSettings");
if (eventSourceSettingsType == null)
@@ -198,7 +198,7 @@ namespace System.Management.Automation.Tracing
{
if (object.ReferenceEquals(_resourceManager, null))
{
_resourceManager = new global::System.Resources.ResourceManager("System.Management.Automation.resources.EventResource", typeof(EventResource).GetTypeInfo().Assembly);
_resourceManager = new global::System.Resources.ResourceManager("System.Management.Automation.resources.EventResource", typeof(EventResource).Assembly);
}
return _resourceManager;
}