8000 Clean up 'GetTypeInfo()' calls in engine folder by daxian-dbw · Pull Request #6634 · PowerShell/PowerShell · GitHub
[go: up one dir, main page]

Skip to content

Clean up 'GetTypeInfo()' calls in engine folder #6634

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

Merged
merged 1 commit into from
Apr 13, 2018
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
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ private static void CheckBoolValue(object value, Type boolType)
}
else
{
bool isNullable = boolType.GetTypeInfo().IsGenericType &&
bool isNullable = boolType.IsGenericType &&
boolType.GetGenericTypeDefinition() == typeof(Nullable<>);

if (!isNullable && LanguagePrimitives.IsBooleanType(boolType))
Expand Down
2 changes: 1 addition & 1 deletion src/System.Management.Automation/engine/CmdletInfo.cs
8000
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,7 @@ public override ReadOnlyCollection<PSTypeName> OutputType

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);
Expand Down
2 changes: 1 addition & 1 deletion src/System.Management.Automation/engine/CommandMetadata.cs
Original file line number Diff line number Diff line change
Expand Up @@ -697,7 +697,7 @@ private void ConstructCmdletMetadataUsingReflection()

// Process the attributes on the cmdlet

var customAttributes = CommandType.GetTypeInfo().GetCustomAttributes(false);
var customAttributes = CommandType.GetCustomAttributes(false);

