Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit ec573b5

Browse files
authored
Merge pull request #4759 from tamasvajk/feature/cil-attribute-array
C#: Improve array argument CIL extraction for attributes
2 parents 3bddb94 + cbcae66 commit ec573b5

4 files changed

Lines changed: 2668 additions & 4 deletions

File tree

csharp/extractor/Semmle.Extraction.CIL/Entities/Attribute.cs

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System;
22
using System.Collections.Generic;
3+
using System.Linq;
34
using System.Reflection.Metadata;
45

56
namespace Semmle.Extraction.CIL.Entities
@@ -51,19 +52,29 @@ public override IEnumerable<IExtractionProduct> Contents
5152
for (var index = 0; index < decoded.FixedArguments.Length; ++index)
5253
{
5354
var value = decoded.FixedArguments[index].Value;
54-
var stringValue = value?.ToString();
55-
yield return Tuples.cil_attribute_positional_argument(this, index, stringValue ?? "null");
55+
var stringValue = GetStringValue(value);
56+
yield return Tuples.cil_attribute_positional_argument(this, index, stringValue);
5657
}
5758

5859
foreach (var p in decoded.NamedArguments)
5960
{
6061
var value = p.Value;
61-
var stringValue = value?.ToString();
62-
yield return Tuples.cil_attribute_named_argument(this, p.Name, stringValue ?? "null");
62+
var stringValue = GetStringValue(value);
63+
yield return Tuples.cil_attribute_named_argument(this, p.Name, stringValue);
6364
}
6465
}
6566
}
6667

68+
private static string GetStringValue(object? value)
69+
{
70+
if (value is System.Collections.Immutable.ImmutableArray<CustomAttributeTypedArgument<Type>> values)
71+
{
72+
return "[" + string.Join(",", values.Select(v => GetStringValue(v.Value))) + "]";
73+
}
74+
75+
return value?.ToString() ?? "null";
76+
}
77+
6778
public static IEnumerable<IExtractionProduct> Populate(Context cx, IEntity @object, CustomAttributeHandleCollection attributes)
6879
{
6980
foreach (var attrib in attributes)
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// semmle-extractor-options: --cil
2+
3+
using System;
4+
5+
class Test
6+
{
7+
}

0 commit comments

Comments
 (0)