Skip to content

Commit

Permalink
Add a prefix to the generated observables on static classes with the …
Browse files Browse the repository at this point in the history
…type name
  • Loading branch information
glennawatson committed Jun 8, 2019
1 parent a5bd805 commit d19b120
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,12 @@ internal abstract class EventGeneratorBase : IEventGenerator
/// </summary>
/// <param name="eventDetails">The details of the event to wrap.</param>
/// <param name="dataObjectName">The name of the item where the event is stored.</param>
/// <param name="prefix">A prefix to append to the name.</param>
/// <returns>The property declaration.</returns>
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<eventArgs, eventHandler> EventName => System.Reactive.Linq.Observable.FromEventPattern();
var invokeMethod = eventDetails.GetEventType().GetDelegateInvokeMethod();
Expand Down Expand Up @@ -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))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public override IEnumerable<NamespaceDeclarationSyntax> 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();

Expand Down

0 comments on commit d19b120

Please sign in to comment.