Beispiel #1
0
        /// <summary>
        /// Writes CRUD interface methods definition for the specified table.
        /// </summary>
        /// <param name="table">The table to write interface for.</param>
        public void WriteTableDataProviderInterface(TableInfo table)
        {
            MethodSignature[] signatures = new MethodSignature[4];
            signatures[0] = MethodSignature.GetCreateSignature(table);
            signatures[1] = MethodSignature.GetUpdateSignature(table);
            signatures[2] = MethodSignature.GetDeleteSignature(table);
            signatures[3] = MethodSignature.GetReadSignature(table);

            foreach (var signature in signatures)
            {
                WriteLine(signature.ToString("i", null));
            }
        }
Beispiel #2
0
        /// <summary>
        /// Writes data provider methods definition for the specified table.
        /// </summary>
        /// <param name="table">The table to write methods for.</param>
        public void WriteTableDataProviderImplementation(TableInfo table)
        {
            MethodSignature signature = MethodSignature.GetCreateSignature(table);
            IMethodBuilder  builder   = new CreateMethodBuilder(table);

            WrapMethodBody(signature, builder);

            signature = MethodSignature.GetUpdateSignature(table);
            builder   = new UpdateMethodBuilder(table);
            WrapMethodBody(signature, builder);

            signature = MethodSignature.GetDeleteSignature(table);
            builder   = new DeleteMethodBuilder(table);
            WrapMethodBody(signature, builder);

            signature = MethodSignature.GetReadSignature(table);
            builder   = new ReadMethodBuilder(table);
            WrapMethodBody(signature, builder);
        }
        /// <summary>
        /// Gets the method body without definition and curly braces.
        /// </summary>
        public string GetMethodBody()
        {
            StringBuilder buffer    = new StringBuilder(512);
            var           signature = MethodSignature.GetDeleteSignature(_table);

            buffer.AppendLine("using (var connection = GetRealTimeConnection())");
            buffer.AppendLine("{");
            buffer.AppendLine("connection.Open();");

            buffer.AppendFormat("return connection.Execute(\"DELETE FROM {0} WHERE ", _table.FullName);
            buffer.Append(string.Join(" AND ",
                                      signature.Parameters.Select(p => string.Format("{0} = @{0}", p.Key))));
            buffer.Append("\", new { ");
            buffer.Append(string.Join(", ",
                                      signature.Parameters.Select(p => p.Key)));
            buffer.AppendLine(" });");

            buffer.AppendLine("}");

            return(buffer.ToString());
        }