C#: Add extensions test.

This commit is contained in:
Michael Nebel
2026-02-04 16:31:27 +01:00
parent 849823eff6
commit c040daab9c
7 changed files with 412 additions and 0 deletions

View File

@@ -0,0 +1,30 @@
using System;
using System.Diagnostics.CodeAnalysis;
public static class MyExtensionTypes
{
extension([NotNull] string s)
{
public void M11() { }
}
extension(ref readonly int i1)
{
public void M21() { }
}
extension(in int i2)
{
public void M31() { }
}
extension(ref int i3)
{
public void M41() { }
}
extension(string? s)
{
public void M51() { }
}
extension<T1>([NotNullWhen(true)] T1 t1) where T1 : class
{
public void M61<T2>(object o, T2 t2) { }
}
}

View File

@@ -0,0 +1,37 @@
extensionTypeReceiverParameter
| extensionTypes.cs:6:5:9:5 | extension(String) | extensionTypes.cs:6:32:6:32 | s |
| extensionTypes.cs:10:5:13:5 | extension(Int32) | extensionTypes.cs:10:32:10:33 | i1 |
| extensionTypes.cs:14:5:17:5 | extension(Int32) | extensionTypes.cs:14:22:14:23 | i2 |
| extensionTypes.cs:18:5:21:5 | extension(Int32) | extensionTypes.cs:18:23:18:24 | i3 |
| extensionTypes.cs:22:5:25:5 | extension(String) | extensionTypes.cs:22:23:22:23 | s |
| extensionTypes.cs:26:5:29:5 | extension(T1)`1 | extensionTypes.cs:26:42:26:43 | t1 |
| extensions.cs:6:5:17:5 | extension(String) | extensions.cs:6:22:6:22 | s |
| extensions.cs:26:5:35:5 | extension(Object)<Object> | extensions.cs:26:20:26:20 | t |
| extensions.cs:26:5:35:5 | extension(String)<String> | extensions.cs:26:20:26:20 | t |
| extensions.cs:26:5:35:5 | extension(T)`1 | extensions.cs:26:20:26:20 | t |
extensionTypeExtendedType
| extensionTypes.cs:6:5:9:5 | extension(String) | string |
| extensionTypes.cs:10:5:13:5 | extension(Int32) | int |
| extensionTypes.cs:14:5:17:5 | extension(Int32) | int |
| extensionTypes.cs:18:5:21:5 | extension(Int32) | int |
| extensionTypes.cs:22:5:25:5 | extension(String) | string |
| extensionTypes.cs:26:5:29:5 | extension(T1)`1 | T1 |
| extensions.cs:6:5:17:5 | extension(String) | string |
| extensions.cs:19:5:24:5 | extension(Object) | object |
| extensions.cs:26:5:35:5 | extension(Object)<Object> | object |
| extensions.cs:26:5:35:5 | extension(String)<String> | string |
| extensions.cs:26:5:35:5 | extension(T)`1 | T |
extensionTypeReceiverParameterAttribute
| extensionTypes.cs:6:5:9:5 | extension(String) | extensionTypes.cs:6:32:6:32 | s | extensionTypes.cs:6:16:6:22 | [NotNull(...)] |
| extensionTypes.cs:26:5:29:5 | extension(T1)`1 | extensionTypes.cs:26:42:26:43 | t1 | extensionTypes.cs:26:20:26:30 | [NotNullWhen(...)] |
extensionTypeReceiverParameterModifier
| extensionTypes.cs:10:5:13:5 | extension(Int32) | extensionTypes.cs:10:32:10:33 | i1 | ref readonly |
| extensionTypes.cs:14:5:17:5 | extension(Int32) | extensionTypes.cs:14:22:14:23 | i2 | in |
| extensionTypes.cs:18:5:21:5 | extension(Int32) | extensionTypes.cs:18:23:18:24 | i3 | ref |
extensionTypeParameterConstraints
| extensionTypes.cs:26:5:29:5 | extension(T1)`1 | extensionTypes.cs:26:15:26:16 | T1 | file://:0:0:0:0 | where T1: ... |
| extensions.cs:26:5:35:5 | extension(T)`1 | extensions.cs:26:15:26:15 | T | file://:0:0:0:0 | where T: ... |
syntheticParameterModifier
| extensionTypes.cs:10:5:13:5 | extension(Int32) | extensionTypes.cs:12:21:12:23 | M21 | extensionTypes.cs:10:32:10:33 | i1 | ref readonly |
| extensionTypes.cs:14:5:17:5 | extension(Int32) | extensionTypes.cs:16:21:16:23 | M31 | extensionTypes.cs:14:22:14:23 | i2 | in |
| extensionTypes.cs:18:5:21:5 | extension(Int32) | extensionTypes.cs:20:21:20:23 | M41 | extensionTypes.cs:18:23:18:24 | i3 | ref |

View File

@@ -0,0 +1,56 @@
import csharp
private predicate inTestFile(ExtensionType et) {
et.getFile().getBaseName() = ["extensions.cs", "extensionTypes.cs"]
}
private string getModifier(Parameter p) {
p.isIn() and result = "in"
or
p.isRef() and result = "ref"
or
p.isReadonlyRef() and result = "ref readonly"
}
query predicate extensionTypeReceiverParameter(ExtensionType et, Parameter p) {
inTestFile(et) and
p = et.getReceiverParameter()
}
query predicate extensionTypeExtendedType(ExtensionType et, string t) {
inTestFile(et) and
t = et.getExtendedType().toStringWithTypes()
}
query predicate extensionTypeReceiverParameterAttribute(ExtensionType et, Parameter p, Attribute a) {
inTestFile(et) and
et.getReceiverParameter() = p and
p.getAnAttribute() = a
}
query predicate extensionTypeReceiverParameterModifier(
ExtensionType et, Parameter p, string modifier
) {
inTestFile(et) and
et.getReceiverParameter() = p and
modifier = getModifier(p)
}
query predicate extensionTypeParameterConstraints(
UnboundGeneric ug, TypeParameter tp, TypeParameterConstraints c
) {
inTestFile(ug) and
ug instanceof ExtensionType and
tp = ug.getATypeParameter() and
tp.getConstraints() = c
}
query predicate syntheticParameterModifier(
ExtensionType et, ExtensionMethod em, Parameter p, string modifier
) {
inTestFile(et) and
em.getDeclaringType() = et and
p = em.getParameter(0) and
not em.isStatic() and
modifier = getModifier(p)
}

View File

@@ -0,0 +1,107 @@
using System;
using System.Collections.Generic;
public static class MyExtensions
{
extension(string s)
{
public bool Prop1 => s.Length > 0;
public bool Prop2 { get { return true; } set { } }
public static bool StaticProp1 { get { return false; } }
public bool M1() => s is not null;
public string M2(string other) { return s + other; }
public static int StaticM1() { return 0; }
public static int StaticM2(string x) { return x.Length; }
public static string operator *(int a, string b) { return ""; }
public T StringGenericM1<T>(T t, object o) { return t; }
}
extension(object)
{
public static int StaticObjectM1() { return 0; }
public static int StaticObjectM2(string s) { return s.Length; }
public static bool StaticProp => true;
}
extension<T>(T t) where T : class
{
public bool GenericProp1 => t is not null;
public bool GenericProp2 { get { return true; } set { } }
public bool GenericM1() => t is not null;
public void GenericM2<S>(S other) { }
public void GenericStaticM1() { }
public static void GenericStaticM2<S>(S other) { }
public static T operator +(T a, T b) { return null; }
}
}
public static class ClassicExtensions
{
public static bool M3(this string s) => s is not null;
}
public class C
{
public static void CallingExtensions()
{
var s = "Hello World.";
// Calling the extensions properties
var x11 = s.Prop1;
var x12 = s.Prop2;
s.Prop2 = true;
var x13 = string.StaticProp1;
var x14 = object.StaticProp;
// Calling the extensions methods.
var x21 = s.M1();
var x22 = s.M2("!!!");
var x23 = string.StaticM1();
var x24 = string.StaticM2(s);
var x25 = object.StaticObjectM1();
var x26 = object.StaticObjectM2(s);
// Calling the extension operator.
var x30 = 3 * s;
// Calling the classic extension method.
var y = s.M3();
// Calling the compiler generated static extension methods.
MyExtensions.M1(s);
MyExtensions.M2(s, "!!!");
MyExtensions.StaticM1();
MyExtensions.StaticM2(s);
MyExtensions.StaticObjectM1();
MyExtensions.StaticObjectM2(s);
// Calling the compiler generated operator method.
MyExtensions.op_Multiply(3, s);
// Calling the compiler generated methods used by the extension property accessors.
MyExtensions.get_Prop1(s);
MyExtensions.get_Prop2(s);
MyExtensions.set_Prop2(s, false);
MyExtensions.get_StaticProp();
}
public static void CallingGenericExtensions()
{
var s = "Hello Generic World.";
var o = new object();
// Calling generic extension method
o.GenericM1();
s.GenericM1();
// Calling the compiler generated static extension methods.
MyExtensions.GenericM1(o);
MyExtensions.GenericM1(s);
o.GenericM2(42);
MyExtensions.GenericM2(o, 42);
s.StringGenericM1<int>(7, new object());
MyExtensions.StringGenericM1<string>(s, "test", new object());
}
}

View File

@@ -0,0 +1,111 @@
extensionMethodCallArgument
| extensions.cs:57:19:57:24 | call to method M1 | extensions.cs:11:21:11:22 | M1 | extensions.cs:6:22:6:22 | s | 0 | extensions.cs:57:19:57:19 | access to local variable s |
| extensions.cs:58:19:58:29 | call to method M2 | extensions.cs:12:23:12:24 | M2 | extensions.cs:6:22:6:22 | s | 0 | extensions.cs:58:19:58:19 | access to local variable s |
| extensions.cs:58:19:58:29 | call to method M2 | extensions.cs:12:23:12:24 | M2 | extensions.cs:12:33:12:37 | other | 1 | extensions.cs:58:24:58:28 | "!!!" |
| extensions.cs:60:19:60:36 | call to method StaticM2 | extensions.cs:14:27:14:34 | StaticM2 | extensions.cs:14:43:14:43 | x | 0 | extensions.cs:60:35:60:35 | access to local variable s |
| extensions.cs:62:19:62:42 | call to method StaticObjectM2 | extensions.cs:22:27:22:40 | StaticObjectM2 | extensions.cs:22:49:22:49 | s | 0 | extensions.cs:62:41:62:41 | access to local variable s |
| extensions.cs:68:17:68:22 | call to method M3 | extensions.cs:40:24:40:25 | M3 | extensions.cs:40:39:40:39 | s | 0 | extensions.cs:68:17:68:17 | access to local variable s |
| extensions.cs:71:9:71:26 | call to method M1 | extensions.cs:11:21:11:22 | M1 | extensions.cs:6:22:6:22 | s | 0 | extensions.cs:71:25:71:25 | access to local variable s |
| extensions.cs:72:9:72:33 | call to method M2 | extensions.cs:12:23:12:24 | M2 | extensions.cs:6:22:6:22 | s | 0 | extensions.cs:72:25:72:25 | access to local variable s |
| extensions.cs:72:9:72:33 | call to method M2 | extensions.cs:12:23:12:24 | M2 | extensions.cs:12:33:12:37 | other | 1 | extensions.cs:72:28:72:32 | "!!!" |
| extensions.cs:74:9:74:32 | call to method StaticM2 | extensions.cs:14:27:14:34 | StaticM2 | extensions.cs:14:43:14:43 | x | 0 | extensions.cs:74:31:74:31 | access to local variable s |
| extensions.cs:76:9:76:38 | call to method StaticObjectM2 | extensions.cs:22:27:22:40 | StaticObjectM2 | extensions.cs:22:49:22:49 | s | 0 | extensions.cs:76:37:76:37 | access to local variable s |
| extensions.cs:94:9:94:21 | call to method GenericM1 | extensions.cs:30:21:30:29 | GenericM1 | extensions.cs:26:20:26:20 | t | 0 | extensions.cs:94:9:94:9 | access to local variable o |
| extensions.cs:95:9:95:21 | call to method GenericM1 | extensions.cs:30:21:30:29 | GenericM1 | extensions.cs:26:20:26:20 | t | 0 | extensions.cs:95:9:95:9 | access to local variable s |
| extensions.cs:98:9:98:33 | call to method GenericM1 | extensions.cs:30:21:30:29 | GenericM1 | extensions.cs:26:20:26:20 | t | 0 | extensions.cs:98:32:98:32 | access to local variable o |
| extensions.cs:99:9:99:33 | call to method GenericM1 | extensions.cs:30:21:30:29 | GenericM1 | extensions.cs:26:20:26:20 | t | 0 | extensions.cs:99:32:99:32 | access to local variable s |
| extensions.cs:101:9:101:23 | call to method GenericM2<Int32> | extensions.cs:31:21:31:32 | GenericM2<Int32> | extensions.cs:26:20:26:20 | t | 0 | extensions.cs:101:9:101:9 | access to local variable o |
| extensions.cs:101:9:101:23 | call to method GenericM2<Int32> | extensions.cs:31:21:31:32 | GenericM2<Int32> | extensions.cs:31:36:31:40 | other | 1 | extensions.cs:101:21:101:22 | 42 |
| extensions.cs:102:9:102:37 | call to method GenericM2<Int32> | extensions.cs:31:21:31:32 | GenericM2<Int32> | extensions.cs:26:20:26:20 | t | 0 | extensions.cs:102:32:102:32 | access to local variable o |
| extensions.cs:102:9:102:37 | call to method GenericM2<Int32> | extensions.cs:31:21:31:32 | GenericM2<Int32> | extensions.cs:31:36:31:40 | other | 1 | extensions.cs:102:35:102:36 | 42 |
| extensions.cs:104:9:104:47 | call to method StringGenericM1<Int32> | extensions.cs:16:18:16:35 | StringGenericM1<Int32> | extensions.cs:6:22:6:22 | s | 0 | extensions.cs:104:9:104:9 | access to local variable s |
| extensions.cs:104:9:104:47 | call to method StringGenericM1<Int32> | extensions.cs:16:18:16:35 | StringGenericM1<Int32> | extensions.cs:16:39:16:39 | t | 1 | extensions.cs:104:32:104:32 | 7 |
| extensions.cs:104:9:104:47 | call to method StringGenericM1<Int32> | extensions.cs:16:18:16:35 | StringGenericM1<Int32> | extensions.cs:16:49:16:49 | o | 2 | extensions.cs:104:35:104:46 | object creation of type Object |
| extensions.cs:105:9:105:69 | call to method StringGenericM1<String> | extensions.cs:16:18:16:35 | StringGenericM1<String> | extensions.cs:6:22:6:22 | s | 0 | extensions.cs:105:46:105:46 | access to local variable s |
| extensions.cs:105:9:105:69 | call to method StringGenericM1<String> | extensions.cs:16:18:16:35 | StringGenericM1<String> | extensions.cs:16:39:16:39 | t | 1 | extensions.cs:105:49:105:54 | "test" |
| extensions.cs:105:9:105:69 | call to method StringGenericM1<String> | extensions.cs:16:18:16:35 | StringGenericM1<String> | extensions.cs:16:49:16:49 | o | 2 | extensions.cs:105:57:105:68 | object creation of type Object |
extensionMethodCalls
| extensions.cs:57:19:57:24 | call to method M1 | extensions.cs:11:21:11:22 | M1 | extensions.cs:6:5:17:5 | extension(String) | MyExtensions+extension(String).M1 |
| extensions.cs:58:19:58:29 | call to method M2 | extensions.cs:12:23:12:24 | M2 | extensions.cs:6:5:17:5 | extension(String) | MyExtensions+extension(String).M2 |
| extensions.cs:59:19:59:35 | call to method StaticM1 | extensions.cs:13:27:13:34 | StaticM1 | extensions.cs:6:5:17:5 | extension(String) | MyExtensions+extension(String).StaticM1 |
| extensions.cs:60:19:60:36 | call to method StaticM2 | extensions.cs:14:27:14:34 | StaticM2 | extensions.cs:6:5:17:5 | extension(String) | MyExtensions+extension(String).StaticM2 |
| extensions.cs:61:19:61:41 | call to method StaticObjectM1 | extensions.cs:21:27:21:40 | StaticObjectM1 | extensions.cs:19:5:24:5 | extension(Object) | MyExtensions+extension(Object).StaticObjectM1 |
| extensions.cs:62:19:62:42 | call to method StaticObjectM2 | extensions.cs:22:27:22:40 | StaticObjectM2 | extensions.cs:19:5:24:5 | extension(Object) | MyExtensions+extension(Object).StaticObjectM2 |
| extensions.cs:68:17:68:22 | call to method M3 | extensions.cs:40:24:40:25 | M3 | extensions.cs:38:21:38:37 | ClassicExtensions | ClassicExtensions.M3 |
| extensions.cs:71:9:71:26 | call to method M1 | extensions.cs:11:21:11:22 | M1 | extensions.cs:6:5:17:5 | extension(String) | MyExtensions+extension(String).M1 |
| extensions.cs:72:9:72:33 | call to method M2 | extensions.cs:12:23:12:24 | M2 | extensions.cs:6:5:17:5 | extension(String) | MyExtensions+extension(String).M2 |
| extensions.cs:73:9:73:31 | call to method StaticM1 | extensions.cs:13:27:13:34 | StaticM1 | extensions.cs:6:5:17:5 | extension(String) | MyExtensions+extension(String).StaticM1 |
| extensions.cs:74:9:74:32 | call to method StaticM2 | extensions.cs:14:27:14:34 | StaticM2 | extensions.cs:6:5:17:5 | extension(String) | MyExtensions+extension(String).StaticM2 |
| extensions.cs:75:9:75:37 | call to method StaticObjectM1 | extensions.cs:21:27:21:40 | StaticObjectM1 | extensions.cs:19:5:24:5 | extension(Object) | MyExtensions+extension(Object).StaticObjectM1 |
| extensions.cs:76:9:76:38 | call to method StaticObjectM2 | extensions.cs:22:27:22:40 | StaticObjectM2 | extensions.cs:19:5:24:5 | extension(Object) | MyExtensions+extension(Object).StaticObjectM2 |
| extensions.cs:94:9:94:21 | call to method GenericM1 | extensions.cs:30:21:30:29 | GenericM1 | extensions.cs:26:5:35:5 | extension(Object)<Object> | MyExtensions+extension(Object)<System.Object>.GenericM1 |
| extensions.cs:95:9:95:21 | call to method GenericM1 | extensions.cs:30:21:30:29 | GenericM1 | extensions.cs:26:5:35:5 | extension(String)<String> | MyExtensions+extension(String)<System.String>.GenericM1 |
| extensions.cs:98:9:98:33 | call to method GenericM1 | extensions.cs:30:21:30:29 | GenericM1 | extensions.cs:26:5:35:5 | extension(Object)<Object> | MyExtensions+extension(Object)<System.Object>.GenericM1 |
| extensions.cs:99:9:99:33 | call to method GenericM1 | extensions.cs:30:21:30:29 | GenericM1 | extensions.cs:26:5:35:5 | extension(String)<String> | MyExtensions+extension(String)<System.String>.GenericM1 |
| extensions.cs:101:9:101:23 | call to method GenericM2<Int32> | extensions.cs:31:21:31:32 | GenericM2<Int32> | extensions.cs:26:5:35:5 | extension(Object)<Object> | MyExtensions+extension(Object)<System.Object>.GenericM2<Int32> |
| extensions.cs:102:9:102:37 | call to method GenericM2<Int32> | extensions.cs:31:21:31:32 | GenericM2<Int32> | extensions.cs:26:5:35:5 | extension(Object)<Object> | MyExtensions+extension(Object)<System.Object>.GenericM2<Int32> |
| extensions.cs:104:9:104:47 | call to method StringGenericM1<Int32> | extensions.cs:16:18:16:35 | StringGenericM1<Int32> | extensions.cs:6:5:17:5 | extension(String) | MyExtensions+extension(String).StringGenericM1<Int32> |
| extensions.cs:105:9:105:69 | call to method StringGenericM1<String> | extensions.cs:16:18:16:35 | StringGenericM1<String> | extensions.cs:6:5:17:5 | extension(String) | MyExtensions+extension(String).StringGenericM1<String> |
extensionParameter
| extensions.cs:11:21:11:22 | M1 | extensions.cs:6:22:6:22 | s | 0 | string | extensions.cs:6:22:6:22 | s |
| extensions.cs:12:23:12:24 | M2 | extensions.cs:6:22:6:22 | s | 0 | string | extensions.cs:6:22:6:22 | s |
| extensions.cs:12:23:12:24 | M2 | extensions.cs:12:33:12:37 | other | 1 | string | extensions.cs:12:33:12:37 | other |
| extensions.cs:14:27:14:34 | StaticM2 | extensions.cs:14:43:14:43 | x | 0 | string | extensions.cs:14:43:14:43 | x |
| extensions.cs:16:18:16:35 | StringGenericM1<Int32> | extensions.cs:6:22:6:22 | s | 0 | string | extensions.cs:6:22:6:22 | s |
| extensions.cs:16:18:16:35 | StringGenericM1<Int32> | extensions.cs:16:39:16:39 | t | 1 | int | extensions.cs:16:39:16:39 | t |
| extensions.cs:16:18:16:35 | StringGenericM1<Int32> | extensions.cs:16:49:16:49 | o | 2 | object | extensions.cs:16:49:16:49 | o |
| extensions.cs:16:18:16:35 | StringGenericM1<String> | extensions.cs:6:22:6:22 | s | 0 | string | extensions.cs:6:22:6:22 | s |
| extensions.cs:16:18:16:35 | StringGenericM1<String> | extensions.cs:16:39:16:39 | t | 1 | string | extensions.cs:16:39:16:39 | t |
| extensions.cs:16:18:16:35 | StringGenericM1<String> | extensions.cs:16:49:16:49 | o | 2 | object | extensions.cs:16:49:16:49 | o |
| extensions.cs:16:18:16:35 | StringGenericM1`1 | extensions.cs:6:22:6:22 | s | 0 | string | extensions.cs:6:22:6:22 | s |
| extensions.cs:16:18:16:35 | StringGenericM1`1 | extensions.cs:16:39:16:39 | t | 1 | T | extensions.cs:16:39:16:39 | t |
| extensions.cs:16:18:16:35 | StringGenericM1`1 | extensions.cs:16:49:16:49 | o | 2 | object | extensions.cs:16:49:16:49 | o |
| extensions.cs:22:27:22:40 | StaticObjectM2 | extensions.cs:22:49:22:49 | s | 0 | string | extensions.cs:22:49:22:49 | s |
| extensions.cs:30:21:30:29 | GenericM1 | extensions.cs:26:20:26:20 | t | 0 | T | extensions.cs:26:20:26:20 | t |
| extensions.cs:30:21:30:29 | GenericM1 | extensions.cs:26:20:26:20 | t | 0 | object | extensions.cs:26:20:26:20 | t |
| extensions.cs:30:21:30:29 | GenericM1 | extensions.cs:26:20:26:20 | t | 0 | string | extensions.cs:26:20:26:20 | t |
| extensions.cs:31:21:31:32 | GenericM2<Int32> | extensions.cs:26:20:26:20 | t | 0 | object | extensions.cs:26:20:26:20 | t |
| extensions.cs:31:21:31:32 | GenericM2<Int32> | extensions.cs:31:36:31:40 | other | 1 | int | extensions.cs:31:36:31:40 | other |
| extensions.cs:31:21:31:32 | GenericM2`1 | extensions.cs:26:20:26:20 | t | 0 | T | extensions.cs:26:20:26:20 | t |
| extensions.cs:31:21:31:32 | GenericM2`1 | extensions.cs:26:20:26:20 | t | 0 | object | extensions.cs:26:20:26:20 | t |
| extensions.cs:31:21:31:32 | GenericM2`1 | extensions.cs:26:20:26:20 | t | 0 | string | extensions.cs:26:20:26:20 | t |
| extensions.cs:31:21:31:32 | GenericM2`1 | extensions.cs:31:36:31:40 | other | 1 | S | extensions.cs:31:36:31:40 | other |
| extensions.cs:31:21:31:32 | GenericM2`1 | extensions.cs:31:36:31:40 | other | 1 | S | extensions.cs:31:36:31:40 | other |
| extensions.cs:31:21:31:32 | GenericM2`1 | extensions.cs:31:36:31:40 | other | 1 | S | extensions.cs:31:36:31:40 | other |
| extensions.cs:32:21:32:35 | GenericStaticM1 | extensions.cs:26:20:26:20 | t | 0 | T | extensions.cs:26:20:26:20 | t |
| extensions.cs:32:21:32:35 | GenericStaticM1 | extensions.cs:26:20:26:20 | t | 0 | object | extensions.cs:26:20:26:20 | t |
| extensions.cs:32:21:32:35 | GenericStaticM1 | extensions.cs:26:20:26:20 | t | 0 | string | extensions.cs:26:20:26:20 | t |
| extensions.cs:33:28:33:45 | GenericStaticM2`1 | extensions.cs:33:49:33:53 | other | 0 | S | extensions.cs:33:49:33:53 | other |
| extensions.cs:33:28:33:45 | GenericStaticM2`1 | extensions.cs:33:49:33:53 | other | 0 | S | extensions.cs:33:49:33:53 | other |
| extensions.cs:33:28:33:45 | GenericStaticM2`1 | extensions.cs:33:49:33:53 | other | 0 | S | extensions.cs:33:49:33:53 | other |
| extensions.cs:40:24:40:25 | M3 | extensions.cs:40:39:40:39 | s | 0 | string | extensions.cs:40:39:40:39 | s |
extensionOperatorCallArgument
| extensions.cs:15:39:15:39 | * | extensions.cs:65:19:65:23 | call to operator * | extensions.cs:15:45:15:45 | a | 0 | extensions.cs:65:19:65:19 | 3 |
| extensions.cs:15:39:15:39 | * | extensions.cs:65:19:65:23 | call to operator * | extensions.cs:15:55:15:55 | b | 1 | extensions.cs:65:23:65:23 | access to local variable s |
| extensions.cs:15:39:15:39 | * | extensions.cs:79:9:79:38 | call to operator * | extensions.cs:15:45:15:45 | a | 0 | extensions.cs:79:34:79:34 | 3 |
| extensions.cs:15:39:15:39 | * | extensions.cs:79:9:79:38 | call to operator * | extensions.cs:15:55:15:55 | b | 1 | extensions.cs:79:37:79:37 | access to local variable s |
extensionOperatorCalls
| extensions.cs:65:19:65:23 | call to operator * | extensions.cs:15:39:15:39 | * | extensions.cs:6:5:17:5 | extension(String) | MyExtensions+extension(String).op_Multiply |
| extensions.cs:79:9:79:38 | call to operator * | extensions.cs:15:39:15:39 | * | extensions.cs:6:5:17:5 | extension(String) | MyExtensions+extension(String).op_Multiply |
extensionProperty
| extensions.cs:8:21:8:25 | Prop1 | extensions.cs:6:5:17:5 | extension(String) |
| extensions.cs:9:21:9:25 | Prop2 | extensions.cs:6:5:17:5 | extension(String) |
| extensions.cs:10:28:10:38 | StaticProp1 | extensions.cs:6:5:17:5 | extension(String) |
| extensions.cs:23:28:23:37 | StaticProp | extensions.cs:19:5:24:5 | extension(Object) |
| extensions.cs:28:21:28:32 | GenericProp1 | extensions.cs:26:5:35:5 | extension(Object)<Object> |
| extensions.cs:28:21:28:32 | GenericProp1 | extensions.cs:26:5:35:5 | extension(String)<String> |
| extensions.cs:28:21:28:32 | GenericProp1 | extensions.cs:26:5:35:5 | extension(T)`1 |
| extensions.cs:29:21:29:32 | GenericProp2 | extensions.cs:26:5:35:5 | extension(Object)<Object> |
| extensions.cs:29:21:29:32 | GenericProp2 | extensions.cs:26:5:35:5 | extension(String)<String> |
| extensions.cs:29:21:29:32 | GenericProp2 | extensions.cs:26:5:35:5 | extension(T)`1 |
extensionPropertyCall
| extensions.cs:50:19:50:25 | access to property Prop1 | extensions.cs:8:21:8:25 | Prop1 | extensions.cs:6:5:17:5 | extension(String) | MyExtensions+extension(String).Prop1 |
| extensions.cs:51:19:51:25 | access to property Prop2 | extensions.cs:9:21:9:25 | Prop2 | extensions.cs:6:5:17:5 | extension(String) | MyExtensions+extension(String).Prop2 |
| extensions.cs:52:9:52:15 | access to property Prop2 | extensions.cs:9:21:9:25 | Prop2 | extensions.cs:6:5:17:5 | extension(String) | MyExtensions+extension(String).Prop2 |
| extensions.cs:53:19:53:36 | access to property StaticProp1 | extensions.cs:10:28:10:38 | StaticProp1 | extensions.cs:6:5:17:5 | extension(String) | MyExtensions+extension(String).StaticProp1 |
| extensions.cs:54:19:54:35 | access to property StaticProp | extensions.cs:23:28:23:37 | StaticProp | extensions.cs:19:5:24:5 | extension(Object) | MyExtensions+extension(Object).StaticProp |
extensionAccessorCall
| extensions.cs:82:9:82:33 | call to extension accessor get_Prop1 | extensions.cs:8:30:8:41 | get_Prop1 | extensions.cs:8:21:8:25 | Prop1 | MyExtensions+extension(String).get_Prop1 |
| extensions.cs:83:9:83:33 | call to extension accessor get_Prop2 | extensions.cs:9:29:9:31 | get_Prop2 | extensions.cs:9:21:9:25 | Prop2 | MyExtensions+extension(String).get_Prop2 |
| extensions.cs:84:9:84:40 | call to extension accessor set_Prop2 | extensions.cs:9:50:9:52 | set_Prop2 | extensions.cs:9:21:9:25 | Prop2 | MyExtensions+extension(String).set_Prop2 |
| extensions.cs:85:9:85:37 | call to extension accessor get_StaticProp | extensions.cs:23:42:23:45 | get_StaticProp | extensions.cs:23:28:23:37 | StaticProp | MyExtensions+extension(Object).get_StaticProp |

View File

@@ -0,0 +1,69 @@
import csharp
query predicate extensionMethodCallArgument(
ExtensionMethodCall emc, ExtensionMethod em, Parameter p, int i, Expr e
) {
em.getFile().getBaseName() = "extensions.cs" and
emc.getTarget() = em and
em.getParameter(i) = p and
emc.getArgument(i) = e
}
query predicate extensionMethodCalls(
ExtensionMethodCall emc, ExtensionMethod em, Type t, string type
) {
em.getFile().getBaseName() = "extensions.cs" and
emc.getTarget() = em and
em.getDeclaringType() = t and
em.getFullyQualifiedNameDebug() = type
}
query predicate extensionParameter(
ExtensionMethod em, Parameter p, int i, string type, Parameter unbound
) {
em.getFile().getBaseName() = "extensions.cs" and
p = em.getParameter(i) and
type = p.getType().toStringWithTypes() and
unbound = p.getUnboundDeclaration()
}
query predicate extensionOperatorCallArgument(
ExtensionOperator op, ExtensionOperatorCall opc, Parameter p, int pos, Expr e
) {
opc.getTarget() = op and
op.getFile().getBaseName() = "extensions.cs" and
p = op.getParameter(pos) and
e = opc.getArgument(pos)
}
query predicate extensionOperatorCalls(
ExtensionOperatorCall opc, ExtensionOperator op, Type t, string type
) {
op.getFile().getBaseName() = "extensions.cs" and
opc.getTarget() = op and
op.getDeclaringType() = t and
op.getFullyQualifiedNameDebug() = type
}
query predicate extensionProperty(ExtensionProperty p, Type t) {
p.getFile().getBaseName() = "extensions.cs" and
p.getDeclaringType() = t
}
query predicate extensionPropertyCall(
ExtensionPropertyCall pc, ExtensionProperty p, Type t, string type
) {
p.getFile().getBaseName() = "extensions.cs" and
pc.getProperty() = p and
p.getDeclaringType() = t and
p.getFullyQualifiedNameDebug() = type
}
query predicate extensionAccessorCall(
MethodCall m, ExtensionAccessor a, ExtensionProperty p, string type
) {
p.getFile().getBaseName() = "extensions.cs" and
(a.(Getter).getDeclaration() = p or a.(Setter).getDeclaration() = p) and
m.getTargetAccessor() = a and
a.getFullyQualifiedNameDebug() = type
}

View File

@@ -0,0 +1,2 @@
semmle-extractor-options: /nostdlib /noconfig
semmle-extractor-options: --load-sources-from-project:${testdir}/../../resources/stubs/_frameworks/Microsoft.NETCore.App/Microsoft.NETCore.App.csproj