Skip to content

Commit 136e5c9

Browse files
authored
Merge pull request #4672 from tamasvajk/feature/extract-anon-types
C#: Extract anonymous types explicitly
2 parents 807fc94 + 800fd94 commit 136e5c9

File tree

8 files changed

+6573
-2732
lines changed

8 files changed

+6573
-2732
lines changed

csharp/extractor/Semmle.Extraction.CSharp/Entities/Types/NamedType.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,11 @@ public override void Populate(TextWriter trapFile)
8787
foreach (var l in Locations)
8888
trapFile.type_location(this, l);
8989
}
90+
91+
if (symbol.IsAnonymousType)
92+
{
93+
trapFile.anonymous_types(this);
94+
}
9095
}
9196

9297
private readonly Lazy<Type[]> typeArgumentsLazy;

csharp/extractor/Semmle.Extraction.CSharp/Tuples.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -271,6 +271,11 @@ internal static void extend(this TextWriter trapFile, Type type, Type super)
271271
trapFile.WriteTuple("extend", type, super);
272272
}
273273

274+
internal static void anonymous_types(this TextWriter trapFile, Type type)
275+
{
276+
trapFile.WriteTuple("anonymous_types", type);
277+
}
278+
274279
internal static void field_location(this TextWriter trapFile, Field field, Location location)
275280
{
276281
trapFile.WriteTuple("field_location", field, location);

csharp/ql/src/semmle/code/csharp/Type.qll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -746,7 +746,7 @@ class Class extends RefType, @class_type {
746746
* ```
747747
*/
748748
class AnonymousClass extends Class {
749-
AnonymousClass() { this.getName().matches("<%") }
749+
AnonymousClass() { anonymous_types(this) }
750750
}
751751

752752
/**

csharp/ql/src/semmlecode.csharp.dbscheme

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -413,6 +413,9 @@ extend(
413413
unique int sub: @type ref,
414414
int super: @type_or_ref ref);
415415

416+
anonymous_types(
417+
unique int id: @type ref);
418+
416419
@interface_or_ref = @interface_type | @typeref;
417420

418421
implement(

0 commit comments

Comments
 (0)