我遇到了一个适用于结构的扩展方法,(SomeStruct)并返回该值是否等于default(SomeStruct)(当调用无参数构造函数时).
public static bool IsDefault<T> (this T value)
where T : struct
{
return (!EqualityComparer<T>.Default.Equals(value, default(T)));
}
Run Code Online (Sandbox Code Playgroud)
这让我想知道结构是否被装箱.这纯粹是出于好奇,因为根据上下文有拳击/传递值的优点/缺点.
假设:
==/!=.object.Equals(object o).(object/T)所以我认为它也将避免拳击.但是,目标结构需要实现IEquatable<T>接口,使得辅助扩展方法不是很有用.变化:
public static bool IsDefault<T> (this T value)
where T : struct
{
// Illegal since there is no way to know whether T implements the ==/!= operators.
return (value == default(T));
}
public static bool IsDefault<T> (this T value)
where T : struct …Run Code Online (Sandbox Code Playgroud) This issue is partially resolved, the problem now lies in authenticating the ApiGateway request. I am unsure of how to acquire the necessary tokens to send with the request so that it is valid, because this is a [serverless-framework] service so I can't use the AWS Console to copy paste the tokens into the request's json data. Moreover, I wouldn't know what json key they'd have to be under anyways. So I guess this question has changed considerably in …
amazon-web-services node.js aws-lambda aws-api-gateway serverless-framework