C#拥有布尔类,通过引用传递bool

时间:2016-07-20 21:06:53

标签: c# boolean ref

是否有可能以某种方式使用此类(test.Value不是我正在寻找的):

app.UseAuthQSTokenExtractor();

这是课堂主体:

namespace Owin
{
    public static class AuthorizationQSTokenExtractorExtension
    {
        public static void UseAuthQSTokenExtractor(this IAppBuilder app)
        {
            app.Use<AuthorizationQsTokenExtractorMiddleware>();
        }
    }
}


namespace Chat.Middleware
    {
        public class AuthorizationQsTokenExtractorMiddleware : OwinMiddleware
        {

            public AuthorizationQsTokenExtractorMiddleware(OwinMiddleware next)
                : base(next)
            {

            }

            public override async Task Invoke(IOwinContext context)
            {
                Debug.WriteLine("signalr-auth-middleware");

                string bearerToken = context.Request.Query.Get("access_token");
                Debug.WriteLine("signar-bearer: " + bearerToken);
                if (bearerToken != null)
                {
                    TokenHelper.DecodeAndWrite(bearerToken);
                    string[] authorization = { "Bearer " + bearerToken };
                    context.Request.Headers.Add("Authorization", authorization);
                }

                await Next.Invoke(context);

            }
        }

1 个答案:

答案 0 :(得分:2)

是的,如果您重载truefalse运营商:

// note: you might want to think about what `null` means in terms of true/false
public static bool operator true(RefBool val) => val.Value;
public static bool operator false(RefBool val) => !val.Value;
但是,我不确定这是个好主意。 ref bool似乎更明显。