From d19b1209c5a2e6387373711faebdb558f6c98a4c Mon Sep 17 00:00:00 2001 From: Glenn Watson Date: Sat, 8 Jun 2019 17:16:57 +1000 Subject: [PATCH] Add a prefix to the generated observables on static classes with the type name --- .../Generation/Generators/EventGeneratorBase.cs | 7 +++++-- .../Generation/Generators/StaticEventGenerator.cs | 2 +- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/Pharmacist.Core/Generation/Generators/EventGeneratorBase.cs b/src/Pharmacist.Core/Generation/Generators/EventGeneratorBase.cs index 4e15d61..bb544a6 100644 --- a/src/Pharmacist.Core/Generation/Generators/EventGeneratorBase.cs +++ b/src/Pharmacist.Core/Generation/Generators/EventGeneratorBase.cs @@ -28,9 +28,12 @@ internal abstract class EventGeneratorBase : IEventGenerator /// /// The details of the event to wrap. /// The name of the item where the event is stored. + /// A prefix to append to the name. /// The property declaration. - protected static PropertyDeclarationSyntax GenerateEventWrapperObservable(IEvent eventDetails, string dataObjectName) + protected static PropertyDeclarationSyntax GenerateEventWrapperObservable(IEvent eventDetails, string dataObjectName, string prefix = null) { + prefix = prefix ?? string.Empty; + // Produces: // public System.IObservable EventName => System.Reactive.Linq.Observable.FromEventPattern(); var invokeMethod = eventDetails.GetEventType().GetDelegateInvokeMethod(); @@ -68,7 +71,7 @@ protected static PropertyDeclarationSyntax GenerateEventWrapperObservable(IEvent ? SyntaxFactory.TokenList(SyntaxFactory.Token(SyntaxKind.PublicKeyword), SyntaxFactory.Token(SyntaxKind.StaticKeyword)) : SyntaxFactory.TokenList(SyntaxFactory.Token(SyntaxKind.PublicKeyword)); - return SyntaxFactory.PropertyDeclaration(observableEventArgType, eventDetails.Name) + return SyntaxFactory.PropertyDeclaration(observableEventArgType, prefix + eventDetails.Name) .WithModifiers(modifiers) .WithExpressionBody(expressionBody) .WithSemicolonToken(SyntaxFactory.Token(SyntaxKind.SemicolonToken)) diff --git a/src/Pharmacist.Core/Generation/Generators/StaticEventGenerator.cs b/src/Pharmacist.Core/Generation/Generators/StaticEventGenerator.cs index ab24fe5..303ead3 100644 --- a/src/Pharmacist.Core/Generation/Generators/StaticEventGenerator.cs +++ b/src/Pharmacist.Core/Generation/Generators/StaticEventGenerator.cs @@ -33,7 +33,7 @@ public override IEnumerable Generate(IEnumerable<(IT x => x.events .OrderBy(eventDetails => eventDetails.Name) - .Select(eventDetails => GenerateEventWrapperObservable(eventDetails, x.typeDefinition.GenerateFullGenericName())) + .Select(eventDetails => GenerateEventWrapperObservable(eventDetails, x.typeDefinition.GenerateFullGenericName(), x.typeDefinition.Name)) .Where(y => y != null)) .ToList();