Skip to content

Commit 92f4a67

Browse files
committed
Minor fixes to StaticAnalysis
1 parent 1d025bf commit 92f4a67

File tree

3 files changed

+28
-5
lines changed

3 files changed

+28
-5
lines changed

tools/StaticAnalysis/BreakingChangeAttributesAnalyzer/BreakingChangeAttributesAnalyzer.cs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@
1212
// limitations under the License.
1313
// ----------------------------------------------------------------------------------
1414

15+
#if !NETSTANDARD
16+
using Microsoft.WindowsAzure.Commands.Common.CustomAttributes;
17+
#endif
1518
using StaticAnalysis.BreakingChangeAnalyzer;
1619
using System;
1720
using System.Collections.Generic;
@@ -229,7 +232,13 @@ private void LogBreakingChangesInModule(BreakingChangeAttributesInModule moduleD
229232
foreach (BreakingChangeAttributesInCmdlet cmdletData in moduleData.CmdletList)
230233
{
231234
textForBreakingChangesInModule += string.Format(BREAKING_CHANGE_CMDLET_HEADER_FORMAT_STRING, cmdletData.CmdletName);
232-
}
235+
#if !NETSTANDARD
236+
foreach (GenericBreakingChangeAttribute attribute in cmdletData.BreakingChangeAttributes)
237+
{
238+
textForBreakingChangesInModule += attribute.GetBreakingChangeTextFromAttribute(cmdletData.CmdletType, true) + "\n\n";
239+
}
240+
#endif
241+
}
233242

234243
//Now that we have the text, add it to the log file
235244
logger.LogMessage(textForBreakingChangesInModule);

tools/StaticAnalysis/BreakingChangeAttributesAnalyzer/CmdletBreakingChangeAttributeLoader.cs

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@
1818
using System.Linq;
1919
using System.Reflection;
2020
using System.Management.Automation;
21+
#if !NETSTANDARD
22+
using Microsoft.WindowsAzure.Commands.Common.CustomAttributes;
23+
#endif
2124
using Tools.Common.Extensions;
2225

2326
namespace StaticAnalysis.BreakingChangeAttributesAnalyzer
@@ -37,6 +40,9 @@ public class BreakingChangeAttributesInCmdlet
3740
{
3841
public Type CmdletType { get; set; }
3942
public string CmdletName { get; set; }
43+
#if !NETSTANDARD
44+
public List<GenericBreakingChangeAttribute> BreakingChangeAttributes { get; set; }
45+
#endif
4046
}
4147

4248
public class CmdletBreakingChangeAttributeLoader : MarshalByRefObject
@@ -56,11 +62,19 @@ public BreakingChangeAttributesInModule GetModuleBreakingChangeAttributes(string
5662
foreach (var type in assembly.GetCmdletTypes())
5763
{
5864
var cmdlet = type.GetAttribute<CmdletAttribute>();
65+
#if !NETSTANDARD
66+
var attributes = type.GetAttributes<GenericBreakingChangeAttribute>();
67+
68+
if (attributes != null && (attributes.Count() > 0)) { }
69+
#endif
5970
var cmdletMetadata = new BreakingChangeAttributesInCmdlet
6071
{
6172
CmdletType = type,
62-
CmdletName = cmdlet.VerbName + "-" + cmdlet.NounName
63-
};
73+
CmdletName = cmdlet.VerbName + "-" + cmdlet.NounName,
74+
#if !NETSTANDARD
75+
BreakingChangeAttributes = attributes.ToList()
76+
#endif
77+
};
6478

6579
results.Add(cmdletMetadata);
6680
}

tools/Tools.Common/Loaders/AssemblyLoader.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,10 +73,10 @@ public AssemblyMetadata GetReflectedAssemblyFromFile(string assemblyPath)
7373
#else
7474
return new AssemblyMetadata(AssemblyLoadContext.Default.LoadFromAssemblyPath(assemblyPath));
7575
}
76-
catch(System.IO.FileLoadException ex) when (string.Equals(ex.Message, "Assembly with same name is already loaded"))
76+
catch(System.IO.FileLoadException ex) when (ex != null && string.Equals(ex.Message, "Assembly with same name is already loaded"))
7777
{
7878
var assemblyName = AssemblyLoadContext.GetAssemblyName(assemblyPath);
79-
var assembly = AppDomain.CurrentDomain.GetAssemblies().Where(a => a.GetName().Name == assemblyName.Name).FirstOrDefault();
79+
var assembly = AppDomain.CurrentDomain.GetAssemblies().Where(a => a.GetName().Name == assemblyName?.Name).FirstOrDefault();
8080
if (assembly != null)
8181
{
8282
result = new AssemblyMetadata(assembly);

0 commit comments

Comments
 (0)