コード例 #1
0
        public static void SetParameterFromMemberNonNullableString <T>(this GeneratedMethod method, int index,
                                                                       Expression <Func <T, string> > memberExpression)
        {
            var member = FindMembers.Determine(memberExpression).Single();

            method.Frames.Code($"parameters[{index}].Value = {{0}}.{member.Name};", Use.Type <T>());
            method.Frames.Code($"parameters[{index}].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Text;");
        }
コード例 #2
0
        public static void AssignMemberFromReaderAsync <T>(this GeneratedMethod method, GeneratedType generatedType, int index,
                                                           Expression <Func <T, object> > memberExpression)
        {
            var member       = FindMembers.Determine(memberExpression).Single();
            var variableName = member.Name.ToCamelCase();

            method.Frames.Code($"var {variableName} = await reader.GetFieldValueAsync<{member.GetMemberType().FullNameInCode()}>({index}, {{0}});", Use.Type <CancellationToken>());

            method.Frames.SetMemberValue(member, variableName, typeof(T), generatedType);
        }
コード例 #3
0
        public static void SetParameterFromMember <T>(this GeneratedMethod method, int index,
                                                      Expression <Func <T, object> > memberExpression)
        {
            var member     = FindMembers.Determine(memberExpression).Single();
            var memberType = member.GetMemberType();
            var pgType     = TypeMappings.ToDbType(memberType);

            if (memberType == typeof(string))
            {
                method.Frames.Code($"parameters[{index}].Value = {{0}}.{member.Name} != null ? (object){{0}}.{member.Name} : {typeof(DBNull).FullNameInCode()}.Value;", Use.Type <T>());
                method.Frames.Code($"parameters[{index}].NpgsqlDbType = {{0}};", pgType);
            }
            else
            {
                method.Frames.Code($"parameters[{index}].Value = {{0}}.{member.Name};", Use.Type <T>());
                method.Frames.Code($"parameters[{index}].NpgsqlDbType = {{0}};", pgType);
            }
        }