129 references to OutLn
Microsoft.Extensions.Options.SourceGeneration (129)
Emitter.cs (126)
106OutLn($"namespace {vt.Namespace}"); 112OutLn(p); 119OutLn($"internal sealed partial {vt.DeclarationKeyword} {vt.Name}"); 123OutLn($"partial {vt.DeclarationKeyword} {vt.Name}"); 163OutLn($"namespace {classNamespace}"); 167OutLn($"{_optionsSourceGenContext.ClassModifier} static class {className}"); 214OutLn($$""" 262OutLn($$""" 309OutLn($$""" 360OutLn($$""" 515OutLn($$""" 678OutLn($"namespace {StaticGeneratedValidationAttributesClassesNamespace}"); 716OutLn($"context.MemberName = \"Validate\";"); 717OutLn($"context.DisplayName = string.IsNullOrEmpty(name) ? \"Validate\" : $\"{{name}}.Validate\";"); 718OutLn($"(builder ??= new()).AddResults(((global::System.ComponentModel.DataAnnotations.IValidatableObject)options).Validate(context));"); 729OutLn($"/// <summary>"); 730OutLn($"/// Validates a specific named options instance (or all when <paramref name=\"name\"/> is <see langword=\"null\" />)."); 731OutLn($"/// </summary>"); 732OutLn($"/// <param name=\"name\">The name of the options instance being validated.</param>"); 733OutLn($"/// <param name=\"options\">The options instance.</param>"); 734OutLn($"/// <returns>Validation result.</returns>"); 742OutLn("#if !NET"); 743OutLn($"[global::System.Diagnostics.CodeAnalysis.UnconditionalSuppressMessage(\"Trimming\", \"IL2026:RequiresUnreferencedCode\","); 744OutLn($" Justification = \"The created ValidationContext object is used in a way that never call reflection\")]"); 745OutLn("#endif"); 748OutLn($"public {(makeStatic ? "static " : string.Empty)}global::Microsoft.Extensions.Options.ValidateOptionsResult Validate(string? name, {modelToValidate.Name} options)"); 750OutLn($"global::Microsoft.Extensions.Options.ValidateOptionsResultBuilder? builder = null;"); 751OutLn("#if NET"); 752OutLn($"var context = new {StaticValidationContextType}(options, \"{modelToValidate.SimpleName}\", null, null);"); 753OutLn("#else"); 754OutLn($"var context = new {StaticValidationContextType}(options);"); 755OutLn("#endif"); 760OutLn($"var validationResults = new {StaticListType}<{StaticValidationResultType}>();"); 761OutLn($"var validationAttributes = new {StaticListType}<{StaticValidationAttributeType}>({capacity});"); 839OutLn($"/// <summary>"); 840OutLn($"/// Validates a specific named options instance asynchronously (or all when <paramref name=\"name\"/> is <see langword=\"null\" />)."); 841OutLn($"/// </summary>"); 842OutLn($"/// <param name=\"name\">The name of the options instance being validated.</param>"); 843OutLn($"/// <param name=\"options\">The options instance.</param>"); 844OutLn($"/// <param name=\"cancellationToken\">The <see cref=\"global::System.Threading.CancellationToken\"/> to monitor for cancellation requests.</param>"); 845OutLn($"/// <returns>A task representing the asynchronous validation operation, containing the validation result.</returns>"); 853OutLn("#if !NET"); 854OutLn($"[global::System.Diagnostics.CodeAnalysis.UnconditionalSuppressMessage(\"Trimming\", \"IL2026:RequiresUnreferencedCode\","); 855OutLn($" Justification = \"The created ValidationContext object is used in a way that never call reflection\")]"); 856OutLn("#endif"); 861OutLn("#pragma warning disable CS1998 // The method is declared async so cancellationToken.ThrowIfCancellationRequested() below surfaces on the returned Task rather than throwing synchronously."); 864OutLn($"public {(makeStatic ? "static " : string.Empty)}async global::System.Threading.Tasks.Task<global::Microsoft.Extensions.Options.ValidateOptionsResult> ValidateAsync(string? name, {modelToValidate.Name} options, global::System.Threading.CancellationToken cancellationToken = default)"); 866OutLn($"cancellationToken.ThrowIfCancellationRequested();"); 868OutLn($"global::Microsoft.Extensions.Options.ValidateOptionsResultBuilder? builder = null;"); 877OutLn("#if NET"); 878OutLn($"var context = new {StaticValidationContextType}(options, \"{modelToValidate.SimpleName}\", null, null);"); 879OutLn("#else"); 880OutLn($"var context = new {StaticValidationContextType}(options);"); 881OutLn("#endif"); 887OutLn($"var validationResults = new {StaticListType}<{StaticValidationResultType}>();"); 888OutLn($"var validationAttributes = new {StaticListType}<{StaticValidationAttributeType}>({capacity});"); 918OutLn("#if NET"); 919OutLn($"var context = new {StaticValidationContextType}(options, \"{modelToValidate.SimpleName}\", null, null);"); 920OutLn("#else"); 921OutLn($"var context = new {StaticValidationContextType}(options);"); 922OutLn("#endif"); 932OutLn("#pragma warning restore CS1998"); 961OutLn("#pragma warning disable CS1998 // This member's validation never awaits, but the local function is declared async to participate uniformly in Task.WhenAll below."); 964OutLn($"async global::System.Threading.Tasks.Task<global::Microsoft.Extensions.Options.ValidateOptionsResult> Validate{i}Async()"); 966OutLn($"global::Microsoft.Extensions.Options.ValidateOptionsResultBuilder? {builderVar} = null;"); 970OutLn("#if NET"); 971OutLn($"var {contextVar} = new {StaticValidationContextType}(options, \"{modelToValidate.SimpleName}\", null, null);"); 972OutLn("#else"); 973OutLn($"var {contextVar} = new {StaticValidationContextType}(options);"); 974OutLn("#endif"); 975OutLn($"var {resultsVar} = new {StaticListType}<{StaticValidationResultType}>();"); 976OutLn($"var {attributesVar} = new {StaticListType}<{StaticValidationAttributeType}>({vm.ValidationAttributes.Count});"); 996OutLn("#pragma warning restore CS1998"); 1006OutLn($"var {taskVarNames[i]} = Validate{i}Async();"); 1009OutLn($"var memberResults = await global::System.Threading.Tasks.Task.WhenAll({string.Join(", ", taskVarNames)}).ConfigureAwait(false);"); 1014OutLn($"if (memberResults[{i}].Failed)"); 1016OutLn($"(builder ??= new()).AddResult(memberResults[{i}]);"); 1023OutLn($"return {builderVariable} is null ? global::Microsoft.Extensions.Options.ValidateOptionsResult.Success : {builderVariable}.Build();"); 1035OutLn($"{contextVar}.MemberName = \"{vm.Name}\";"); 1036OutLn($"{contextVar}.DisplayName = string.IsNullOrEmpty(name) ? \"{vm.Name}\" : $\"{{name}}.{vm.Name}\";"); 1040OutLn($"{resultsVar}.Clear();"); 1041OutLn($"{attributesVar}.Clear();"); 1047OutLn($"{attributesVar}.Add({_staticValidationAttributeHolderClassFQN}.{staticValidationAttributeInstance.FieldName});"); 1052OutLn($"if (!await global::System.ComponentModel.DataAnnotations.Validator.TryValidateValueAsync(options.{EscapeIdentifier(vm.Name)}{_TryGetValueNullableAnnotation}, {contextVar}, {resultsVar}, {attributesVar}, cancellationToken).ConfigureAwait(false))"); 1056OutLn($"if (!global::System.ComponentModel.DataAnnotations.Validator.TryValidateValue(options.{EscapeIdentifier(vm.Name)}{_TryGetValueNullableAnnotation}, {contextVar}, {resultsVar}, {attributesVar}))"); 1060OutLn($"({builderVar} ??= new()).AddResults({resultsVar});"); 1095OutLn($"if ({memberAccess} is not null)"); 1097OutLn($"({builderVar} ??= new()).AddResult({resultExpression});"); 1102OutLn($"({builderVar} ??= new()).AddResult({resultExpression});"); 1130OutLn($"if ({memberAccess} is not null)"); 1135OutLn($"var count = 0;"); 1136OutLn($"foreach (var o in {memberAccess}{valueAccess})"); 1141OutLn($"if (o is not null)"); 1147OutLn($"({builderVar} ??= new()).AddResult({itemResult});"); 1152OutLn($"else"); 1155OutLn($"({builderVar} ??= new()).AddError({error});"); 1159OutLn($"count++;"); 1167OutLn($"({builderVar} ??= new()).AddResult({itemResult});"); 1178OutLn($"context.MemberName = \"ValidateAsync\";"); 1179OutLn($"context.DisplayName = string.IsNullOrEmpty(name) ? \"ValidateAsync\" : $\"{{name}}.ValidateAsync\";"); 1180OutLn($"var asyncSelfValidationResults = ((global::System.ComponentModel.DataAnnotations.IAsyncValidatableObject)options).ValidateAsync(context, cancellationToken);"); 1181OutLn($"if (asyncSelfValidationResults is not null)"); 1183OutLn($"await foreach (var asyncValidationResult in global::System.Threading.Tasks.TaskAsyncEnumerableExtensions.ConfigureAwait(asyncSelfValidationResults, false))"); 1185OutLn($"(builder ??= new()).AddResult(asyncValidationResult);"); 1192OutLn($"context.MemberName = \"Validate\";"); 1193OutLn($"context.DisplayName = string.IsNullOrEmpty(name) ? \"Validate\" : $\"{{name}}.Validate\";"); 1194OutLn($"(builder ??= new()).AddResults(((global::System.ComponentModel.DataAnnotations.IValidatableObject)options).Validate(context));"); 1201OutLn($"context.MemberName = \"{vm.Name}\";"); 1202OutLn($"context.DisplayName = string.IsNullOrEmpty(name) ? \"{vm.Name}\" : $\"{{name}}.{vm.Name}\";"); 1206OutLn($"validationResults.Clear();"); 1207OutLn($"validationAttributes.Clear();"); 1213OutLn($"validationAttributes.Add({_staticValidationAttributeHolderClassFQN}.{staticValidationAttributeInstance.FieldName});"); 1216OutLn($"if (!global::System.ComponentModel.DataAnnotations.Validator.TryValidateValue(options.{EscapeIdentifier(vm.Name)}{_TryGetValueNullableAnnotation}, context, validationResults, validationAttributes))"); 1218OutLn($"(builder ??= new()).AddResults(validationResults);"); 1303OutLn($"if ({memberAccess} is not null)"); 1305OutLn($"(builder ??= new()).AddResult({callSequence}.Validate({baseName}, {memberAccess}{valueAccess}));"); 1310OutLn($"(builder ??= new()).AddResult({callSequence}.Validate({baseName}, {memberAccess}{valueAccess}));"); 1334OutLn($"if ({memberAccess} is not null)"); 1339OutLn($"var count = 0;"); 1340OutLn($"foreach (var o in {memberAccess}{valueAccess})"); 1345OutLn($"if (o is not null)"); 1348OutLn($"(builder ??= new()).AddResult({callSequence}.Validate({propertyName}, o{enumeratedValueAccess}));"); 1353OutLn($"else"); 1356OutLn($"(builder ??= new()).AddError({error});"); 1360OutLn($"count++;"); 1365OutLn($"(builder ??= new()).AddResult({callSequence}.Validate({propertyName}, o{enumeratedValueAccess}));");
EmitterBase.cs (3)
44OutLn("{"); 51OutLn("}"); 108protected void OutGeneratedCodeAttribute() => OutLn($"[{GeneratedCodeAttribute}]");