mirror of
https://github.com/github/codeql.git
synced 2026-04-20 22:44:52 +02:00
C#: Add some examples of using attributes on properties and indexers for use in external models.
This commit is contained in:
@@ -12,6 +12,12 @@ namespace My.Qltest
|
||||
|
||||
object fieldWrite = new object();
|
||||
TaggedField = fieldWrite;
|
||||
|
||||
object propertyWrite = new object();
|
||||
TaggedPropertySetter = propertyWrite;
|
||||
|
||||
object indexerWrite = new object();
|
||||
this[0] = indexerWrite;
|
||||
}
|
||||
|
||||
object SinkMethod()
|
||||
@@ -34,7 +40,21 @@ namespace My.Qltest
|
||||
|
||||
[SinkAttribute]
|
||||
object TaggedField;
|
||||
|
||||
[SinkPropertyAttribute]
|
||||
object TaggedPropertySetter { get; set; }
|
||||
|
||||
[SinkIndexerAttribute]
|
||||
object this[int index]
|
||||
{
|
||||
get { return null; }
|
||||
set { }
|
||||
}
|
||||
}
|
||||
|
||||
class SinkAttribute : System.Attribute { }
|
||||
}
|
||||
|
||||
class SinkPropertyAttribute : System.Attribute { }
|
||||
|
||||
class SinkIndexerAttribute : System.Attribute { }
|
||||
}
|
||||
|
||||
@@ -18,14 +18,17 @@ namespace My.Qltest
|
||||
x = TaggedSrcField;
|
||||
|
||||
x = SrcTwoArg("", "");
|
||||
|
||||
x = TaggedSrcPropertyGetter;
|
||||
x = this[0];
|
||||
}
|
||||
|
||||
[SourceAttribute()]
|
||||
[SourceAttribute]
|
||||
void Tagged1(object taggedMethodParam)
|
||||
{
|
||||
}
|
||||
|
||||
void Tagged2([SourceAttribute()] object taggedSrcParam)
|
||||
void Tagged2([SourceAttribute] object taggedSrcParam)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -49,14 +52,20 @@ namespace My.Qltest
|
||||
|
||||
void SrcArg(object src) { }
|
||||
|
||||
[SourceAttribute()]
|
||||
[SourceAttribute]
|
||||
object TaggedSrcMethod() { return null; }
|
||||
|
||||
[SourceAttribute()]
|
||||
[SourceAttribute]
|
||||
object TaggedSrcField;
|
||||
|
||||
object SrcTwoArg(string s1, string s2) { return null; }
|
||||
|
||||
[SourceAttribute]
|
||||
object TaggedSrcPropertyGetter { get; }
|
||||
|
||||
[SourceAttribute]
|
||||
object this[int i] => null;
|
||||
}
|
||||
|
||||
class SourceAttribute : System.Attribute { }
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user