Release 0.0.1
ln.build - build0.waldrennach.l--n.de build job pending Details

master
Harald Wolff 2020-12-06 15:04:04 +01:00
parent c99342c027
commit 1620357018
5 changed files with 28 additions and 11 deletions

View File

@ -1,7 +1,5 @@
using System.Reflection.Metadata;
using ln.http.api.attributes;
using ln.http.api.attributes;
using ln.http.router;
using ln.json.mapping;
using ln.type;
namespace ln.http.api.demo
@ -52,12 +50,18 @@ namespace ln.http.api.demo
public User[] GetUsers()
{
return new User[]{
new User(),
new User(),
new User()
new User() { Username = "User A" },
new User() { Username = "User B" },
new User() { Username = "User C" }
};
}
[GET("/header/:headername")]
public string GetHeaderValue(HttpRequest request, string headername)
{
return request.GetRequestHeader(headername);
}
}
class User

View File

@ -2,6 +2,7 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Reflection;
using ln.http.api.attributes;
using ln.http.exceptions;
@ -74,7 +75,10 @@ namespace ln.http.api
ParameterInfo parameterInfo = parameterInfos[n];
ArgumentSourceAttribute sourceAttribute = parameterInfo.GetCustomAttribute<ArgumentSourceAttribute>() ?? ArgumentSourceAttribute.Default;
if (!FindArgumentByName(sourceAttribute, request, jsonContent, parameterInfo.Name, out object value))
if (typeof(HttpRequest).Equals(parameterInfo.ParameterType))
{
arguments[n] = request;
} else if (!FindArgumentByName(sourceAttribute, request, jsonContent, parameterInfo.Name, out object value))
{
if (parameterInfo.HasDefaultValue)
{
@ -88,9 +92,11 @@ namespace ln.http.api
{
if (!JSONMapper.DefaultMapper.Deserialize(jsonValue, parameterInfo.ParameterType, out arguments[n]))
throw new BadRequestException();
} else
} else if (value is string text)
{
arguments[n] = Convert.ChangeType(value, parameterInfo.ParameterType);
arguments[n] = TypeDescriptor.GetConverter(parameterInfo.ParameterType).ConvertFromInvariantString(text);
} else {
arguments[n] = Convert.ChangeType(value, parameterInfo.ParameterType);
}
} catch (FormatException)
{

View File

@ -8,6 +8,7 @@ namespace ln.http.api.attributes
public enum ArgumentSource : int{
AUTO = -1,
CONTENT = (1<<0),
PARAMETER = (1<<1)
PARAMETER = (1<<1),
HEADER = (1<<2)
}
}

View File

@ -85,6 +85,12 @@ namespace ln.http.api.attributes
public FromContentAttribute() :base(ArgumentSource.CONTENT) {}
}
[AttributeUsage(AttributeTargets.Parameter)]
public class FromHeaderAttribute : ArgumentSourceAttribute
{
public FromHeaderAttribute() :base(ArgumentSource.HEADER) {}
}
}

View File

@ -4,7 +4,7 @@
<TargetFramework>netcoreapp3.1</TargetFramework>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<Version>0.0.1-test</Version>
<Version>0.0.1</Version>
<Authors>Harald Wolff-Thobaben</Authors>
<Company>l--n.de</Company>
<Description>Framework to create REST like APIs</Description>