mirror of
https://github.com/github/codeql.git
synced 2025-12-17 01:03:14 +01:00
C#: Autoformat cookbook examples.
This commit is contained in:
@@ -11,6 +11,7 @@
|
|||||||
import csharp
|
import csharp
|
||||||
|
|
||||||
from CastExpr c
|
from CastExpr c
|
||||||
where c.getExpr().getType() instanceof FloatingPointType
|
where
|
||||||
and c.getType() instanceof IntegralType
|
c.getExpr().getType() instanceof FloatingPointType and
|
||||||
|
c.getType() instanceof IntegralType
|
||||||
select c
|
select c
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
* try
|
* try
|
||||||
* exception
|
* exception
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import csharp
|
import csharp
|
||||||
|
|
||||||
from CatchClause catch
|
from CatchClause catch
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
* constructor
|
* constructor
|
||||||
* new
|
* new
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import csharp
|
import csharp
|
||||||
|
|
||||||
from ObjectCreation new
|
from ObjectCreation new
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
* test
|
* test
|
||||||
* boolean
|
* boolean
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import csharp
|
import csharp
|
||||||
|
|
||||||
from EqualityOperation eq
|
from EqualityOperation eq
|
||||||
|
|||||||
@@ -9,7 +9,7 @@
|
|||||||
* subtype
|
* subtype
|
||||||
* supertype
|
* supertype
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import csharp
|
import csharp
|
||||||
|
|
||||||
from RefType type
|
from RefType type
|
||||||
|
|||||||
@@ -5,11 +5,12 @@
|
|||||||
* @tags field
|
* @tags field
|
||||||
* read
|
* read
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import csharp
|
import csharp
|
||||||
|
|
||||||
from Field f, FieldRead read
|
from Field f, FieldRead read
|
||||||
where f.hasName("VirtualAddress")
|
where
|
||||||
and f.getDeclaringType().hasQualifiedName("Mono.Cecil.PE.Section")
|
f.hasName("VirtualAddress") and
|
||||||
and f = read.getTarget()
|
f.getDeclaringType().hasQualifiedName("Mono.Cecil.PE.Section") and
|
||||||
|
f = read.getTarget()
|
||||||
select read
|
select read
|
||||||
|
|||||||
@@ -5,7 +5,7 @@
|
|||||||
* @tags integer
|
* @tags integer
|
||||||
* literal
|
* literal
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import csharp
|
import csharp
|
||||||
|
|
||||||
from IntegerLiteral literal
|
from IntegerLiteral literal
|
||||||
|
|||||||
@@ -5,11 +5,12 @@
|
|||||||
* @tags call
|
* @tags call
|
||||||
* method
|
* method
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import csharp
|
import csharp
|
||||||
|
|
||||||
from MethodCall call, Method method
|
from MethodCall call, Method method
|
||||||
where call.getTarget() = method
|
where
|
||||||
and method.hasName("MethodName")
|
call.getTarget() = method and
|
||||||
and method.getDeclaringType().hasQualifiedName("Company.Class")
|
method.hasName("MethodName") and
|
||||||
|
method.getDeclaringType().hasQualifiedName("Company.Class")
|
||||||
select call
|
select call
|
||||||
|
|||||||
@@ -9,8 +9,8 @@
|
|||||||
import csharp
|
import csharp
|
||||||
|
|
||||||
from Method m, Method n
|
from Method m, Method n
|
||||||
where m.calls(n)
|
where
|
||||||
and n.calls(m)
|
m.calls(n) and
|
||||||
and m != n
|
n.calls(m) and
|
||||||
|
m != n
|
||||||
select m, n
|
select m, n
|
||||||
|
|
||||||
|
|||||||
@@ -8,12 +8,16 @@
|
|||||||
* collection
|
* collection
|
||||||
* add
|
* add
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import csharp
|
import csharp
|
||||||
|
|
||||||
from MethodCall call, Method add
|
from MethodCall call, Method add
|
||||||
where call.getTarget() = add.getAnUltimateImplementor*()
|
where
|
||||||
and add.hasName("Add")
|
call.getTarget() = add.getAnUltimateImplementor*() and
|
||||||
and add.getDeclaringType().getSourceDeclaration().hasQualifiedName("System.Collections.Generic.ICollection<>")
|
add.hasName("Add") and
|
||||||
and call.getAnArgument() instanceof NullLiteral
|
add
|
||||||
|
.getDeclaringType()
|
||||||
|
.getSourceDeclaration()
|
||||||
|
.hasQualifiedName("System.Collections.Generic.ICollection<>") and
|
||||||
|
call.getAnArgument() instanceof NullLiteral
|
||||||
select call
|
select call
|
||||||
|
|||||||
@@ -5,11 +5,12 @@
|
|||||||
* @tags method
|
* @tags method
|
||||||
* override
|
* override
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import csharp
|
import csharp
|
||||||
|
|
||||||
from Method override, Method base
|
from Method override, Method base
|
||||||
where base.hasName("ToString")
|
where
|
||||||
and base.getDeclaringType().hasQualifiedName("System.Object")
|
base.hasName("ToString") and
|
||||||
and base.getAnOverrider() = override
|
base.getDeclaringType().hasQualifiedName("System.Object") and
|
||||||
|
base.getAnOverrider() = override
|
||||||
select override
|
select override
|
||||||
|
|||||||
@@ -10,8 +10,9 @@
|
|||||||
import csharp
|
import csharp
|
||||||
|
|
||||||
from SwitchStmt switch, Enum enum, EnumConstant missing
|
from SwitchStmt switch, Enum enum, EnumConstant missing
|
||||||
where switch.getCondition().getType() = enum
|
where
|
||||||
and missing.getDeclaringType() = enum
|
switch.getCondition().getType() = enum and
|
||||||
and not switch.getAConstCase().getExpr() = missing.getAnAccess()
|
missing.getDeclaringType() = enum and
|
||||||
and not exists(switch.getDefaultCase())
|
not switch.getAConstCase().getExpr() = missing.getAnAccess() and
|
||||||
|
not exists(switch.getDefaultCase())
|
||||||
select switch
|
select switch
|
||||||
|
|||||||
@@ -10,7 +10,8 @@
|
|||||||
import csharp
|
import csharp
|
||||||
|
|
||||||
from ConditionalExpr e
|
from ConditionalExpr e
|
||||||
where e.getThen().stripImplicitCasts() != e.getElse().stripImplicitCasts()
|
where
|
||||||
and not e.getThen().getType() instanceof NullType
|
e.getThen().stripImplicitCasts() != e.getElse().stripImplicitCasts() and
|
||||||
and not e.getElse().getType() instanceof NullType
|
not e.getThen().getType() instanceof NullType and
|
||||||
|
not e.getElse().getType() instanceof NullType
|
||||||
select e
|
select e
|
||||||
|
|||||||
@@ -5,7 +5,7 @@
|
|||||||
* @tags throw
|
* @tags throw
|
||||||
* exception
|
* exception
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import csharp
|
import csharp
|
||||||
|
|
||||||
from ThrowStmt throw
|
from ThrowStmt throw
|
||||||
|
|||||||
@@ -11,6 +11,7 @@
|
|||||||
import csharp
|
import csharp
|
||||||
|
|
||||||
from TryStmt t
|
from TryStmt t
|
||||||
where exists(t.getFinally())
|
where
|
||||||
and not exists(t.getACatchClause())
|
exists(t.getFinally()) and
|
||||||
|
not exists(t.getACatchClause())
|
||||||
select t
|
select t
|
||||||
|
|||||||
Reference in New Issue
Block a user