Skip to content

Commit

Permalink
Sgen: Update progress when importing types (#46415)
Browse files Browse the repository at this point in the history
* Sgen: Update progress when importing types
* Null check
* Remove trailing whitespace
* Updated Strings.resx
* Sgen: Use string resource
  • Loading branch information
TalAloni committed Jun 29, 2021
1 parent 5d29560 commit 53e6b47
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
17 changes: 11 additions & 6 deletions src/libraries/Microsoft.XmlSerializer.Generator/src/Sgen.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ private int Run(string[] args)
bool noLogo = false;
bool parsableErrors = false;
bool silent = false;
bool warnings = false;
bool verbose = false;

AppDomain.CurrentDomain.AssemblyResolve += SgenAssemblyResolver;

Expand Down Expand Up @@ -120,7 +120,7 @@ private int Run(string[] args)
}
else if (ArgumentMatch(arg, "verbose"))
{
warnings = true;
verbose = true;
}
else if (ArgumentMatch(arg, "reference"))
{
Expand Down Expand Up @@ -189,7 +189,7 @@ private int Run(string[] args)
ParseReferences();
}

GenerateFile(types, assembly, proxyOnly, silent, warnings, force, codePath, parsableErrors);
GenerateFile(types, assembly, proxyOnly, silent, verbose, force, codePath, parsableErrors);
}
catch (Exception e)
{
Expand All @@ -205,7 +205,7 @@ private int Run(string[] args)
return 0;
}

private void GenerateFile(List<string> typeNames, string assemblyName, bool proxyOnly, bool silent, bool warnings, bool force, string outputDirectory, bool parsableerrors)
private void GenerateFile(List<string> typeNames, string assemblyName, bool proxyOnly, bool silent, bool verbose, bool force, string outputDirectory, bool parsableerrors)
{
Assembly assembly = LoadAssembly(assemblyName, true);
Type[] types;
Expand Down Expand Up @@ -258,6 +258,11 @@ private void GenerateFile(List<string> typeNames, string assemblyName, bool prox
{
if (type != null)
{
if (verbose)
{
Console.WriteLine(SR.Format(SR.ImportInfo, type.Name, i + 1, types.Length));
}

bool isObsolete = false;
object[] obsoleteAttributes = type.GetCustomAttributes(typeof(ObsoleteAttribute), false);
foreach (object attribute in obsoleteAttributes)
Expand All @@ -278,7 +283,7 @@ private void GenerateFile(List<string> typeNames, string assemblyName, bool prox
//Ignore the FileNotFoundException when call GetCustomAttributes e.g. if the type uses the attributes defined in a different assembly
catch (FileNotFoundException e)
{
if (warnings)
if (verbose)
{
Console.Out.WriteLine(FormatMessage(parsableerrors, true, SR.Format(SR.InfoIgnoreType, type.FullName)));
WriteWarning(e, parsableerrors);
Expand All @@ -289,7 +294,7 @@ private void GenerateFile(List<string> typeNames, string assemblyName, bool prox

if (!proxyOnly)
{
ImportType(type, mappings, importedTypes, warnings, importer, parsableerrors);
ImportType(type, mappings, importedTypes, verbose, importer, parsableerrors);
}
}

Expand Down
3 changes: 3 additions & 0 deletions src/libraries/System.Private.Xml/src/Resources/Strings.resx
Original file line number Diff line number Diff line change
Expand Up @@ -3453,4 +3453,7 @@ Usage: dotnet {0} [--assembly &lt;assembly file path&gt;] [--type &lt;type name&
<data name="CompilingScriptsNotSupported" xml:space="preserve">
<value>Compiling JScript/CSharp scripts is not supported</value>
</data>
<data name="ImportInfo" xml:space="preserve">
<value>Importing {0} ({1}/{2})</value>
</data>
</root>

0 comments on commit 53e6b47

Please sign in to comment.