2 using System.Collections.Generic;
5 using System.Reflection;
10 namespace SiliconStudio.Paradox.PublicApiCheck
25 var assembly = AssemblyDefinition.ReadAssembly(assemblyRef);
26 return assembly.MainModule.Types.SelectMany(GetPublicApiItems);
39 yield
return type.FullName;
41 foreach (var field
in type.Fields.Where(field => (field.IsPublic || field.IsAssembly)))
43 yield
return field.FullName;
46 foreach (var property
in type.Properties)
48 if (property.GetMethod != null && (property.GetMethod.IsPublic || property.GetMethod.IsAssembly))
49 yield
return property.GetMethod.FullName;
51 if (property.SetMethod != null && (property.SetMethod.IsPublic || property.SetMethod.IsAssembly))
52 yield
return property.SetMethod.FullName;
55 foreach (var method
in type.Methods)
57 if (method.IsPublic || method.IsAssembly)
59 if (method.IsSetter || method.IsGetter)
62 yield
return method.FullName;
75 var fromTypes = GetPublicApiItems(from);
76 var toTypes = GetPublicApiItems(to);
78 return fromTypes.Except(toTypes).ToList();
89 var diff = DiffAssembly(from, to);
92 var output =
new StringBuilder();
93 output.AppendFormat(
"{0} public missing in {1}", diff.Count, Path.GetFileName(to));
95 foreach (var diffItem
in diff)
97 output.AppendLine(diffItem);
99 return output.ToString();
104 static void Main(
string[] args)
106 if (args.Length != 2)
108 Console.WriteLine(
"{0} assemblyRef assemblyAgainst", Path.GetFileName(Assembly.GetEntryAssembly().Location));
109 Environment.Exit(-1);
112 var diff = DiffAssemblyToString(args[0], args[1]);
115 Console.WriteLine(diff);
116 Environment.Exit(-1);
static string DiffAssemblyToString(string from, string to)
Performs a diff between the public API of two assemblies.
static List< string > DiffAssembly(string from, string to)
Performs a diff between the public API of two assemblies.
static IEnumerable< string > GetPublicApiItems(string assemblyRef)
Gets all the public API as string items from an assembly.
static IEnumerable< string > GetPublicApiItems(TypeDefinition type)
Gets all the public API as string items from a type.
Helper class to check public API consistency between assemblies.