当前位置: 首页>>代码示例>>C#>>正文


C# IUser.GetType方法代码示例

本文整理汇总了C#中IUser.GetType方法的典型用法代码示例。如果您正苦于以下问题:C# IUser.GetType方法的具体用法?C# IUser.GetType怎么用?C# IUser.GetType使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在IUser的用法示例。


在下文中一共展示了IUser.GetType方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: NewFromOtherUser

        /// <summary>
        /// The new from other user.
        /// </summary>
        /// <param name="source">
        /// The source.
        /// </param>
        /// <returns>
        /// The <see cref="LegacyUser"/>.
        /// </returns>
        public static LegacyUser NewFromOtherUser(IUser source)
        {
            if (source.GetType() == typeof(LegacyUser))
            {
                return (LegacyUser)source;
            }

            if (source.GetType().GetInterfaces().Contains(typeof(ILegacyUser)))
            {
                return (LegacyUser)source;
            }

            return NewFromString(string.Format("{0}!{1}@{2}", source.Nickname, source.Username, source.Hostname));
        }
开发者ID:tom29739,项目名称:helpmebot,代码行数:23,代码来源:LegacyUser.cs

示例2: WriteJson

        public static void WriteJson(IUser user, TextWriter output, string usermode = "", bool pretty = false, int level = 0) {
            if (string.IsNullOrWhiteSpace(usermode)) {
                usermode = "admin";
            }
            var notnullonly = usermode != "store";
            var jw = new JsonWriter(output,pretty:pretty,level:level);
            if (null == user) {
                jw.WriteValue(null);
                return;
            }
            jw.OpenObject();
            
            jw.WriteProperty("__id", user.Id, notnullonly);
            jw.WriteProperty("__version", user.Version, notnullonly);
            jw.WriteProperty("createtime", user.CreateTime.ToUniversalTime(), notnullonly);
            jw.WriteProperty("updatetime", user.UpdateTime.ToUniversalTime(), notnullonly);

            if (usermode == "admin" || usermode == "store") {
                jw.WriteProperty("class", "user");
                jw.WriteProperty("__type", "user");
                var type = user.GetType();
                jw.WriteProperty("netclass", type.FullName + ", " + type.Assembly.GetName().Name);
            }


            jw.WriteProperty("login", user.Login, notnullonly);
            jw.WriteProperty("name", user.Name, notnullonly);
            jw.WriteProperty("email", user.Email, notnullonly);
            jw.WriteProperty("admin", user.IsAdmin, notnullonly);
            jw.WriteProperty("isgroup", user.IsGroup, notnullonly);
            jw.WriteProperty("active", user.Active, notnullonly);
            jw.WriteProperty("expire", user.Expire.ToUniversalTime(), notnullonly);
            jw.WriteProperty("publickey", user.PublicKey, notnullonly);

            if (usermode == "store" || usermode == "admin") {
                
                jw.WriteProperty("hash", user.Hash, notnullonly);
                jw.WriteProperty("salt", user.Salt, notnullonly);
                jw.WriteProperty("resetkey", user.ResetKey, notnullonly);
                jw.WriteProperty("resetexpire", user.ResetExpire.ToUniversalTime(), notnullonly);
                
                jw.WriteProperty("logable", user.Logable, notnullonly);
            }
            jw.WriteProperty("domain", user.Domain, notnullonly);
            jw.WriteProperty("roles", user.Roles.OrderBy(_ => _).ToArray(), notnullonly);
            jw.WriteProperty("groups", user.Groups.OrderBy(_ => _).ToArray(), notnullonly);
            jw.WriteProperty("custom", user.Custom, notnullonly);

            var extensions = user as IJsonSerializationExtension;
            if (null != extensions) {
                extensions.WriteExtensions(jw, usermode, null);
            }

            jw.CloseObject();
        }
开发者ID:Qorpent,项目名称:qorpent.sys,代码行数:55,代码来源:UserSerializer.cs


注:本文中的IUser.GetType方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。