Skip to content

Commit

Permalink
Automated dotnet-format update (#1096)
Browse files Browse the repository at this point in the history
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
  • Loading branch information
github-actions[bot] authored May 27, 2021
1 parent 29dd7c6 commit ed636dd
Showing 1 changed file with 18 additions and 18 deletions.
36 changes: 18 additions & 18 deletions src/Controls/src/SourceGen/CodeBehindGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public class CodeBehindGenerator : ISourceGenerator
"case", "catch", "char", "checked", "class", "const", "continue",
"decimal", "default", "delegate", "do", "double",
"else", "enum", "event", "explicit", "extern",
"false", "finally", "fixed", "float", "for", "foreach",
"false", "finally", "fixed", "float", "for", "foreach",
"goto",
"if", "implicit", "in", "int", "interface", "internal", "is",
"lock", "long", "namespace", "new", "null",
Expand Down Expand Up @@ -62,7 +62,7 @@ public void Execute(GeneratorExecutionContext context)
continue;
if (!context.AnalyzerConfigOptions.GetOptions(file).TryGetValue("build_metadata.additionalfiles.TargetPath", out string? name))
name = file.Path;
name = $"{(string.IsNullOrEmpty(Path.GetDirectoryName(name))? "" : Path.GetDirectoryName(name) + Path.DirectorySeparatorChar )}{Path.GetFileNameWithoutExtension(name)}.{kind.ToLowerInvariant()}.sg.cs".Replace(Path.DirectorySeparatorChar, '_');
name = $"{(string.IsNullOrEmpty(Path.GetDirectoryName(name)) ? "" : Path.GetDirectoryName(name) + Path.DirectorySeparatorChar)}{Path.GetFileNameWithoutExtension(name)}.{kind.ToLowerInvariant()}.sg.cs".Replace(Path.DirectorySeparatorChar, '_');
context.AddSource(name, SourceText.From(code, Encoding.UTF8));
}
}
Expand Down Expand Up @@ -104,9 +104,9 @@ bool TryGenerateXamlCodeBehind(AdditionalText file, GeneratorExecutionContext co

var sb = new StringBuilder();
var opt = context.AnalyzerConfigOptions.GetOptions(file);
if ( context.AnalyzerConfigOptions.GetOptions(file).TryGetValue("build_metadata.additionalfiles.ManifestResourceName", out string? manifestResourceName)
if (context.AnalyzerConfigOptions.GetOptions(file).TryGetValue("build_metadata.additionalfiles.ManifestResourceName", out string? manifestResourceName)
&& context.AnalyzerConfigOptions.GetOptions(file).TryGetValue("build_metadata.additionalfiles.TargetPath", out string? targetPath))
sb.AppendLine($"[assembly: global::Microsoft.Maui.Controls.Xaml.XamlResourceId(\"{manifestResourceName}\", \"{targetPath.Replace('\\','/')}\", {(rootType == null ? "null" : "typeof(global::"+rootClrNamespace+"."+rootType+")")})]");
sb.AppendLine($"[assembly: global::Microsoft.Maui.Controls.Xaml.XamlResourceId(\"{manifestResourceName}\", \"{targetPath.Replace('\\', '/')}\", {(rootType == null ? "null" : "typeof(global::" + rootClrNamespace + "." + rootType + ")")})]");
if (XamlResourceIdOnly)
{
code = sb.ToString();
Expand All @@ -127,7 +127,7 @@ bool TryGenerateXamlCodeBehind(AdditionalText file, GeneratorExecutionContext co

sb.AppendLine($"\tpublic partial class {rootType} : {baseType}");
sb.AppendLine("\t{");

//optional default ctor
if (generateDefaultCtor)
{
Expand All @@ -144,8 +144,8 @@ bool TryGenerateXamlCodeBehind(AdditionalText file, GeneratorExecutionContext co
foreach ((var fname, var ftype, var faccess) in namedFields)
{
sb.AppendLine($"\t\t[global::System.CodeDom.Compiler.GeneratedCode(\"Microsoft.Maui.Controls.SourceGen\", \"1.0.0.0\")]");
sb.AppendLine($"\t\t{faccess} {ftype} {(_CSharpKeywords.Contains(fname) ? "@"+fname: fname)};");

sb.AppendLine($"\t\t{faccess} {ftype} {(_CSharpKeywords.Contains(fname) ? "@" + fname : fname)};");
sb.AppendLine();
}

Expand All @@ -157,7 +157,7 @@ bool TryGenerateXamlCodeBehind(AdditionalText file, GeneratorExecutionContext co
if (namedFields != null)
foreach ((var fname, var ftype, var faccess) in namedFields)
sb.AppendLine($"\t\t\t{(_CSharpKeywords.Contains(fname) ? "@" + fname : fname)} = global::Microsoft.Maui.Controls.NameScopeExtensions.FindByName<{ftype}>(this, \"{fname}\");");

sb.AppendLine("\t\t}");
sb.AppendLine("\t}");
sb.AppendLine("}");
Expand All @@ -167,7 +167,7 @@ bool TryGenerateXamlCodeBehind(AdditionalText file, GeneratorExecutionContext co
}
}

bool TryParseXaml(TextReader xaml, GeneratorExecutionContext context, IList<XmlnsDefinitionAttribute> xmlnsDefinitionCache, out string? rootType, out string? rootClrNamespace, out bool generateDefaultCtor, out bool addXamlCompilationAttribute, out bool hideFromIntellisense, out bool xamlResourceIdOnly, out string? baseType, out IEnumerable<(string,string,string)>? namedFields)
bool TryParseXaml(TextReader xaml, GeneratorExecutionContext context, IList<XmlnsDefinitionAttribute> xmlnsDefinitionCache, out string? rootType, out string? rootClrNamespace, out bool generateDefaultCtor, out bool addXamlCompilationAttribute, out bool hideFromIntellisense, out bool xamlResourceIdOnly, out string? baseType, out IEnumerable<(string, string, string)>? namedFields)
{
rootType = null;
rootClrNamespace = null;
Expand Down Expand Up @@ -266,7 +266,7 @@ static bool GetXamlCompilationProcessingInstruction(XmlDocument xmlDoc)
: null);

var accessModifier = fieldModifier?.ToLowerInvariant().Replace("notpublic", "internal") ?? "private"; //notpublic is WPF for internal
if (!new []{ "private", "public", "internal", "protected"}.Contains(accessModifier)) //quick validation
if (!new[] { "private", "public", "internal", "protected" }.Contains(accessModifier)) //quick validation
accessModifier = "private";
yield return (name ?? "", GetTypeName(xmlType, context, xmlnsDefinitionCache), accessModifier);
}
Expand All @@ -283,7 +283,7 @@ string GetTypeName(XmlType xmlType, GeneratorExecutionContext context, IList<Xml
// It's an external, non-built-in namespace URL.
returnType = GetTypeNameFromCustomNamespace(xmlType, context, xmlnsDefinitionCache);
}

if (xmlType.TypeArguments != null)
returnType = $"{returnType}<{string.Join(", ", xmlType.TypeArguments.Select(typeArg => GetTypeName(typeArg, context, xmlnsDefinitionCache)))}>";

Expand Down Expand Up @@ -341,20 +341,20 @@ bool TryGenerateCssCodeBehind(AdditionalText file, GeneratorExecutionContext con
{
var sb = new StringBuilder();
var opt = context.AnalyzerConfigOptions.GetOptions(file);
if ( context.AnalyzerConfigOptions.GetOptions(file).TryGetValue("build_metadata.additionalfiles.ManifestResourceName", out string? manifestResourceName)
&& context.AnalyzerConfigOptions.GetOptions(file).TryGetValue("build_metadata.additionalfiles.TargetPath", out string? targetPath))
sb.AppendLine($"[assembly: global::Microsoft.Maui.Controls.Xaml.XamlResourceId(\"{manifestResourceName}\", \"{targetPath.Replace('\\','/')}\", null)]");
if (context.AnalyzerConfigOptions.GetOptions(file).TryGetValue("build_metadata.additionalfiles.ManifestResourceName", out string? manifestResourceName)
&& context.AnalyzerConfigOptions.GetOptions(file).TryGetValue("build_metadata.additionalfiles.TargetPath", out string? targetPath))
sb.AppendLine($"[assembly: global::Microsoft.Maui.Controls.Xaml.XamlResourceId(\"{manifestResourceName}\", \"{targetPath.Replace('\\', '/')}\", null)]");

code = sb.ToString();
return true;
}

public void Initialize(GeneratorInitializationContext context)
{
//#if DEBUG
// if (!Debugger.IsAttached)
// Debugger.Launch();
//#endif
//#if DEBUG
// if (!Debugger.IsAttached)
// Debugger.Launch();
//#endif
}
}
}

0 comments on commit ed636dd

Please sign in to comment.