From 7d866679d0cb1b30ec4b7fb11f71ba6c97442280 Mon Sep 17 00:00:00 2001 From: Sergei Vorobev Date: Tue, 26 Jul 2016 17:44:47 -0700 Subject: [PATCH] Address some feedback - Name fields more descriptive - Use .AddRange instead of foreach --- .../commands/utility/AddType.cs | 33 ++++++++----------- 1 file changed, 14 insertions(+), 19 deletions(-) diff --git a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/AddType.cs b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/AddType.cs index 93254717a6..51528a5f3e 100644 --- a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/AddType.cs +++ b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/AddType.cs @@ -1059,15 +1059,13 @@ namespace Microsoft.PowerShell.Commands private static PortableExecutableReference ObjectImplementationAssemblyReference = MetadataReference.CreateFromFile(typeof(object).GetTypeInfo().Assembly.Location); - // This assembly should be System.Runtime.dll - private static PortableExecutableReference ObjectDeclaredAssemblyReference = - MetadataReference.CreateFromFile(ClrFacade.GetAssemblies(typeof(object).FullName).First().Location); - - // In CoreCLR 1.0.0 RTM, System.Attribute need to be loaded from mscorlib.dll, - // not from ObjectDeclaredAssemblyReference. - private static PortableExecutableReference AttributeDeclaredAssemblyReference = + private static PortableExecutableReference MscorlibAssemblyReference = MetadataReference.CreateFromFile(Assembly.Load(new AssemblyName("mscorlib")).Location); + // This assembly should be System.Runtime.dll + private static PortableExecutableReference SystemRuntimeAssemblyReference = + MetadataReference.CreateFromFile(ClrFacade.GetAssemblies(typeof(object).FullName).First().Location); + // SecureString is defined in a separate assembly. // This fact is an implementation detail and should not require the user to specify one more assembly, // if they want to use SecureString in Add-Type -TypeDefinition. @@ -1076,22 +1074,22 @@ namespace Microsoft.PowerShell.Commands MetadataReference.CreateFromFile(typeof(System.Security.SecureString).GetTypeInfo().Assembly.Location); - // These assemlbies are automatically added to ReferencedAssemblies. + // These assemlbies are always automatically added to ReferencedAssemblies. private static PortableExecutableReference[] autoReferencedAssemblies = new PortableExecutableReference[] { - ObjectImplementationAssemblyReference, - ObjectDeclaredAssemblyReference, - AttributeDeclaredAssemblyReference, - SecureStringAssemblyReference + MscorlibAssemblyReference, + SystemRuntimeAssemblyReference, + SecureStringAssemblyReference, + ObjectImplementationAssemblyReference }; // These assemlbies are used, when ReferencedAssemblies parameter is not specified. private static PortableExecutableReference[] defaultAssemblies = new PortableExecutableReference[] { - ObjectImplementationAssemblyReference, - ObjectDeclaredAssemblyReference, - AttributeDeclaredAssemblyReference, + MscorlibAssemblyReference, + SystemRuntimeAssemblyReference, SecureStringAssemblyReference, + ObjectImplementationAssemblyReference, MetadataReference.CreateFromFile(typeof(PSObject).GetTypeInfo().Assembly.Location) }; @@ -1233,10 +1231,7 @@ namespace Microsoft.PowerShell.Commands if (referencedAssembliesSpecified) { var tempReferences = ReferencedAssemblies.Select(a => MetadataReference.CreateFromFile(ResolveReferencedAssembly(a))).ToList(); - foreach (var reference in autoReferencedAssemblies) - { - tempReferences.Add(reference); - } + tempReferences.AddRange(autoReferencedAssemblies); references = tempReferences.ToArray(); }