-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEmptyMigration.cs
More file actions
45 lines (36 loc) · 1.55 KB
/
EmptyMigration.cs
File metadata and controls
45 lines (36 loc) · 1.55 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
using System;
using System.Reflection;
using System.Reflection.Emit;
using Microsoft.EntityFrameworkCore.Migrations;
namespace DataContextContainer
{
[Migration("Empty1")]
public class EmptyMigration : Migration
{
private static readonly Type type = typeof(EmptyMigration);
private static readonly AssemblyName assemblyName = new AssemblyName("EmptyMigrationsAssembly");
private static readonly AssemblyBuilder builder = AssemblyBuilder.DefineDynamicAssembly(assemblyName, AssemblyBuilderAccess.Run);
private static readonly ModuleBuilder moduleBuilder = builder.DefineDynamicModule(assemblyName.Name);
static EmptyMigration()
{
Instance = new EmptyMigration();
}
public static EmptyMigration Instance { get; }
protected override void Up(MigrationBuilder migrationBuilder)
{
}
public static EmptyMigration GetNewInstance()
{
var guid = Guid.NewGuid();
var tb = moduleBuilder.DefineType(type.Name + "Proxy_" + guid, TypeAttributes.Public, type);
var attrCtorParams = new Type[] { typeof(string) };
var attrCtorInfo = typeof(MigrationAttribute).GetConstructor(attrCtorParams);
var attrBuilder = new CustomAttributeBuilder(attrCtorInfo, new object[] { "Empty1" + guid });
tb.SetCustomAttribute(attrBuilder);
var newType = tb.CreateType();
var instance = (EmptyMigration)Activator.CreateInstance(newType);
return instance;
}
}
}