C#: Add some examples of using attributes on properties and indexers for use in external models.

This commit is contained in:
Michael Nebel
2024-09-13 10:23:34 +02:00
parent 3c97bcb790
commit 367bbc4039
2 changed files with 35 additions and 6 deletions

View File

@@ -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 { }
}

View File

@@ -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 { }
}
}