Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@

namespace OrchardCore.ContentTypes.Shapes;

public class ContentCardFieldsEditShape
[GenerateShape]
public partial class ContentCardFieldsEditShape
{
public IShape CardShape { get; set; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@

namespace OrchardCore.ContentTypes.Shapes;

public class ContentCardFrameShape
[GenerateShape]
public partial class ContentCardFrameShape
{
public IShape ChildContent { get; set; }
public int? ColumnSize { get; set; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@

namespace OrchardCore.ContentTypes.Shapes;

public class ContentCardShape
[GenerateShape]
public partial class ContentCardShape
{
public IUpdateModel Updater { get; set; }
public string CollectionShapeType { get; set; }
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
namespace OrchardCore.DisplayManagement;

/// <summary>
/// Marks a model type to generate a compile-time <see cref="IShape"/> implementation.
/// </summary>
/// <remarks>
/// Apply this attribute to a <c>partial</c> class with an accessible parameterless constructor.
/// The source generator will implement <see cref="IShape"/> and <see cref="IPositioned"/> directly on the model type,
/// which avoids both interceptors and runtime proxy generation for that model.
/// </remarks>
[AttributeUsage(AttributeTargets.Class, AllowMultiple = false, Inherited = false)]
public sealed class GenerateShapeAttribute : Attribute
{
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ namespace OrchardCore.DisplayManagement;

public static class ShapeFactoryExtensions
{
private static readonly ConcurrentDictionary<Type, Type> _proxyTypesCache = [];
private static readonly ConcurrentDictionary<Type, Type> _proxyTypeCache = [];
private static readonly ProxyGenerator _proxyGenerator = new();

/// <summary>
Expand Down Expand Up @@ -187,15 +187,12 @@ static async ValueTask<IShape> Awaited(ValueTask task, IShape shape)
/// </remarks>
private static IShape CreateStronglyTypedShape(Type baseType)
{
var shapeType = baseType;

// Don't generate a proxy for shape types.
if (typeof(IShape).IsAssignableFrom(shapeType))
if (typeof(IShape).IsAssignableFrom(baseType))
{
return (IShape)Activator.CreateInstance(baseType);
}

if (_proxyTypesCache.TryGetValue(baseType, out var proxyType))
if (_proxyTypeCache.TryGetValue(baseType, out var proxyType))
{
var model = new ShapeViewModel();

Expand All @@ -206,7 +203,7 @@ private static IShape CreateStronglyTypedShape(Type baseType)
options.AddMixinInstance(new ShapeViewModel());
var shape = (IShape)_proxyGenerator.CreateClassProxy(baseType, options);

_proxyTypesCache.TryAdd(baseType, shape.GetType());
_proxyTypeCache.TryAdd(baseType, shape.GetType());

return shape;
}
Expand Down
Loading
Loading