Ejemplo n.º 1
0
        public static string GenerateAttributeCode(ImplicitNullabilityConfiguration configuration)
        {
            AssemblyMetadataAttributeValues GenerateAttributeValues()
            {
                if (configuration.AppliesTo == ImplicitNullabilityAppliesTo.None)
                {
                    return(new AssemblyMetadataAttributeValues(configuration.AppliesTo.ToString()));
                }

                var appliesToText = configuration.AppliesTo.ToString();

                var fieldsText =
                    configuration.HasAppliesTo(ImplicitNullabilityAppliesTo.Fields) &&
                    configuration.FieldOptions != ImplicitNullabilityFieldOptions.NoOption
                        ? configuration.FieldOptions.ToString()
                        : null;

                var propertiesText =
                    configuration.HasAppliesTo(ImplicitNullabilityAppliesTo.Properties) &&
                    configuration.PropertyOptions != ImplicitNullabilityPropertyOptions.NoOption
                        ? configuration.PropertyOptions.ToString()
                        : null;

                var generatedCodeText = configuration.GeneratedCode.ToString();

                return(new AssemblyMetadataAttributeValues(appliesToText, fieldsText, propertiesText, generatedCodeText));
            }

            return(GenerateAttributeValues().GenerateAttributeCode());
        }
        private ImplicitNullabilityConfiguration CalculateConfiguration(IPsiModule psiModule)
        {
            var implicitNullabilitySettings = GetSettings(psiModule);

            if (!implicitNullabilitySettings.Enabled)
            {
                return(ImplicitNullabilityConfiguration.AllDisabled);
            }

            var configurationFromAssemblyAttribute = ParseConfigurationFromAssemblyAttribute(psiModule);

            if (configurationFromAssemblyAttribute.HasValue)
            {
                return(configurationFromAssemblyAttribute.Value);
            }

            if (!psiModule.IsPartOfSolutionCode())
            {
                return(ImplicitNullabilityConfiguration.AllDisabled);
            }

            return(ImplicitNullabilityConfiguration.CreateFromSettings(implicitNullabilitySettings));
        }