foreach (Attribute attribute in customAttributes)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -613,7 +613,6 @@ internal ParameterCollectionTypeInformation(Type type)
{
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?
Expand All @@ -636,8 +635,8 @@ internal ParameterCollectionTypeInformation(Type type)
}

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;
}
Expand All @@ -648,7 +647,7 @@ internal ParameterCollectionTypeInformation(Type type)
// 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
Expand All @@ -666,7 +665,7 @@ internal ParameterCollectionTypeInformation(Type type)
// 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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public sealed class FlagsExpression<T> where T : struct, IConvertible
/// </param>
public FlagsExpression(string expression)
{
if (!typeof(T).GetTypeInfo().IsEnum)
if (!typeof(T).IsEnum)
{
throw InterpreterError.NewInterpreterException(expression, typeof(RuntimeException),
null, "InvalidGenericType", EnumExpressionEvaluatorStrings.InvalidGenericType);
Expand Down Expand Up @@ -58,7 +58,7 @@ public FlagsExpression(string expression)
/// </param>
public FlagsExpression(object[] expression)
{
if (!typeof(T).GetTypeInfo().IsEnum)
if (!typeof(T).IsEnum)
{
throw InterpreterError.NewInterpreterException(expression, typeof(RuntimeException),
null, "InvalidGenericType", EnumExpressionEvaluatorStrings.InvalidGenericType);
Expand Down
2 changes: 1 addition & 1 deletion src/System.Management.Automation/engine/EventManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1464,7 +1464,7 @@ private Type GenerateEventHandler(MethodInfo invokeSignature)
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]);
}
Expand Down
6 changes: 3 additions & 3 deletions src/System.Management.Automation/engine/GetCommandCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1472,8 +1472,8 @@ private static PSObject[] GetParameterInfo(ReadOnlyCollection<CommandParameterIn
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));
Expand All @@ -1483,7 +1483,7 @@ private static PSObject GetParameterType(Type parameterType)
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.
Expand Down
16 changes: 7 additions & 9 deletions src/System.Management.Automation/engine/InitialSessionState.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4976,9 +4976,9 @@ internal static Assembly LoadPSSnapInAssembly(PSSnapInInfo psSnapInInfo,
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");
Expand Down Expand Up @@ -5238,16 +5238,15 @@ private static void AnalyzeModuleAssemblyWithReflection(Assembly assembly, strin

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
if (IsCmdletClass(type) && HasDefaultConstructor(type))
{
randomCmdletToCheckLinkDemand = type;

CmdletAttribute cmdletAttribute = GetCustomAttribute<CmdletAttribute>(typeInfo);
CmdletAttribute cmdletAttribute = GetCustomAttribute<CmdletAttribute>(type);
if (cmdletAttribute == null)
{
continue;
Expand Down Expand Up @@ -5275,7 +5274,7 @@ private static void AnalyzeModuleAssemblyWithReflection(Assembly assembly, strin
}
cmdlets.Add(cmdletName, cmdlet);

var aliasAttribute = GetCustomAttribute<AliasAttribute>(typeInfo);
var aliasAttribute = GetCustomAttribute<AliasAttribute>(type);
if (aliasAttribute != null)
{
if (aliases == null)
Expand Down Expand Up @@ -5309,7 +5308,7 @@ private static void AnalyzeModuleAssemblyWithReflection(Assembly assembly, strin
{
randomProviderToCheckLinkDemand = type;

CmdletProviderAttribute providerAttribute = GetCustomAttribute<CmdletProviderAttribute>(typeInfo);
CmdletProviderAttribute providerAttribute = GetCustomAttribute<CmdletProviderAttribute>(type);
if (providerAttribute == null)
{
continue;
Expand Down Expand Up @@ -5453,8 +5452,7 @@ private static void ExecuteModuleInitializer(Assembly assembly, Type[] assemblyT
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))
{
Expand Down
2 changes: 1 addition & 1 deletion src/System.Management.Automation/engine/MshCmdlet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -444,7 +444,7 @@ public CmdletInfo GetCmdletByTypeName(string cmdletTypeName)
}

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)
Expand Down
15 changes: 7 additions & 8 deletions src/System.Management.Automation/engine/MshObject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2407,8 +2407,7 @@ internal static string Type(Type type, bool dropNamespaces = false, string key =
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:
Expand All @@ -2417,12 +2416,12 @@ internal static string Type(Type type, bool dropNamespaces = false, string key =
// 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);
Expand All @@ -2445,7 +2444,7 @@ internal static string Type(Type type, bool dropNamespaces = false, string key =
}
if (dropNamespaces)
{
if (typeinfo.IsNested)
if (type.IsNested)
{
// For nested types, we should return OuterType+InnerType. For example,
// System.Environment+SpecialFolder -> Environment+SpecialFolder
Expand All @@ -2468,10 +2467,10 @@ internal static string Type(Type type, bool dropNamespaces = false, string key =

// 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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -850,7 +850,7 @@ private bool ShouldContinueUncoercedBind(
{
return parameterType == null ||
isDefaultValue ||
(!parameterType.GetTypeInfo().IsValueType &&
(!parameterType.IsValueType &&
parameterType != typeof(string));
}

Expand Down Expand Up @@ -1245,14 +1245,13 @@ private object CoerceTypeAsNeeded(
// 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();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ private static Action<object, object> GetSetter(Type type, string property)
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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2285,7 +2285,7 @@ private bool HasGetChildItemDynamicParameters(ProviderInfo providerInfo)
{
mi = providerType.GetMethod("GetChildItemsDynamicParameters",
BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.DeclaredOnly);
providerType = providerType.GetTypeInfo().BaseType;
providerType = providerType.BaseType;
} while (
(mi == null) &&
(providerType != null) &&
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ public virtual Collection<string> GetTypeNameHierarchy(object baseObject)

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);
}
Expand Down
2 changes: 1 addition & 1 deletion src/System.Management.Automation/engine/cmdlet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ public virtual string GetResourceString(string baseName, string resourceId)
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
Expand Down
6 changes: 3 additions & 3 deletions src/System.Management.Automation/engine/serialization.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5308,7 +5308,7 @@ internal static void GetKnownContainerTypeInfo(
else
{
Type gt = source.GetType();
if (gt.GetTypeInfo().IsGenericType)
if (gt.IsGenericType)
{
if (DerivesFromGenericType(gt, typeof(Stack<>)))
{
Expand Down Expand Up @@ -5382,14 +5382,14 @@ private static bool DerivesFromGenericType(Type derived, Type baseType)
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;
}
Expand Down
0