Skip to content
Merged
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 @@ -272,7 +272,8 @@ private static EmitResult EmitExpressionTreeForProperty(
{
var thisParam = descriptor.ParametersList.Parameters[0];
var thisTypeFqn = thisParam.Type?.ToString() ?? "object";
emitterParams.Add(new EmitterParameter("@this", thisTypeFqn, isThis: true));
emitterParams.Add(new EmitterParameter(
"@this", thisTypeFqn, symbol: descriptor.ExtensionParameterSymbol, isThis: true));
}

var allTypeArgs = emitterParams.Select(p => p.TypeFqn).ToList();
Expand All @@ -295,7 +296,8 @@ private static List<EmitterParameter> BuildEmitterParameters(
{
var thisParam = descriptor.ParametersList.Parameters[0];
var thisTypeFqn = thisParam.Type?.ToString() ?? "object";
result.Add(new EmitterParameter("@this", thisTypeFqn, isThis: true));
result.Add(new EmitterParameter(
"@this", thisTypeFqn, symbol: descriptor.ExtensionParameterSymbol, isThis: true));
}

foreach (var param in methodSymbol.Parameters)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ static internal partial class ExpressiveInterpreter
var descriptor = BuildBaseDescriptor(
member, memberSymbol, methodSymbol,
isExtensionMember, extensionParameter, extensionReceiverType);
descriptor.ExtensionParameterSymbol = extensionParameter;

foreach (var typeName in expressiveAttribute.TransformerTypeNames)
descriptor.DeclaredTransformerTypeNames.Add(typeName);
Expand Down Expand Up @@ -94,6 +95,12 @@ private static ExpressiveDescriptor BuildBaseDescriptor(
ParametersList = SyntaxFactory.ParameterList()
};

// A `static` member inside an `extension(T) { }` block has no implicit receiver —
// treat it like an ordinary static method on the containing static class.
var isInstanceExtensionMember = isExtensionMember
&& extensionReceiverType is not null
&& !member.Modifiers.Any(SyntaxKind.StaticKeyword);

if (methodSymbol is not null)
{
var parameterTypeNames = methodSymbol.Parameters
Expand All @@ -102,10 +109,10 @@ private static ExpressiveDescriptor BuildBaseDescriptor(

// Prepend the extension receiver type to match how the runtime sees the method
// (receiver is the first implicit parameter).
if (isExtensionMember && extensionReceiverType is not null)
if (isInstanceExtensionMember)
{
parameterTypeNames.Insert(0,
extensionReceiverType.ToDisplayString(SymbolDisplayFormat.FullyQualifiedFormat));
extensionReceiverType!.ToDisplayString(SymbolDisplayFormat.FullyQualifiedFormat));
}

descriptor.ParameterTypeNames = parameterTypeNames;
Expand All @@ -116,12 +123,12 @@ private static ExpressiveDescriptor BuildBaseDescriptor(
SetupGenericTypeParameters(descriptor, classForNaming);
}

if (isExtensionMember && extensionReceiverType is not null)
if (isInstanceExtensionMember)
{
descriptor.ParametersList = descriptor.ParametersList.AddParameters(
SyntaxFactory.Parameter(SyntaxFactory.Identifier("@this"))
.WithType(SyntaxFactory.ParseTypeName(
extensionReceiverType.ToDisplayString(SymbolDisplayFormat.FullyQualifiedFormat))));
extensionReceiverType!.ToDisplayString(SymbolDisplayFormat.FullyQualifiedFormat))));
}
else if (!member.Modifiers.Any(SyntaxKind.StaticKeyword) && member is not ConstructorDeclarationSyntax)
{
Expand All @@ -132,9 +139,9 @@ private static ExpressiveDescriptor BuildBaseDescriptor(
}

// Target class info is used by the registry to associate the projection.
if (isExtensionMember && extensionReceiverType is not null)
if (isInstanceExtensionMember)
{
descriptor.TargetClassNamespace = extensionReceiverType.ContainingNamespace.IsGlobalNamespace
descriptor.TargetClassNamespace = extensionReceiverType!.ContainingNamespace.IsGlobalNamespace
? null
: extensionReceiverType.ContainingNamespace.ToDisplayString();
descriptor.TargetNestedInClassNames = GetNestedInClassPath(extensionReceiverType);
Expand Down
2 changes: 2 additions & 0 deletions src/ExpressiveSharp.Generator/Models/ExpressiveDescriptor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ internal class ExpressiveDescriptor
public ParameterListSyntax? ParametersList { get; set; }

public IEnumerable<string>? ParameterTypeNames { get; set; }

public IParameterSymbol? ExtensionParameterSymbol { get; set; }

public TypeParameterListSyntax? TypeParameterList { get; set; }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,9 @@ namespace ExpressiveSharp.Generated
static global::System.Linq.Expressions.Expression<global::System.Func<global::Foo.Entity, int>> TripleId_P0_Foo_Entity_Expression()
{
var p__this = global::System.Linq.Expressions.Expression.Parameter(typeof(global::Foo.Entity), "@this");
var expr_2 = global::System.Linq.Expressions.Expression.Parameter(typeof(global::Foo.Entity), "e"); // e
var expr_1 = global::System.Linq.Expressions.Expression.Property(expr_2, typeof(global::Foo.Entity).GetProperty("Id", global::System.Reflection.BindingFlags.Public | global::System.Reflection.BindingFlags.NonPublic | global::System.Reflection.BindingFlags.Instance));
var expr_3 = global::System.Linq.Expressions.Expression.Constant(3, typeof(int)); // 3
var expr_0 = global::System.Linq.Expressions.Expression.MakeBinary(global::System.Linq.Expressions.ExpressionType.Multiply, expr_1, expr_3);
var expr_1 = global::System.Linq.Expressions.Expression.Property(p__this, typeof(global::Foo.Entity).GetProperty("Id", global::System.Reflection.BindingFlags.Public | global::System.Reflection.BindingFlags.NonPublic | global::System.Reflection.BindingFlags.Instance)); // e.Id
var expr_2 = global::System.Linq.Expressions.Expression.Constant(3, typeof(int)); // 3
var expr_0 = global::System.Linq.Expressions.Expression.MakeBinary(global::System.Linq.Expressions.ExpressionType.Multiply, expr_1, expr_2);
return global::System.Linq.Expressions.Expression.Lambda<global::System.Func<global::Foo.Entity, int>>(expr_0, p__this);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@ namespace ExpressiveSharp.Generated
{
var p__this = global::System.Linq.Expressions.Expression.Parameter(typeof(global::Foo.Entity), "@this");
var p_factor = global::System.Linq.Expressions.Expression.Parameter(typeof(int), "factor");
var expr_2 = global::System.Linq.Expressions.Expression.Parameter(typeof(global::Foo.Entity), "e"); // e
var expr_1 = global::System.Linq.Expressions.Expression.Property(expr_2, typeof(global::Foo.Entity).GetProperty("Id", global::System.Reflection.BindingFlags.Public | global::System.Reflection.BindingFlags.NonPublic | global::System.Reflection.BindingFlags.Instance));
var expr_1 = global::System.Linq.Expressions.Expression.Property(p__this, typeof(global::Foo.Entity).GetProperty("Id", global::System.Reflection.BindingFlags.Public | global::System.Reflection.BindingFlags.NonPublic | global::System.Reflection.BindingFlags.Instance)); // e.Id
var expr_0 = global::System.Linq.Expressions.Expression.MakeBinary(global::System.Linq.Expressions.ExpressionType.Multiply, expr_1, p_factor);
return global::System.Linq.Expressions.Expression.Lambda<global::System.Func<global::Foo.Entity, int, int>>(expr_0, p__this, p_factor);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,12 @@ namespace ExpressiveSharp.Generated
static global::System.Linq.Expressions.Expression<global::System.Func<global::Foo.IEntity, string>> Label_Expression()
{
var p__this = global::System.Linq.Expressions.Expression.Parameter(typeof(global::Foo.IEntity), "@this");
var expr_4 = global::System.Linq.Expressions.Expression.Parameter(typeof(global::Foo.IEntity), "e"); // e
var expr_3 = global::System.Linq.Expressions.Expression.Property(expr_4, typeof(global::Foo.IEntity).GetProperty("Id", global::System.Reflection.BindingFlags.Public | global::System.Reflection.BindingFlags.NonPublic | global::System.Reflection.BindingFlags.Instance));
var expr_3 = global::System.Linq.Expressions.Expression.Property(p__this, typeof(global::Foo.IEntity).GetProperty("Id", global::System.Reflection.BindingFlags.Public | global::System.Reflection.BindingFlags.NonPublic | global::System.Reflection.BindingFlags.Instance)); // e.Id
var expr_2 = global::System.Linq.Expressions.Expression.Convert(expr_3, typeof(object));
var expr_5 = global::System.Linq.Expressions.Expression.Constant(": ", typeof(string)); // ": "
var expr_1 = global::System.Linq.Expressions.Expression.Call(typeof(string).GetMethod("Concat", global::System.Reflection.BindingFlags.Public | global::System.Reflection.BindingFlags.NonPublic | global::System.Reflection.BindingFlags.Static, null, new global::System.Type[] { typeof(object), typeof(object) }, null), expr_2, expr_5);
var expr_6 = global::System.Linq.Expressions.Expression.Property(expr_4, typeof(global::Foo.IEntity).GetProperty("Name", global::System.Reflection.BindingFlags.Public | global::System.Reflection.BindingFlags.NonPublic | global::System.Reflection.BindingFlags.Instance)); // e.Name
var expr_0 = global::System.Linq.Expressions.Expression.Call(typeof(string).GetMethod("Concat", global::System.Reflection.BindingFlags.Public | global::System.Reflection.BindingFlags.NonPublic | global::System.Reflection.BindingFlags.Static, null, new global::System.Type[] { typeof(string), typeof(string) }, null), expr_1, expr_6);
var expr_4 = global::System.Linq.Expressions.Expression.Constant(": ", typeof(string)); // ": "
var expr_1 = global::System.Linq.Expressions.Expression.Call(typeof(string).GetMethod("Concat", global::System.Reflection.BindingFlags.Public | global::System.Reflection.BindingFlags.NonPublic | global::System.Reflection.BindingFlags.Static, null, new global::System.Type[] { typeof(object), typeof(object) }, null), expr_2, expr_4);
var expr_5 = global::System.Linq.Expressions.Expression.Property(p__this, typeof(global::Foo.IEntity).GetProperty("Name", global::System.Reflection.BindingFlags.Public | global::System.Reflection.BindingFlags.NonPublic | global::System.Reflection.BindingFlags.Instance)); // e.Name
var expr_0 = global::System.Linq.Expressions.Expression.Call(typeof(string).GetMethod("Concat", global::System.Reflection.BindingFlags.Public | global::System.Reflection.BindingFlags.NonPublic | global::System.Reflection.BindingFlags.Static, null, new global::System.Type[] { typeof(string), typeof(string) }, null), expr_1, expr_5);
return global::System.Linq.Expressions.Expression.Lambda<global::System.Func<global::Foo.IEntity, string>>(expr_0, p__this);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@ namespace ExpressiveSharp.Generated
static global::System.Linq.Expressions.Expression<global::System.Func<int, int>> Squared_Expression()
{
var p__this = global::System.Linq.Expressions.Expression.Parameter(typeof(int), "@this");
var expr_1 = global::System.Linq.Expressions.Expression.Parameter(typeof(int), "i"); // i
var expr_0 = global::System.Linq.Expressions.Expression.MakeBinary(global::System.Linq.Expressions.ExpressionType.Multiply, expr_1, expr_1);
var expr_0 = global::System.Linq.Expressions.Expression.MakeBinary(global::System.Linq.Expressions.ExpressionType.Multiply, p__this, p__this); // i * i
return global::System.Linq.Expressions.Expression.Lambda<global::System.Func<int, int>>(expr_0, p__this);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,9 @@ namespace ExpressiveSharp.Generated
static global::System.Linq.Expressions.Expression<global::System.Func<global::Foo.Entity, int>> DoubleId_Expression()
{
var p__this = global::System.Linq.Expressions.Expression.Parameter(typeof(global::Foo.Entity), "@this");
var expr_2 = global::System.Linq.Expressions.Expression.Parameter(typeof(global::Foo.Entity), "e"); // e
var expr_1 = global::System.Linq.Expressions.Expression.Property(expr_2, typeof(global::Foo.Entity).GetProperty("Id", global::System.Reflection.BindingFlags.Public | global::System.Reflection.BindingFlags.NonPublic | global::System.Reflection.BindingFlags.Instance));
var expr_3 = global::System.Linq.Expressions.Expression.Constant(2, typeof(int)); // 2
var expr_0 = global::System.Linq.Expressions.Expression.MakeBinary(global::System.Linq.Expressions.ExpressionType.Multiply, expr_1, expr_3);
var expr_1 = global::System.Linq.Expressions.Expression.Property(p__this, typeof(global::Foo.Entity).GetProperty("Id", global::System.Reflection.BindingFlags.Public | global::System.Reflection.BindingFlags.NonPublic | global::System.Reflection.BindingFlags.Instance)); // e.Id
var expr_2 = global::System.Linq.Expressions.Expression.Constant(2, typeof(int)); // 2
var expr_0 = global::System.Linq.Expressions.Expression.MakeBinary(global::System.Linq.Expressions.ExpressionType.Multiply, expr_1, expr_2);
return global::System.Linq.Expressions.Expression.Lambda<global::System.Func<global::Foo.Entity, int>>(expr_0, p__this);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,14 @@ namespace ExpressiveSharp.Generated
static global::System.Linq.Expressions.Expression<global::System.Func<global::Foo.Entity, string>> GetStatus_P0_Foo_Entity_Expression()
{
var p__this = global::System.Linq.Expressions.Expression.Parameter(typeof(global::Foo.Entity), "@this");
var expr_3 = global::System.Linq.Expressions.Expression.Parameter(typeof(global::Foo.Entity), "e"); // e
var expr_2 = global::System.Linq.Expressions.Expression.Property(expr_3, typeof(global::Foo.Entity).GetProperty("IsActive", global::System.Reflection.BindingFlags.Public | global::System.Reflection.BindingFlags.NonPublic | global::System.Reflection.BindingFlags.Instance));
var expr_5 = global::System.Linq.Expressions.Expression.Property(expr_3, typeof(global::Foo.Entity).GetProperty("Value", global::System.Reflection.BindingFlags.Public | global::System.Reflection.BindingFlags.NonPublic | global::System.Reflection.BindingFlags.Instance)); // e.Value
var expr_6 = global::System.Linq.Expressions.Expression.Constant(0, typeof(int)); // 0
var expr_4 = global::System.Linq.Expressions.Expression.MakeBinary(global::System.Linq.Expressions.ExpressionType.GreaterThan, expr_5, expr_6);
var expr_1 = global::System.Linq.Expressions.Expression.MakeBinary(global::System.Linq.Expressions.ExpressionType.AndAlso, expr_2, expr_4);
var expr_7 = global::System.Linq.Expressions.Expression.Constant("Active", typeof(string)); // "Active"
var expr_8 = global::System.Linq.Expressions.Expression.Constant("Inactive", typeof(string)); // "Inactive"
var expr_0 = global::System.Linq.Expressions.Expression.Condition(expr_1, expr_7, expr_8, typeof(string));
var expr_2 = global::System.Linq.Expressions.Expression.Property(p__this, typeof(global::Foo.Entity).GetProperty("IsActive", global::System.Reflection.BindingFlags.Public | global::System.Reflection.BindingFlags.NonPublic | global::System.Reflection.BindingFlags.Instance)); // e.IsActive
var expr_4 = global::System.Linq.Expressions.Expression.Property(p__this, typeof(global::Foo.Entity).GetProperty("Value", global::System.Reflection.BindingFlags.Public | global::System.Reflection.BindingFlags.NonPublic | global::System.Reflection.BindingFlags.Instance)); // e.Value
var expr_5 = global::System.Linq.Expressions.Expression.Constant(0, typeof(int)); // 0
var expr_3 = global::System.Linq.Expressions.Expression.MakeBinary(global::System.Linq.Expressions.ExpressionType.GreaterThan, expr_4, expr_5);
var expr_1 = global::System.Linq.Expressions.Expression.MakeBinary(global::System.Linq.Expressions.ExpressionType.AndAlso, expr_2, expr_3);
var expr_6 = global::System.Linq.Expressions.Expression.Constant("Active", typeof(string)); // "Active"
var expr_7 = global::System.Linq.Expressions.Expression.Constant("Inactive", typeof(string)); // "Inactive"
var expr_0 = global::System.Linq.Expressions.Expression.Condition(expr_1, expr_6, expr_7, typeof(string));
return global::System.Linq.Expressions.Expression.Lambda<global::System.Func<global::Foo.Entity, string>>(expr_0, p__this);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,10 @@ namespace ExpressiveSharp.Generated
static global::System.Linq.Expressions.Expression<global::System.Func<global::Foo.Entity, bool>> IsHighValue_Expression()
{
var p__this = global::System.Linq.Expressions.Expression.Parameter(typeof(global::Foo.Entity), "@this");
var expr_1 = global::System.Linq.Expressions.Expression.Parameter(typeof(global::Foo.Entity), "e"); // e
var expr_0 = global::System.Linq.Expressions.Expression.Property(expr_1, typeof(global::Foo.Entity).GetProperty("Value", global::System.Reflection.BindingFlags.Public | global::System.Reflection.BindingFlags.NonPublic | global::System.Reflection.BindingFlags.Instance));
var expr_3 = global::System.Linq.Expressions.Expression.Constant(100, typeof(int)); // 100
var expr_2 = global::System.Linq.Expressions.Expression.MakeBinary(global::System.Linq.Expressions.ExpressionType.GreaterThan, expr_0, expr_3);
return global::System.Linq.Expressions.Expression.Lambda<global::System.Func<global::Foo.Entity, bool>>(expr_2, p__this);
var expr_0 = global::System.Linq.Expressions.Expression.Property(p__this, typeof(global::Foo.Entity).GetProperty("Value", global::System.Reflection.BindingFlags.Public | global::System.Reflection.BindingFlags.NonPublic | global::System.Reflection.BindingFlags.Instance)); // e.Value
var expr_2 = global::System.Linq.Expressions.Expression.Constant(100, typeof(int)); // 100
var expr_1 = global::System.Linq.Expressions.Expression.MakeBinary(global::System.Linq.Expressions.ExpressionType.GreaterThan, expr_0, expr_2);
return global::System.Linq.Expressions.Expression.Lambda<global::System.Func<global::Foo.Entity, bool>>(expr_1, p__this);
}
}
}
Loading
Loading