コード例 #1
0
        public T GetId()
        {
            T id = default(T);

            if (this.HttpContextAccessor.HttpContext != null)
            {
                string authorization = this.HttpContextAccessor.HttpContext.Request.Query["access_token"].Count > 0 ? this.HttpContextAccessor.HttpContext.Request.Query["access_token"] : this.HttpContextAccessor.HttpContext.Request.Headers["Authorization"];
                if (!String.IsNullOrEmpty(authorization))
                {
                    string token       = authorization.Replace("Bearer ", String.Empty, StringComparison.OrdinalIgnoreCase);
                    var    userProfile = this.TokenService.GetUserProfileByToken(token);
                    id = TypeUtility.Converte <T>(userProfile.Id);
                }
            }
            return(id);
        }
コード例 #2
0
        public void TestConvert()
        {
            Stopwatch stopwatch = new Stopwatch();

            stopwatch.Start();
            dynamic from = Guid.NewGuid();
            // Guid to Guid
            dynamic to = TypeUtility.Converte <Guid>(from);

            Assert.AreEqual(from, to);
            // Guid to String
            to = TypeUtility.Converte <string>(from);
            Assert.AreEqual(from.ToString(), to);
            // String 2 Guid
            to = TypeUtility.Converte <Guid>(from.ToString());
            Assert.AreEqual(from, to);
            // String to String
            from = "FewBox";
            to   = TypeUtility.Converte <string>(from);
            Assert.AreEqual(from, to);
            stopwatch.Stop();
            Assert.IsTrue(stopwatch.Elapsed.Milliseconds < 500, $"Time: {stopwatch.Elapsed.Milliseconds} milliseconds.");
        }