private static void UpdateFromContext(EntityContext generatedContext, string contextDirectory) { if (generatedContext == null || contextDirectory == null || !Directory.Exists(contextDirectory)) { return; } // parse context ParsedContext parsedContext = null; var files = Directory.EnumerateFiles(contextDirectory, "*.Generated.cs").GetEnumerator(); while (files.MoveNext() && parsedContext == null) { parsedContext = ContextParser.Parse(files.Current); } if (parsedContext == null) { return; } if (generatedContext.ClassName != parsedContext.ContextClass) { Debug.WriteLine("Rename Context Class'{0}' to '{1}'.", generatedContext.ClassName, parsedContext.ContextClass); generatedContext.ClassName = parsedContext.ContextClass; } foreach (var parsedProperty in parsedContext.Properties) { var entity = generatedContext.Entities.ByClass(parsedProperty.EntityClass); if (entity == null) { continue; } if (entity.ContextName == parsedProperty.ContextProperty) { continue; } Debug.WriteLine("Rename Context Property'{0}' to '{1}'.", entity.ContextName, parsedProperty.ContextProperty); entity.ContextName = parsedProperty.ContextProperty; } }
public override object VisitTypeDeclaration(TypeDeclaration typeDeclaration, object data) { var baseType = typeDeclaration.BaseTypes .OfType <MemberType>() .FirstOrDefault(); // warning: if inherited from custom base type, this will break // anyway to improve this? if (baseType == null || baseType.MemberName != ContextBaseType) { return(base.VisitTypeDeclaration(typeDeclaration, data)); } if (ParsedContext == null) { ParsedContext = new ParsedContext(); } ParsedContext.ContextClass = typeDeclaration.Name; return(base.VisitTypeDeclaration(typeDeclaration, ParsedContext)); }