Skip to content

Commit

Permalink
Expose building typeinspector since it's used in other areas
Browse files Browse the repository at this point in the history
  • Loading branch information
EdwardCooke committed Jul 14, 2024
1 parent c428589 commit 30cced2
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 14 deletions.
6 changes: 5 additions & 1 deletion YamlDotNet/Serialization/DeserializerBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,11 @@ public DeserializerBuilder()

protected override DeserializerBuilder Self { get { return this; } }

internal ITypeInspector BuildTypeInspector()
/// <summary>
/// Builds the type inspector used by various classes to get information about types and their members.
/// </summary>
/// <returns></returns>
public ITypeInspector BuildTypeInspector()
{
ITypeInspector innerInspector = new WritablePropertiesTypeInspector(typeResolver, includeNonPublicProperties);

Expand Down
31 changes: 25 additions & 6 deletions YamlDotNet/Serialization/SerializerBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -158,10 +158,14 @@ public SerializerBuilder WithMaximumRecursion(int maximumRecursion)
/// </summary>
/// <param name="eventEmitterFactory">A function that instantiates the event emitter.</param>
public SerializerBuilder WithEventEmitter<TEventEmitter>(Func<IEventEmitter, TEventEmitter> eventEmitterFactory)
where TEventEmitter : IEventEmitter
{
return WithEventEmitter(eventEmitterFactory, w => w.OnTop());
}
where TEventEmitter : IEventEmitter => WithEventEmitter(eventEmitterFactory, w => w.OnTop());

/// <summary>
/// Registers an additional <see cref="IEventEmitter" /> to be used by the serializer.
/// </summary>
/// <param name="eventEmitterFactory">A function that instantiates the event emitter.</param>
public SerializerBuilder WithEventEmitter<TEventEmitter>(Func<IEventEmitter, ITypeInspector, TEventEmitter> eventEmitterFactory)
where TEventEmitter : IEventEmitter => WithEventEmitter(eventEmitterFactory, w => w.OnTop());

/// <summary>
/// Registers an additional <see cref="IEventEmitter" /> to be used by the serializer.
Expand All @@ -171,6 +175,16 @@ public SerializerBuilder WithEventEmitter<TEventEmitter>(Func<IEventEmitter, TEv
public SerializerBuilder WithEventEmitter<TEventEmitter>(
Func<IEventEmitter, TEventEmitter> eventEmitterFactory,
Action<IRegistrationLocationSelectionSyntax<IEventEmitter>> where
) where TEventEmitter : IEventEmitter => WithEventEmitter((IEventEmitter e, ITypeInspector _) => eventEmitterFactory(e), where);

/// <summary>
/// Registers an additional <see cref="IEventEmitter" /> to be used by the serializer.
/// </summary>
/// <param name="eventEmitterFactory">A function that instantiates the event emitter.</param>
/// <param name="where">Configures the location where to insert the <see cref="IEventEmitter" /></param>
public SerializerBuilder WithEventEmitter<TEventEmitter>(
Func<IEventEmitter, ITypeInspector, TEventEmitter> eventEmitterFactory,
Action<IRegistrationLocationSelectionSyntax<IEventEmitter>> where
)
where TEventEmitter : IEventEmitter
{
Expand All @@ -184,10 +198,11 @@ Action<IRegistrationLocationSelectionSyntax<IEventEmitter>> where
throw new ArgumentNullException(nameof(where));
}

where(eventEmitterFactories.CreateRegistrationLocationSelector(typeof(TEventEmitter), inner => eventEmitterFactory(inner)));
where(eventEmitterFactories.CreateRegistrationLocationSelector(typeof(TEventEmitter), inner => eventEmitterFactory(inner, BuildTypeInspector())));
return Self;
}


/// <summary>
/// Registers an additional <see cref="IEventEmitter" /> to be used by the serializer.
/// </summary>
Expand Down Expand Up @@ -695,7 +710,11 @@ public IValueSerializer BuildValueSerializer()
);
}

