From d093db88f61246f54d27cf1ac3076f332bc4ab7c Mon Sep 17 00:00:00 2001 From: Dongbo Wang Date: Thu, 12 Apr 2018 00:10:23 -0700 Subject: [PATCH] [Feature] Clean up 'GetTypeInfo()' calls in other engine sub-folders --- .../CommandCompletion/CompletionCompleters.cs | 14 ++++++-------- .../engine/Modules/ModuleCmdletBase.cs | 2 +- .../engine/Modules/RemoveModuleCommand.cs | 2 +- .../engine/WinRT/IInspectable.cs | 2 +- .../engine/hostifaces/PSDataCollection.cs | 2 +- .../engine/lang/parserutils.cs | 4 ++-- .../common/WireDataFormat/EncodeAndDecode.cs | 8 +++----- .../common/WireDataFormat/RemoteHostEncoder.cs | 8 ++++---- .../namespaces/ProviderBase.cs | 2 +- .../singleshell/config/MshSnapinInfo.cs | 2 +- .../singleshell/config/MshSnapinLoadException.cs | 2 +- .../utils/ExtensionMethods.cs | 6 +++--- .../utils/PSTelemetryWrapper.cs | 2 +- .../utils/tracing/SysLogProvider.cs | 2 +- 14 files changed, 27 insertions(+), 31 deletions(-) diff --git a/src/System.Management.Automation/engine/CommandCompletion/CompletionCompleters.cs b/src/System.Management.Automation/engine/CommandCompletion/CompletionCompleters.cs index c0055b8dab6..1ae30cf9167 100644 --- a/src/System.Management.Automation/engine/CommandCompletion/CompletionCompleters.cs +++ b/src/System.Management.Automation/engine/CommandCompletion/CompletionCompleters.cs @@ -782,7 +782,7 @@ orderby op 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 @@ private static void ProcessParameter( parameterType = parameterType.GetElementType(); } - if (parameterType.GetTypeInfo().IsEnum) + if (parameterType.IsEnum) { RemoveLastNullCompletionResult(result); @@ -5468,15 +5468,13 @@ private class TypeCompletion : TypeCompletionBase 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 @@ internal static string CombineVariableWithPartialPath(VariableExpressionAst vari 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(value); } diff --git a/src/System.Management.Automation/engine/Modules/ModuleCmdletBase.cs b/src/System.Management.Automation/engine/Modules/ModuleCmdletBase.cs index 037b9651bbe..a16e50e589b 100644 --- a/src/System.Management.Automation/engine/Modules/ModuleCmdletBase.cs +++ b/src/System.Management.Automation/engine/Modules/ModuleCmdletBase.cs @@ -4796,7 +4796,7 @@ internal void RemoveModule(PSModuleInfo module, string moduleNameInRemoveModuleC 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 diff --git a/src/System.Management.Automation/engine/Modules/RemoveModuleCommand.cs b/src/System.Management.Automation/engine/Modules/RemoveModuleCommand.cs index 3dd8d3ac926..bde9976d2e6 100644 --- a/src/System.Management.Automation/engine/Modules/RemoveModuleCommand.cs +++ b/src/System.Management.Automation/engine/Modules/RemoveModuleCommand.cs @@ -259,7 +259,7 @@ private bool ModuleProvidesCurrentSessionDrive(PSModuleInfo module) 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)) diff --git a/src/System.Management.Automation/engine/WinRT/IInspectable.cs b/src/System.Management.Automation/engine/WinRT/IInspectable.cs index 8177dcb2ff0..42ef2b36b27 100644 --- a/src/System.Management.Automation/engine/WinRT/IInspectable.cs +++ b/src/System.Management.Automation/engine/WinRT/IInspectable.cs @@ -34,7 +34,7 @@ internal static bool IsWinRTType(Type type) // 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"); } } } diff --git a/src/System.Management.Automation/engine/hostifaces/PSDataCollection.cs b/src/System.Management.Automation/engine/hostifaces/PSDataCollection.cs index 4fa79521636..03eb9b75345 100644 --- a/src/System.Management.Automation/engine/hostifaces/PSDataCollection.cs +++ b/src/System.Management.Automation/engine/hostifaces/PSDataCollection.cs @@ -1614,7 +1614,7 @@ private static void VerifyValueType(object value) { if (null == value) { - if (typeof(T).GetTypeInfo().IsValueType) + if (typeof(T).IsValueType) { throw PSTraceSource.NewArgumentNullException("value", PSDataBufferStrings.ValueNullReference); } diff --git a/src/System.Management.Automation/engine/lang/parserutils.cs b/src/System.Management.Automation/engine/lang/parserutils.cs index 7d5e7f0889a..50e22f3f00f 100644 --- a/src/System.Management.Automation/engine/lang/parserutils.cs +++ b/src/System.Management.Automation/engine/lang/parserutils.cs @@ -440,7 +440,7 @@ internal static object ImplicitOp(object lval, object rval, string op, IScriptEx 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 @@ internal static object ImplicitOp(object lval, object rval, string op, IScriptEx // 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 { diff --git a/src/System.Management.Automation/engine/remoting/common/WireDataFormat/EncodeAndDecode.cs b/src/System.Management.Automation/engine/remoting/common/WireDataFormat/EncodeAndDecode.cs index 418724d8dd7..e1fb2a8a86e 100644 --- a/src/System.Management.Automation/engine/remoting/common/WireDataFormat/EncodeAndDecode.cs +++ b/src/System.Management.Automation/engine/remoting/common/WireDataFormat/EncodeAndDecode.cs @@ -1649,7 +1649,7 @@ private static T ConvertPropertyValueTo(string propertyName, object propertyV throw PSTraceSource.NewArgumentNullException("propertyName"); } - if (typeof(T).GetTypeInfo().IsEnum) + if (typeof(T).IsEnum) { if (propertyValue is string) { @@ -1698,14 +1698,12 @@ private static T ConvertPropertyValueTo(string propertyName, object propertyV } 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); } diff --git a/src/System.Management.Automation/engine/remoting/common/WireDataFormat/RemoteHostEncoder.cs b/src/System.Management.Automation/engine/remoting/common/WireDataFormat/RemoteHostEncoder.cs index 1199b6afc35..f04aae52135 100644 --- a/src/System.Management.Automation/engine/remoting/common/WireDataFormat/RemoteHostEncoder.cs +++ b/src/System.Management.Automation/engine/remoting/common/WireDataFormat/RemoteHostEncoder.cs @@ -107,7 +107,7 @@ private static object DecodeClassOrStruct(PSObject psObject, Type type) /// 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 @@ private static IList DecodeCollection(PSObject psObject, Type collectionType) /// private static bool IsDictionary(Type type) { - return type.GetTypeInfo().IsGenericType && type.GetGenericTypeDefinition().Equals(typeof(Dictionary<,>)); + return type.IsGenericType && type.GetGenericTypeDefinition().Equals(typeof(Dictionary<,>)); } /// @@ -335,7 +335,7 @@ internal static object EncodeObject(object obj) { return obj; } - else if (type.GetTypeInfo().IsEnum) + else if (type.IsEnum) { return (int)obj; } @@ -449,7 +449,7 @@ internal static object DecodeObject(object obj, Type type) } return cred; } - else if (obj is int && type.GetTypeInfo().IsEnum) + else if (obj is int && type.IsEnum) { return Enum.ToObject(type, (int)obj); } diff --git a/src/System.Management.Automation/namespaces/ProviderBase.cs b/src/System.Management.Automation/namespaces/ProviderBase.cs index a299513149d..eefaf9d9be7 100644 --- a/src/System.Management.Automation/namespaces/ProviderBase.cs +++ b/src/System.Management.Automation/namespaces/ProviderBase.cs @@ -1547,7 +1547,7 @@ public virtual string GetResourceString(string baseName, string resourceId) ResourceManager manager = ResourceManagerCache.GetResourceManager( - this.GetType().GetTypeInfo().Assembly, + this.GetType().Assembly, baseName); string retValue = null; diff --git a/src/System.Management.Automation/singleshell/config/MshSnapinInfo.cs b/src/System.Management.Automation/singleshell/config/MshSnapinInfo.cs index 32741bea030..fa2c1f5d547 100644 --- a/src/System.Management.Automation/singleshell/config/MshSnapinInfo.cs +++ b/src/System.Management.Automation/singleshell/config/MshSnapinInfo.cs @@ -901,7 +901,7 @@ internal static void ReadRegistryInfo(out Version assemblyVersion, out string pu // 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) diff --git a/src/System.Management.Automation/singleshell/config/MshSnapinLoadException.cs b/src/System.Management.Automation/singleshell/config/MshSnapinLoadException.cs index 179d9f76153..e3eacff3643 100644 --- a/src/System.Management.Automation/singleshell/config/MshSnapinLoadException.cs +++ b/src/System.Management.Automation/singleshell/config/MshSnapinLoadException.cs @@ -101,7 +101,7 @@ private void CreateErrorRecord() // no useful information anyway. if (!String.IsNullOrEmpty(_PSSnapin) && !String.IsNullOrEmpty(_reason)) { - Assembly currentAssembly = typeof(PSSnapInException).GetTypeInfo().Assembly; + Assembly currentAssembly = typeof(PSSnapInException).Assembly; if (_warning) { diff --git a/src/System.Management.Automation/utils/ExtensionMethods.cs b/src/System.Management.Automation/utils/ExtensionMethods.cs index e36d698a82c..fe4d5ea9083 100644 --- a/src/System.Management.Automation/utils/ExtensionMethods.cs +++ b/src/System.Management.Automation/utils/ExtensionMethods.cs @@ -99,12 +99,12 @@ internal static bool IsNumeric(this Type type) 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 @@ internal static TypeCode GetTypeCode(this Type type) internal static IEnumerable GetCustomAttributes(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; } diff --git a/src/System.Management.Automation/utils/PSTelemetryWrapper.cs b/src/System.Management.Automation/utils/PSTelemetryWrapper.cs index 995de89a167..969ef39d016 100644 --- a/src/System.Management.Automation/utils/PSTelemetryWrapper.cs +++ b/src/System.Management.Automation/utils/PSTelemetryWrapper.cs @@ -27,7 +27,7 @@ static TelemetryWrapper() // 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) diff --git a/src/System.Management.Automation/utils/tracing/SysLogProvider.cs b/src/System.Management.Automation/utils/tracing/SysLogProvider.cs index ca1b5c8680d..d7f4827af05 100755 --- a/src/System.Management.Automation/utils/tracing/SysLogProvider.cs +++ b/src/System.Management.Automation/utils/tracing/SysLogProvider.cs @@ -198,7 +198,7 @@ private bool ShouldLog(PSLevel level, PSKeyword keywords, PSChannel channel) { 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; }