diff --git a/src/Directory.Packages.props b/src/Directory.Packages.props index 547d4b2..d664f1b 100644 --- a/src/Directory.Packages.props +++ b/src/Directory.Packages.props @@ -5,8 +5,9 @@ - + + - + \ No newline at end of file diff --git a/src/SharpScss/LibSass.Generated.cs b/src/SharpScss/LibSass.Generated.cs index ec31599..286c862 100644 --- a/src/SharpScss/LibSass.Generated.cs +++ b/src/SharpScss/LibSass.Generated.cs @@ -8,6 +8,8 @@ //------------------------------------------------------------------------------ using System; +#pragma warning disable CS8981 + namespace SharpScss { using System.Runtime.InteropServices; diff --git a/src/SharpScss/LibSass.cs b/src/SharpScss/LibSass.cs index 66912d2..787e817 100644 --- a/src/SharpScss/LibSass.cs +++ b/src/SharpScss/LibSass.cs @@ -88,7 +88,7 @@ public StringUtf8(IntPtr pointer) public bool IsEmpty => pointer == IntPtr.Zero; - public static implicit operator string(StringUtf8 stringUtf8) + public static implicit operator string?(StringUtf8 stringUtf8) { if (stringUtf8.pointer != IntPtr.Zero) { @@ -97,7 +97,7 @@ public static implicit operator string(StringUtf8 stringUtf8) return null; } - public static unsafe implicit operator StringUtf8(string text) + public static unsafe implicit operator StringUtf8(string? text) { if (text == null) { @@ -138,7 +138,7 @@ public UTF8EncodingRelaxed() : base(false, false) internal abstract class SassAllocator { [ThreadStatic] - private static List PointersToFree; + private static List? PointersToFree; public static void FreeNative() { diff --git a/src/SharpScss/Scss.cs b/src/SharpScss/Scss.cs index 80682f2..d34630b 100644 --- a/src/SharpScss/Scss.cs +++ b/src/SharpScss/Scss.cs @@ -16,8 +16,8 @@ public static class Scss { // NOTE: It is important to keep allocated delegate importer function, so that it will not be garbage collected private static readonly LibSass.Sass_Importer_Fn ScssImporterLock; - private static string version; - private static string languageVersion; + private static string? version; + private static string? languageVersion; private static readonly ScssOptions DefaultOptions = new ScssOptions(); static Scss() @@ -31,7 +31,7 @@ static Scss() /// public static string Version { - get { return version = version ?? LibSass.libsass_version(); } + get { return version ??= LibSass.libsass_version(); } } /// @@ -49,7 +49,7 @@ public static string LanguageVersion /// The options. /// The result of the conversion /// if scss is null - public static ScssResult ConvertToCss(string scss, ScssOptions options = null) + public static ScssResult ConvertToCss(string scss, ScssOptions? options = null) { if (scss == null) throw new ArgumentNullException(nameof(scss)); return FromCore(scss, false, options); @@ -62,7 +62,7 @@ public static ScssResult ConvertToCss(string scss, ScssOptions options = null) /// The options. /// The result of the conversion /// if scss is null - public static ScssResult ConvertFileToCss(string scssFile, ScssOptions options = null) + public static ScssResult ConvertFileToCss(string scssFile, ScssOptions? options = null) { if (scssFile == null) throw new ArgumentNullException(nameof(scssFile)); return FromCore(scssFile, true, options); @@ -75,7 +75,7 @@ public static ScssResult ConvertFileToCss(string scssFile, ScssOptions options = /// if set to true is a scss file; otherwise it is a scss content. /// The options. /// The result of the conversion - private static ScssResult FromCore(string fromStringOrFile, bool fromFile, ScssOptions options = null) + private static ScssResult FromCore(string fromStringOrFile, bool fromFile, ScssOptions? options = null) { var compiler = new LibSass.Sass_Compiler(); GCHandle? tryImportHandle = null; @@ -87,18 +87,15 @@ private static ScssResult FromCore(string fromStringOrFile, bool fromFile, ScssO { var fileContext = LibSass.sass_make_file_context(fromStringOrFile); context = fileContext; - if (options.InputFile == null) - { - options.InputFile = fromStringOrFile; - } - tryImportHandle = MarshalOptions(fileContext, options); + var inputFile = options.InputFile ?? fromStringOrFile; + tryImportHandle = MarshalOptions(fileContext, options, inputFile); compiler = LibSass.sass_make_file_compiler(fileContext); } else { var dataContext = LibSass.sass_make_data_context(fromStringOrFile); context = dataContext; - tryImportHandle = MarshalOptions(dataContext, options); + tryImportHandle = MarshalOptions(dataContext, options, options.InputFile); compiler = LibSass.sass_make_data_compiler(dataContext); } @@ -112,8 +109,8 @@ private static ScssResult FromCore(string fromStringOrFile, bool fromFile, ScssO var css = LibSass.sass_context_get_output_string(context); // Gets the map if it was enabled - string map = null; - if (options != null && options.GenerateSourceMap) + string? map = null; + if (options.GenerateSourceMap) { map = LibSass.sass_context_get_source_map_string(context); } @@ -154,20 +151,18 @@ private static ScssResult FromCore(string fromStringOrFile, bool fromFile, ScssO } } - private static unsafe List GetIncludedFiles(LibSass.Sass_Context context) + private static unsafe List? GetIncludedFiles(LibSass.Sass_Context context) { var filesCount = (int)LibSass.sass_context_get_included_files_size(context); var files = (LibSass.StringUtf8*)LibSass.sass_context_get_included_files(context); - List list = null; + List? list = null; for(int i = 0; i < filesCount; i++) { if (!files->IsEmpty) { - if (list == null) - { - list = new List(); - } - list.Add(*files); + list ??= new List(); + var fileAsString = (string)(*files)!; + list.Add(fileAsString); } files++; } @@ -189,7 +184,7 @@ private static void CheckStatus(LibSass.Sass_Context context) } } - private static GCHandle? MarshalOptions(LibSass.Sass_Context context, ScssOptions options) + private static GCHandle? MarshalOptions(LibSass.Sass_Context context, ScssOptions options, string? inputFile) { var nativeOptions = LibSass.sass_context_get_options(context); @@ -227,24 +222,17 @@ private static void CheckStatus(LibSass.Sass_Context context) { LibSass.sass_option_set_linefeed(nativeOptions, options.Linefeed); } - if (options.InputFile != null) + if (inputFile != null) { - var inputFile = GetRootedPath(options.InputFile); + inputFile = GetRootedPath(inputFile); LibSass.sass_option_set_input_path(nativeOptions, inputFile); } - string outputFile = null; - if (options.OutputFile != null) + string? outputFile = options.OutputFile; + if (outputFile != null) { - outputFile = GetRootedPath(options.OutputFile); + outputFile = GetRootedPath(outputFile); LibSass.sass_option_set_output_path(nativeOptions, outputFile); } - //if (options.PluginPaths.Count > 0) - //{ - // foreach (var path in options.PluginPaths) - // { - // LibSass.sass_option_push_plugin_path(nativeOptions, path); - // } - //} if (options.IncludePaths.Count > 0) { foreach (var path in options.IncludePaths) @@ -256,11 +244,6 @@ private static void CheckStatus(LibSass.Sass_Context context) if (options.GenerateSourceMap) { var sourceMapFile = GetRootedPath(options.SourceMapFile ?? (outputFile ?? "result.css") + ".map"); - if (options.SourceMapFile == null) - { - options.SourceMapFile = sourceMapFile; - } - LibSass.sass_option_set_source_map_file(nativeOptions, sourceMapFile); } if (options.SourceMapRoot != null) @@ -284,19 +267,19 @@ private static unsafe LibSass.Sass_Import_List CustomScssImporter(string current string previousPath = LibSass.sass_import_get_abs_path(previous); var cookieHandle = GCHandle.FromIntPtr(cookie); - var tryImport = (ScssOptions.TryImportDelegate)cookieHandle.Target; + var tryImport = (ScssOptions.TryImportDelegate?)cookieHandle.Target; var file = (string)currentPath; var importList = LibSass.sass_make_import_list(1); uint line = 0; uint column = 0; - string errorMessage = null; + string? errorMessage = null; if (tryImport != null) { try { string scss; - string map; + string? map; if (tryImport(ref file, previousPath, out scss, out map)) { var entry = LibSass.sass_make_import(currentPath, file, scss, map ?? ""); diff --git a/src/SharpScss/ScssOptions.cs b/src/SharpScss/ScssOptions.cs index cf86bb2..a6403c1 100644 --- a/src/SharpScss/ScssOptions.cs +++ b/src/SharpScss/ScssOptions.cs @@ -19,7 +19,7 @@ public class ScssOptions /// The output scss if import was found. /// The output map if import was found. May be null /// true if import was found; false otherwise - public delegate bool TryImportDelegate(ref string file, string parentPath, out string scss, out string map); + public delegate bool TryImportDelegate(ref string file, string parentPath, out string scss, out string? map); /// /// Initializes a new instance of the class. @@ -84,12 +84,12 @@ public ScssOptions() /// /// Gets or sets the indent string. Default is 2 spaces. /// - public string Indent { get; set; } + public string? Indent { get; set; } /// /// Gets or sets the linefeed. Default is LF (\n) /// - public string Linefeed { get; set; } + public string? Linefeed { get; set; } /// /// Gets or sets the name of the input file. See remarks for more information. @@ -98,23 +98,23 @@ public ScssOptions() /// This is recommended when so that they can properly refer back to their intended files. /// Note also that this is not used to load the data from a file. Use instead. /// - public string InputFile { get; set; } + public string? InputFile { get; set; } /// /// Gets or sets the location of the output file. This is recommended when so that they can properly refer back to their intended files. /// - public string OutputFile { get; set; } + public string? OutputFile { get; set; } /// /// Gets or sets the intended location of the source map file. Note that is used when is set. By default, if this property is not set, /// the + ".map" extension will be used. Default is null /// - public string SourceMapFile { get; set; } + public string? SourceMapFile { get; set; } /// /// Gets or sets the value that will be emitted as sourceRoot in the source map information. Default is null. /// - public string SourceMapRoot { get; set; } + public string? SourceMapRoot { get; set; } /// /// Gets the include paths that will be used to search for @import directives in scss content. @@ -124,5 +124,5 @@ public ScssOptions() /// /// Gets or sets a dynamic delegate used to resolve imports dynamically. /// - public TryImportDelegate TryImport { get; set; } + public TryImportDelegate? TryImport { get; set; } } \ No newline at end of file diff --git a/src/SharpScss/ScssResult.cs b/src/SharpScss/ScssResult.cs index fe3b079..3cddad8 100644 --- a/src/SharpScss/ScssResult.cs +++ b/src/SharpScss/ScssResult.cs @@ -17,7 +17,7 @@ public struct ScssResult /// The Css. /// The source SourceMap. /// The included files. - public ScssResult(string css, string sourceMap, List includedFiles) + public ScssResult(string css, string? sourceMap, List? includedFiles) { Css = css; SourceMap = sourceMap; @@ -32,10 +32,10 @@ public ScssResult(string css, string sourceMap, List includedFiles) /// /// Gets the source map (may be null if was false. /// - public string SourceMap { get; } + public string? SourceMap { get; } /// /// Gets the included files used to generate this result when converting the input scss content. /// - public List IncludedFiles { get; } + public List? IncludedFiles { get; } } \ No newline at end of file diff --git a/src/SharpScss/SharpScss.csproj b/src/SharpScss/SharpScss.csproj index be4a59d..2429a4a 100644 --- a/src/SharpScss/SharpScss.csproj +++ b/src/SharpScss/SharpScss.csproj @@ -2,14 +2,14 @@ Library - netstandard2.0 + netstandard2.0;net8.0 true - + enable 11.0 True - true + true @@ -55,5 +55,9 @@ + + all + runtime; build; native; contentfiles; analyzers; buildtransitive +