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

Skip to content

Commit d140b01

Browse files
committed
C#: Improve array argument CIL extraction for attributes
1 parent 636ff2d commit d140b01

2 files changed

Lines changed: 68 additions & 57 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 => v.Value?.ToString() ?? "null")) + "]";
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)

0 commit comments

Comments
 (0)