KnownUserGoogleInfo DoCreateUserUnfo(string googleAccountId, SqlDataReader r) { var info = _infoFactory.Create(); info.GoogleAccountId = googleAccountId; FillUserGoogleInfo(info, r, 1); KnownUserGoogleInfo result = new KnownUserGoogleInfo() { UserId = r.GetInt32(0), Info = info }; return(result); }
/// <summary> /// Creates and configures a <see cref="IPoco"/> instance. /// </summary> /// <typeparam name="T">Type of the poco.</typeparam> /// <param name="this">This poco factory.</param> /// <param name="configure">Configuration action.</param> /// <returns>The configured instance.</returns> public static T Create <T>(this IPocoFactory <T> @this, Action <T> configure) where T : IPoco { T p = @this.Create(); configure(p); return(p); }
/// <summary> /// Populates a new instance of <typeparamref name="T"/> with the provided KeyValuePair<string, object>. /// </summary> /// <typeparam name="T">The POCO type.</typeparam> /// <param name="this">This POCO factory.</param> /// <param name="payload">The payload. Must not be null.</param> /// <returns>The resulting POCO.</returns> public static T ExtractPayload <T>( this IPocoFactory <T> @this, IEnumerable <KeyValuePair <string, object> > payload) where T : IPoco { if (payload == null) { throw new ArgumentNullException(nameof(payload)); } T info = @this.Create(); var properties = @this.PocoClassType.GetProperties(BindingFlags.Public | BindingFlags.Instance); foreach (var kv in payload) { var property = properties.FirstOrDefault(p => StringComparer.OrdinalIgnoreCase.Equals(kv.Key, p.Name)); if (property != null) { try { var targetType = property.PropertyType; var pType = targetType.GetTypeInfo(); if (pType.IsGenericType && (pType.GetGenericTypeDefinition() == typeof(Nullable <>))) { if (kv.Value == null) { property.SetValue(info, null); continue; } targetType = Nullable.GetUnderlyingType(targetType); pType = targetType.GetTypeInfo(); } object value; string stringValue; if (pType.IsEnum && (stringValue = kv.Value as string) != null) { value = Enum.Parse(targetType, stringValue); } else { value = Convert.ChangeType(kv.Value, targetType); } property.SetValue(info, value); } catch (Exception ex) { throw new ArgumentException($"Invalid payload. Unable to set '{property.Name}'. See inner exceptions for details.", nameof(payload), ex); } } } return(info); }
IUserOidcInfo IGenericAuthenticationProvider <IUserOidcInfo> .CreatePayload() => _infoFactory.Create();
/// <summary> /// Creates a new <see cref="IUserSimpleInvitationInfo"/> poco. /// </summary> /// <returns>A new poco instance.</returns> public IUserSimpleInvitationInfo CreateInfo() => _infoFactory.Create();
/// <summary> /// Creates a new <see cref="ITokenInfo"/> poco. /// </summary> /// <returns>A poco instance.</returns> public ITokenInfo CreateInfo() => _tokenFactory.Create();
IGuestActorInfo IGenericAuthenticationProvider <IGuestActorInfo> .CreatePayload() => _infoFactory.Create();