Beispiel #1
0
        public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value)
        {
            if (!(value is string arg))
            {
                return(base.ConvertFrom(context, culture, value));
            }

            IUserManager userManager = context.GetRequiredService <IUserManager>();

            string userActorType;
            string userNameOrId;

            if (arg.Contains(Separator))
            {
                string[] args = arg.Split(Separator);
                userActorType = args[0];
                userNameOrId  = string.Join(Separator.ToString(), args.Skip(1).ToArray());
            }
            else
            {
                userActorType = DefaultActorType;
                userNameOrId  = arg;
            }

            return(AsyncHelper.RunSync(async()
                                       => await userManager.FindUserAsync(userActorType, userNameOrId, UserSearchMode.FindByNameOrId)));
        }