public static void AddProperties(OutputModel outputModel, ClassModel classModel, DocumentPlan documentPlan) { outputModel.CancellationToken.ThrowIfCancellationRequested(); if (!outputModel.CanGenerate) { return; } foreach (var propertyModel in classModel.Properties) { var symbol = propertyModel.PropertySymbol; if (outputModel.CanIncludeProperty(symbol)) { var propertyPlan = new PropertyPlan { PropertyName = symbol.Name, ArgumentName = symbol.Name.ToArgumentName(), FullTypeName = symbol.Type.ToDisplayString(), UseDefault = propertyModel.UseDefaultAttribute is not null, IsInitOnly = propertyModel.IsInitOnly, PropertyModel = propertyModel }; outputModel.ValidateIdentifiers( symbol, propertyPlan.PropertyName, propertyPlan.ArgumentName); documentPlan.PropertiesByName[propertyPlan.PropertyName] = propertyPlan; if (documentPlan.PropertiesByArgumentName.ContainsKey(propertyPlan.ArgumentName)) { outputModel.Report(Diagnostics.Errors.PropertyArgumentCollision, symbol, propertyPlan.ArgumentName); } else { documentPlan.PropertiesByArgumentName[propertyPlan.ArgumentName] = propertyPlan; if (!propertyPlan.IsInitOnly && !documentPlan.IsMutable && SymbolEqualityComparer.Default.Equals(propertyPlan.PropertyModel.PropertySymbol.ContainingType, classModel.ClassSymbol)) { outputModel.Report(Diagnostics.Warnings.InitOnlyNotMutable, symbol, propertyPlan.PropertyName); } } } } } }
static void Validate(OutputModel outputModel, ClassModel classModel, PropertyModel model) { var symbol = model.PropertySymbol; if (model.UseDefaultAttribute is not null) { if (symbol.IsStatic) { outputModel.Report(Diagnostics.Errors.UseDefaultStatic, symbol); } if (!classModel.IsDbDoc) { outputModel.Report(Diagnostics.Errors.UseDefaultDbDoc, symbol); } if (!outputModel.CanIncludeProperty(symbol)) { outputModel.Report(Diagnostics.Warnings.UseDefaultIgnored, symbol); } if (symbol.Type.IsReferenceType && symbol.Type.NullableAnnotation != NullableAnnotation.Annotated) { outputModel.Report(Diagnostics.Errors.UseDefaultNullable, symbol); } } }