internal void SetUp(string className, MigrationContext context) { CodeNamespace ns = new CodeNamespace("__MigrationPlan__"); foreach (ScriptImport si in _imports) { ns.Imports.Add(new CodeNamespaceImport(si.Namespace)); } ns.Types.Add(GetTypeDeclaration(className)); CodeCompileUnit unit = new CodeCompileUnit(); unit.Namespaces.Add(ns); CompilerResults results = Compile(context, unit); if (0 == results.Errors.Count) { context.Trace("script compiled successfully."); Assembly assembly = results.CompiledAssembly; Type type = assembly.GetType(string.Format("__MigrationPlan__.{0}", className), true); Activator.CreateInstance(type, new object[] { context }); } else { context.Trace("{0} script compilation error(s)!", results.Errors.Count); foreach (CompilerError error in results.Errors) { context.Trace(error.ToString()); } throw new ApplicationException(results.Errors[0].ToString()); } }
public override System.Type BindToType(string assemblyName, string typeName) { _context.Trace("\nBindToType(\"{0}\", \"{1}\")", assemblyName, typeName); string actualAssemblyName = assemblyName; string actualTypeName = typeName; TypeMapping mapping = _context.MigrationPlan.TypeMappings[typeName]; if (null != mapping) { if (string.Empty == mapping.AssemblyName) { _context.Trace("{0} bound to {1}, {2}", typeName, mapping.TypeName, _context.TargetAssembly.FullName); return(_context.TargetAssembly.GetType(mapping.TypeName)); } else { actualAssemblyName = mapping.AssemblyName; actualTypeName = mapping.TypeName; } } string boundTypeName = actualTypeName + ", " + actualAssemblyName; _context.Trace("{0} bound to {1}", typeName, boundTypeName); return(Type.GetType(boundTypeName)); }
public void InitializeField(MigrationContext context) { FieldInfo field = context.CurrentField; SerializationInfo info = context.CurrentSerializationInfo; object value = info.GetValue(_fieldName, field.FieldType); field.SetValue(context.CurrentObject, context.ChangeType(value, field.FieldType)); context.Trace("Field {0} set to \"{1}\" loaded from field {2}.", field.Name, value, _fieldName); }
public void InitializeField(MigrationContext context) { FieldInfo field = context.CurrentField; SerializationInfo info = context.CurrentSerializationInfo; try { field.SetValue(context.CurrentObject, info.GetValue(field.Name, field.FieldType)); } catch (InvalidCastException) { object value = info.GetValue(field.Name, typeof(object)); context.Trace("Failed to deserialize field {0} of type {1} from value {2} of type {3}!", field.Name, field.FieldType, value, null != value ? value.GetType().ToString() : "null"); throw; } }