in src/Microsoft.NET.Sdk.Functions.Generator/AttributeExtensions.cs [72:128]
public static JObject ToJObject(this Attribute attribute)
{
var obj = new JObject
{
// the friendly name is basically the name without 'Attribute' suffix and lowerCase first Char.
["type"] = attribute.ToAttributeFriendlyName()
};
// Default value is out
foreach (var property in attribute
.GetType()
.GetProperties(BindingFlags.Public | BindingFlags.Instance)
.Where(p => p.CanRead && p.PropertyType != typeof(System.Object)))
{
var propertyValue = property.GetValue(attribute);
if (propertyValue == null || (propertyValue is int && (int)propertyValue == 0))
{
// Don't serialize null properties and int properties for some reason.
// the int handling logic was copied from Mike's > "Table.Take is not nullable. So 0 means ignore"
continue;
}
var propertyType = property.PropertyType;
#if NET46
if (propertyType.IsGenericType && propertyType.GetGenericTypeDefinition() == typeof(Nullable<>))
#else
if (propertyType.GetTypeInfo().IsGenericType && propertyType.GetGenericTypeDefinition() == typeof(Nullable<>))
#endif
{
// Unwrap nullable types to their underlying type.
propertyType = Nullable.GetUnderlyingType(propertyType);
}
// Check if property is supported.
CheckIfPropertyIsSupported(attribute.GetType().Name, property);
// Normalize and store the propertyName
var propertyName = NormalizePropertyName(attribute, property);
if (TryGetPropertyValue(property, propertyValue, out string jsonValue))
{
obj[propertyName] = jsonValue;
}
else
{
obj[propertyName] = JToken.FromObject(propertyValue);
}
}
// Clear AuthLevel from httpTrigger that has a webHook property
if (obj["type"]?.ToString() == "httpTrigger" && obj["webHookType"]?.ToString() != null)
{
obj.Remove("authLevel");
}
return obj;
}