diff --git a/angel_serialize_generator/lib/build_context.dart b/angel_serialize_generator/lib/build_context.dart index 76ccabf4..49f17d73 100644 --- a/angel_serialize_generator/lib/build_context.dart +++ b/angel_serialize_generator/lib/build_context.dart @@ -25,9 +25,17 @@ Future buildContext( bool autoSnakeCaseNames, bool autoIdAndDateFields, {bool heedExclude: true}) async { + // Check for autoIdAndDateFields, autoSnakeCaseNames + autoIdAndDateFields = + annotation.peek('autoIdAndDateFields')?.boolValue ?? autoIdAndDateFields; + autoSnakeCaseNames = + annotation.peek('autoSnakeCaseNames')?.boolValue ?? autoSnakeCaseNames; + var ctx = new BuildContext(annotation, originalClassName: clazz.name, - sourceFilename: p.basename(buildStep.inputId.path)); + sourceFilename: p.basename(buildStep.inputId.path), + autoIdAndDateFields: autoIdAndDateFields, + autoSnakeCaseNames: autoSnakeCaseNames); var lib = await resolver.libraryFor(buildStep.inputId); List fieldNames = []; @@ -57,10 +65,6 @@ Future buildContext( } } - // Check for autoIdAndDateFields, autoSnakeCaseNames - autoIdAndDateFields = annotation.peek('autoIdAndDateFields')?.boolValue ?? autoIdAndDateFields; - autoSnakeCaseNames = annotation.peek('autoSnakeCaseNames')?.boolValue ?? autoSnakeCaseNames; - if (autoIdAndDateFields != false) { if (!fieldNames.contains('id')) { var idField = diff --git a/angel_serialize_generator/lib/context.dart b/angel_serialize_generator/lib/context.dart index afa9f5f6..6c1aab1f 100644 --- a/angel_serialize_generator/lib/context.dart +++ b/angel_serialize_generator/lib/context.dart @@ -18,6 +18,8 @@ class BuildContext { /// A map of "synthetic" fields, i.e. `id` and `created_at` injected automatically. final Map shimmed = {}; + final bool autoIdAndDateFields, autoSnakeCaseNames; + final String originalClassName, sourceFilename; /// The fields declared on the original class. @@ -28,7 +30,11 @@ class BuildContext { /// The name of the field that identifies data of this model type. String primaryKeyName = 'id'; - BuildContext(this.annotation, {this.originalClassName, this.sourceFilename}); + BuildContext(this.annotation, + {this.originalClassName, + this.sourceFilename, + this.autoSnakeCaseNames, + this.autoIdAndDateFields}); /// The name of the generated class. String get modelClassName => originalClassName.startsWith('_')