Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -626,7 +626,14 @@ private bool TryGetAttributeProperties(AttributeData attributeData, Location? at
}
else
{
attrProperties[namedArgument.Key] = namedArgument.Value.Value;
if (TryParseValueByType(namedArgument.Value, out object? argValue))
{
attrProperties[namedArgument.Key] = argValue;
}
else
{
// throw diagnostic error
}
}
}
}
Expand Down Expand Up @@ -657,7 +664,7 @@ private bool TryGetAttributeProperties(AttributeData attributeData, Location? at
return true;
}

private bool TryLoadConstructorArguments(AttributeData attributeData, IDictionary<string, object?> dict, Location? attribLocation)
private bool TryLoadConstructorArguments(AttributeData attributeData, IDictionary<string, object?> argsDict, Location? attribLocation)
Comment thread
satvu marked this conversation as resolved.
Outdated
{
IMethodSymbol? attribMethodSymbol = attributeData.AttributeConstructor;

Expand All @@ -677,41 +684,51 @@ private bool TryLoadConstructorArguments(AttributeData attributeData, IDictionar

var arg = attributeData.ConstructorArguments[i];

switch (arg.Kind)
if (TryParseValueByType(arg, out object? argValue))
{
case TypedConstantKind.Error:
break;
argsDict[argumentName] = argValue;
}
else
{
// throw diagnostic error
}
}

case TypedConstantKind.Primitive:
dict[argumentName] = arg.Value;
break;
return true;
}

case TypedConstantKind.Enum:
var enumValue = arg.Type!.GetMembers()
.FirstOrDefault(m => m is IFieldSymbol field
&& field.ConstantValue is object value
&& value.Equals(arg.Value));
private bool TryParseValueByType(TypedConstant attributeArg, out object? argValue)
{
argValue = null;

if (enumValue is null)
{
return false;
}
switch (attributeArg.Kind)
{
case TypedConstantKind.Primitive:
argValue = attributeArg.Value;
break;

// we want just the enumValue symbol's name (Admin, Anonymous, Function)
dict[argumentName] = enumValue.Name;
break;
case TypedConstantKind.Enum:
var enumValue = attributeArg.Type!.GetMembers()
.FirstOrDefault(m => m is IFieldSymbol field
&& field.ConstantValue is object value
&& value.Equals(attributeArg.Value));

case TypedConstantKind.Type:
break;
if (enumValue is null)
{
return false;
}

case TypedConstantKind.Array:
var arrayValues = arg.Values.Select(a => a.Value?.ToString()).ToArray();
dict[argumentName] = arrayValues;
break;
// we want just the enumValue symbol's name (ex: Admin, Anonymous, Function)
argValue = enumValue.Name;
break;

default:
break;
}
case TypedConstantKind.Array:
var arrayValues = attributeArg.Values.Select(a => a.Value?.ToString()).ToArray();
argValue = arrayValues;
break;

default:
Comment thread
satvu marked this conversation as resolved.
Outdated
break;
}

return true;
Comment thread
satvu marked this conversation as resolved.
Outdated
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ public string QueueToBlob(
[Function("BlobToQueueFunction")]
[QueueOutput("queue2")]
public object BlobToQueue(
[BlobTrigger("container2/%file%")] string blob)
[BlobTrigger("container2/%file%", Source = BlobTriggerSource.EventGrid)] string blob)
{
throw new NotImplementedException();
}
Expand Down Expand Up @@ -206,7 +206,7 @@ public Task<ImmutableArray<IFunctionMetadata>> GetFunctionMetadataAsync(string d
metadataList.Add(Function0);
var Function1RawBindings = new List<string>();
Function1RawBindings.Add(@"{""name"":""$return"",""type"":""Queue"",""direction"":""Out"",""queueName"":""queue2""}");
Function1RawBindings.Add(@"{""name"":""blob"",""type"":""BlobTrigger"",""direction"":""In"",""properties"":{""supportsDeferredBinding"":""True""},""path"":""container2/%file%"",""dataType"":""String""}");
Function1RawBindings.Add(@"{""name"":""blob"",""type"":""BlobTrigger"",""direction"":""In"",""properties"":{""supportsDeferredBinding"":""True""},""path"":""container2/%file%"",""source"":""EventGrid"",""dataType"":""String""}");

var Function1 = new DefaultFunctionMetadata
{
Expand Down