internal ITypeInspector BuildTypeInspector()
/// <summary>
/// Builds the type inspector used by various classes to get information about types and their members.
/// </summary>
/// <returns></returns>
public ITypeInspector BuildTypeInspector()
{
ITypeInspector innerInspector = new ReadablePropertiesTypeInspector(typeResolver, includeNonPublicProperties);

Expand Down
6 changes: 5 additions & 1 deletion YamlDotNet/Serialization/StaticDeserializerBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,11 @@ public StaticDeserializerBuilder(StaticContext context)

protected override StaticDeserializerBuilder Self { get { return this; } }

internal ITypeInspector BuildTypeInspector()
/// <summary>
/// Builds the type inspector used by various classes to get information about types and their members.
/// </summary>
/// <returns></returns>
public ITypeInspector BuildTypeInspector()
{
ITypeInspector innerInspector = context.GetTypeInspector();

Expand Down
32 changes: 26 additions & 6 deletions YamlDotNet/Serialization/StaticSerializerBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -164,10 +164,14 @@ public StaticSerializerBuilder WithMaximumRecursion(int maximumRecursion)
/// </summary>
/// <param name="eventEmitterFactory">A function that instantiates the event emitter.</param>
public StaticSerializerBuilder WithEventEmitter<TEventEmitter>(Func<IEventEmitter, TEventEmitter> eventEmitterFactory)
where TEventEmitter : IEventEmitter
{
return WithEventEmitter(eventEmitterFactory, w => w.OnTop());
}
where TEventEmitter : IEventEmitter => WithEventEmitter(eventEmitterFactory, w => w.OnTop());

/// <summary>
/// Registers an additional <see cref="IEventEmitter" /> to be used by the serializer.
/// </summary>
/// <param name="eventEmitterFactory">A function that instantiates the event emitter.</param>
public StaticSerializerBuilder WithEventEmitter<TEventEmitter>(Func<IEventEmitter, ITypeInspector, TEventEmitter> eventEmitterFactory)
where TEventEmitter : IEventEmitter => WithEventEmitter(eventEmitterFactory, w => w.OnTop());

/// <summary>
/// Registers an additional <see cref="IEventEmitter" /> to be used by the serializer.
Expand All @@ -177,6 +181,16 @@ public StaticSerializerBuilder WithEventEmitter<TEventEmitter>(Func<IEventEmitte
public StaticSerializerBuilder WithEventEmitter<TEventEmitter>(
Func<IEventEmitter, TEventEmitter> eventEmitterFactory,
Action<IRegistrationLocationSelectionSyntax<IEventEmitter>> where
) where TEventEmitter : IEventEmitter => WithEventEmitter((IEventEmitter e, ITypeInspector _) => eventEmitterFactory(e), where);

/// <summary>
/// Registers an additional <see cref="IEventEmitter" /> to be used by the serializer.
/// </summary>
/// <param name="eventEmitterFactory">A function that instantiates the event emitter.</param>
/// <param name="where">Configures the location where to insert the <see cref="IEventEmitter" /></param>
public StaticSerializerBuilder WithEventEmitter<TEventEmitter>(
Func<IEventEmitter, ITypeInspector, TEventEmitter> eventEmitterFactory,
Action<IRegistrationLocationSelectionSyntax<IEventEmitter>> where
)
where TEventEmitter : IEventEmitter
{
Expand All @@ -190,10 +204,11 @@ Action<IRegistrationLocationSelectionSyntax<IEventEmitter>> where
throw new ArgumentNullException(nameof(where));
}

where(eventEmitterFactories.CreateRegistrationLocationSelector(typeof(TEventEmitter), inner => eventEmitterFactory(inner)));
where(eventEmitterFactories.CreateRegistrationLocationSelector(typeof(TEventEmitter), inner => eventEmitterFactory(inner, BuildTypeInspector())));
return Self;
}


/// <summary>
/// Registers an additional <see cref="IEventEmitter" /> to be used by the serializer.
/// </summary>
Expand All @@ -219,6 +234,7 @@ Action<ITrackingRegistrationLocationSelectionSyntax<IEventEmitter>> where
return Self;
}


/// <summary>
/// Unregisters an existing <see cref="IEventEmitter" /> of type <typeparam name="TEventEmitter" />.
/// </summary>
Expand Down Expand Up @@ -698,7 +714,11 @@ public IValueSerializer BuildValueSerializer()
);
}

internal ITypeInspector BuildTypeInspector()
/// <summary>
/// Builds the type inspector used by various classes to get information about types and their members.
/// </summary>
/// <returns></returns>
public ITypeInspector BuildTypeInspector()
{
var typeInspector = context.GetTypeInspector();

Expand Down

0 comments on commit 30cced2

Please sign in to comment.