Skip to content

Commit d51b0ab

Browse files
committed
Minor code refactoring
1 parent 3e29388 commit d51b0ab

File tree

2 files changed

+4
-22
lines changed

2 files changed

+4
-22
lines changed

Microsoft.Toolkit.Mvvm.SourceGenerators/ComponentModel/TransitiveMembersGenerator.cs

Lines changed: 3 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -107,20 +107,6 @@ private void OnExecute(
107107
{
108108
ClassDeclarationSyntax sourceDeclaration = sourceSyntaxTree.GetRoot().DescendantNodes().OfType<ClassDeclarationSyntax>().First();
109109
UsingDirectiveSyntax[] usingDirectives = sourceSyntaxTree.GetRoot().DescendantNodes().OfType<UsingDirectiveSyntax>().ToArray();
110-
BaseListSyntax? baseListSyntax = BaseList(SeparatedList(
111-
sourceDeclaration.BaseList?.Types
112-
.OfType<SimpleBaseTypeSyntax>()
113-
.Select(static t => t.Type)
114-
.OfType<IdentifierNameSyntax>()
115-
.Where(static t => t.Identifier.ValueText.StartsWith("I"))
116-
.Select(static t => SimpleBaseType(t))
117-
.ToArray()
118-
?? Array.Empty<BaseTypeSyntax>()));
119-
120-
if (baseListSyntax.Types.Count == 0)
121-
{
122-
baseListSyntax = null;
123-
}
124110

125111
// Create the class declaration for the user type. This will produce a tree as follows:
126112
//
@@ -131,7 +117,7 @@ private void OnExecute(
131117
var classDeclarationSyntax =
132118
ClassDeclaration(classDeclaration.Identifier.Text)
133119
.WithModifiers(classDeclaration.Modifiers)
134-
.WithBaseList(baseListSyntax)
120+
.WithBaseList(sourceDeclaration.BaseList)
135121
.AddMembers(FilterDeclaredMembers(context, attributeData, classDeclaration, classDeclarationSymbol, sourceDeclaration).ToArray());
136122

137123
TypeDeclarationSyntax typeDeclarationSyntax = classDeclarationSyntax;
@@ -151,16 +137,12 @@ private void OnExecute(
151137
// From this, we can finally generate the source code to output.
152138
var namespaceName = classDeclarationSymbol.ContainingNamespace.ToDisplayString(new(typeQualificationStyle: NameAndContainingTypesAndNamespaces));
153139

140+
// Create the final compilation unit to generate (with using directives and the full type declaration)
154141
var source =
155142
CompilationUnit()
156143
.AddMembers(NamespaceDeclaration(IdentifierName(namespaceName))
157144
.AddMembers(typeDeclarationSyntax))
158-
.AddUsings(usingDirectives.First().WithLeadingTrivia(TriviaList(
159-
Comment("// Licensed to the .NET Foundation under one or more agreements."),
160-
Comment("// The .NET Foundation licenses this file to you under the MIT license."),
161-
Comment("// See the LICENSE file in the project root for more information."),
162-
Trivia(PragmaWarningDirectiveTrivia(Token(SyntaxKind.DisableKeyword), true)))))
163-
.AddUsings(usingDirectives.Skip(1).ToArray())
145+
.AddUsings(usingDirectives)
164146
.NormalizeWhitespace()
165147
.ToFullString();
166148

Microsoft.Toolkit.Mvvm.SourceGenerators/EmbeddedResources/ObservableRecipient.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ namespace Microsoft.Toolkit.Mvvm.ComponentModel
1818
/// A base class for observable objects that also acts as recipients for messages. This class is an extension of
1919
/// <see cref="ObservableObject"/> which also provides built-in support to use the <see cref="IMessenger"/> type.
2020
/// </summary>
21-
public abstract class ObservableRecipient : ObservableObject
21+
public abstract class ObservableRecipient
2222
{
2323
/// <summary>
2424
/// Initializes a new instance of the <see cref="ObservableRecipient"/> class.

0 commit comments

Comments
 (0)