src/Shared/EntityFramework/Migrations/Design/CSharpMigrationCodeGenerator.cs
/// <summary>
/// Generates the code behind file with migration metadata.
/// </summary>
/// <param name="migrationId"> Unique identifier of the migration. </param>
/// <param name="sourceModel"> Source model to be stored in the migration metadata. </param>
/// <param name="targetModel"> Target model to be stored in the migration metadata. </param>
/// <param name="namespace"> Namespace that code should be generated in. </param>
/// <param name="className"> Name of the class that should be generated. </param>
/// <returns> The generated code. </returns>
Generates the code behind file with migration metadata.
Generates the code behind file with migration metadata .
[SuppressMessage("Microsoft.Naming", "CA1716:IdentifiersShouldNotMatchKeywords", MessageId = "namespace")]
        [SuppressMessage("Microsoft.Usage", "CA2202:Do not dispose objects multiple times")]
        protected virtual string Generate(
            string migrationId, string sourceModel, string targetModel, string @namespace, string className)
        {
            Check.NotEmpty(migrationId, "migrationId");
            Check.NotEmpty(targetModel, "targetModel");
            Check.NotEmpty(className, "className");
            using (var stringWriter = new StringWriter(CultureInfo.InvariantCulture))
            {
                using (var writer = new IndentedTextWriter(stringWriter))
                {
                    writer.WriteLine("// <auto-generated />");
                    WriteClassStart(@namespace, className, writer, "IMigrationMetadata", designer: true);
                    writer.Write("private readonly ResourceManager Resources = new ResourceManager(typeof(");
                    writer.Write(className);
                    writer.WriteLine("));");
                    writer.WriteLine();
                    WriteProperty("Id", Quote(migrationId), writer);
                    writer.WriteLine();
                    WriteProperty(
                        "Source",
                        sourceModel == null
                            ? null
                            : "Resources.GetString(\"Source\")",
                        writer);
                    writer.WriteLine();
                    WriteProperty("Target", "Resources.GetString(\"Target\")", writer);
                    WriteClassEnd(@namespace, writer);
                }
                return stringWriter.ToString();
            }
        }
[ SuppressMessage ( " " , " " , MessageId = " " ) ] [ SuppressMessage ( " " , " " ) ] protected virtual string Generate ( string migrationId , string sourceModel , string targetModel , string @namespace , string className ) { Check . NotEmpty ( migrationId , " " ) ; Check . NotEmpty ( targetModel , " " ) ; Check . NotEmpty ( className , " " ) ; using ( var stringWriter = new StringWriter ( CultureInfo . InvariantCulture ) ) { using ( var writer = new IndentedTextWriter ( stringWriter ) ) { writer . WriteLine ( " " ) ; WriteClassStart ( @namespace , className , writer , " " , designer : true ) ; writer . Write ( " " ) ; writer . Write ( className ) ; writer . WriteLine ( " " ) ; writer . WriteLine ( ) ; WriteProperty ( " " , Quote ( migrationId ) , writer ) ; writer . WriteLine ( ) ; WriteProperty ( " " , sourceModel == null ? null : " \" \" " , writer ) ; writer . WriteLine ( ) ; WriteProperty ( " " , " \" \" " , writer ) ; WriteClassEnd ( @namespace , writer ) ; } return stringWriter . ToString ( ) ; } }
Generates the code behind file with migration metadata.
Generates the code behind file with migration metadata .
The generated code.
The generated code .
migrationId
string
Unique identifier of the migration.
Unique identifier of the migration .
sourceModel
string
Source model to be stored in the migration metadata.
Source model to be stored in the migration metadata .
targetModel
string
Target model to be stored in the migration metadata.
Target model to be stored in the migration metadata .
@namespace
string
className
string
Name of the class that should be generated.
Name of the class that should be generated .
namespace
Namespace that code should be generated in.
Namespace that code should be generated in .