Skip to content

Conversation

@Yevrag35
Copy link
Owner

This pull request updates the ListFunctions module and its .NET projects to version 3.1.0, with a focus on modernizing dependencies, improving compatibility, and fixing a bug in the Find-IndexOf cmdlet. The changes include updating PowerShell and .NET target versions, adding new conversion functionality, and ensuring proper assembly binding for newer .NET libraries.

Module and Cmdlet Updates

  • Bumped the module and assembly versions to 3.1.0 and updated copyright years to 2025 in both PowerShell and .NET metadata files. [1] [2] [3]

Bug Fixes and Release Notes

  • Updated release notes to document the fix for Find-IndexOf returning incorrect results in certain situations.

Yevrag35 and others added 30 commits August 31, 2025 12:20
- Updated target framework in `LFPublish.csproj` and `ListFunctions-Next.csproj` to `net9.0`.
- Upgraded `System.Management.Automation` package from `7.4.0` to `7.5.2` in both projects.
- Changed `ImplicitUsings` from `disable` to `enable` in `ListFunctions-Next.csproj`.
- Added `AllowUnsafeBlocks` property to `ListFunctions.Engine.csproj`.
- Introduced new `PackageReference` for `System.Management.Automation` specific to `net9.0` in `ListFunctions.Engine.csproj`.
- Updated `LangVersion` for `ListFunctions.Engine.csproj` to `latest` for `net6.0` and `net8.0`, and set to `preview` for `net9.0`.
- Improved null handling and type safety in `HashCodeBlock.cs`.
- Modified `PSThisVariable` to use `HashSet<string>` instead of `IReadOnlySet<string>` for better performance.
- Cleaned up using directives across various files to enhance code readability and maintainability.
Updated `ListFunctions-NETFramework.csproj` to remove `MG.Collections` and add references for `Microsoft.Bcl.Memory`, `System.Buffers`, `System.Memory`, `System.Numerics.Vectors`, `System.Runtime.CompilerServices.Unsafe`, `System.ValueTuple`, and `ZLinq`. Added `app.config` and `packages.config` with necessary binding redirects and package dependencies.

Introduced `ReadOnlySet.cs` to define the `IReadOnlySet` interface and its implementation, providing a read-only collection that supports set operations. Added `SingleValueReadOnlySet.cs` for creating read-only sets containing a single value.

Significant changes in `Empty.cs` include the removal of generic parameters and the introduction of `EmptyHolder`, along with modifications to use `Array.Empty` for improved functionality.

Updated `EnumerableExtensions.cs` to replace the original `TryGetCount` method with a new implementation using pattern matching for better handling of collection types.

Enhanced `ScriptBlockFilter.cs` to improve instance creation and utilize the new `SingleValueReadOnlySet` and `ReadOnlySet` for managing collections of `PSVariable`.
- Introduced a new `using` directive for `System.Runtime.InteropServices`.
- Added a `StructLayout` attribute to `SingleValueReadOnlySet<T>` for sequential memory layout.
- Removed the `_isNotEmpty` field; modified `IsEmpty` to check if `_value` is null.
- Updated the `Contains` method to return false if the set is empty or the item is null.
- Modified `IsProperSubsetOf`, `IsSubsetOf`, `IsSupersetOf`, and `SetEquals` methods to use `AsValueEnumerable()` for improved performance.
- Changed `GetEnumerator` to return a custom `Enumerator` struct instead of yielding the value directly.
- Defined a new `Enumerator` struct implementing `IEnumerator<T>` for iterating over the single value in the set.
- Improved null handling and type safety in various methods.
- Updated collection checks in `PSVariableCollectionExtensions.cs` for explicit `PSObject` type handling.
- Simplified statement count check in `ScriptBlockExtensions.cs`.
- Modified `Compare` method in `ComparingBlock.cs` to accept nullable types.
- Changed string comparison logic in `DictionaryCtor.cs` to use `StringComparer.CurrentCulture`.
- Added nullability annotations in several methods in `EqualityBlock.cs`.
- Implemented error handling for method resolution failures in `EqualityBlock.cs`.
- Added similar error handling for method retrieval in `ReflectionResolver.cs`.
- Updated iteration in `ScriptBlockFilter.cs` to use `AsValueEnumerable()` for improved performance.
- Changed `EnumerateVariables` in `AssertAllObjectsCmdlet.cs` to return a `PSVariable[]` for better performance.
- Updated `_condition` in `AssertAnyObjectCmdlet.cs` to be non-nullable and added nullability attributes to `InputObject`.
- Modified `ProcessWhenNoCondition` to handle nullable arrays and ensure only non-null objects are processed.
- Removed a parameter from the `$CopyToOutput` array in `Debug.ps1`.
- Disabled implicit usings and nullable reference types in `ListFunctions-Next.csproj`.
- Replaced `using System;` with `using ListFunctions.Extensions;` in `ValidateScriptVariableAttribute.cs` and enhanced `EnumerateAllVariablesInBlock` return type.
- Added `SetExtensions` class in `SetExtensions.cs` with `UnionWithRef` method for improved performance.
- Updated serialization constructor in `HashCodeScriptException.cs` for .NET 8 compatibility.
- Improved `ToDictionary` method in `ScriptBlockInvocationException.cs` for clarity and performance.
- Changed iteration in `ScriptBlockFilter.cs` to use `AsValueEnumerable()` for better performance.
- Removed `ZLinq` library reference from `ListFunctions-NETFramework.csproj` and its entry in `packages.config`.
- Eliminated `using ZLinq.Linq;` from `ValidateScriptVariableAttribute.cs` and modified `EnumerateAllVariablesInBlock` to conditionally use `ZLinq` types.
- Added new file `EnumerableExtensions.cs` with an `AsValueEnumerable` extension method for `IEnumerable<T>`.
- Updated `PSVariableCollectionExtensions.cs` to access the last element of a collection using `collection.Count - 1`.
- Included a conditional `using ZLinq.Linq;` directive in `SetExtensions.cs` based on the target framework.
- Moved `ZLinq` package reference to a conditional item group in `ListFunctions.Engine.csproj`.
- Enhanced methods in `Guard.cs` with `MethodImpl` attributes for aggressive inlining and conditional exception throwing based on the target framework.
- Changed string comparison in `ArgumentToTypeNameTransformAttribute.cs` from `InvariantCultureIgnoreCase` to `OrdinalIgnoreCase` for module name checks, affecting cultural behavior.
- Removed `ListFunctions.Extensions` import in `ValidateScriptVariableAttribute.cs` and consolidated `System` imports to include additional namespaces: `System.Collections.Generic`, `System.Linq`, `System.Management.Automation`, `System.Management.Automation.Language`, and `ZLinq`.
- Updated project files to allow unsafe code blocks.
- Introduced `_genericType` in `NewListCmdlet.cs` for better generic type management.
- Changed `InputObject` from an array to `IList?` for flexible input handling.
- Modified `BeginProcessing` to initialize lists based on generic type and capacity.
- Added methods to set object type and handle null elements.
- Updated `ProcessRecord` to use `Count` for null/empty list checks.
- Refactored item addition logic into `AddItemsToList` and `AddTypedItemsToList`.
- Added `AsValueEnumerable` method in `EnumerableExtensions.cs` for casting `IEnumerable` to `IEnumerable<object>`.
- Changed `InputObject` type from `IList?` to `object?[]?` for improved flexibility.
- Updated `ProcessRecord` method to check `InputObject.Length` instead of `Count`.
- Modified `AddItemsToList` to accept `object?[]` parameter for item addition.
- Updated `AddTypedItemsToList` to use the new `object?[]` parameter for type conversion.
- Added `#nullable enable` directive in `ArgumentToTypeNameTransformAttribute.cs` for enhanced type safety.
- Changed namespace in `SetExtensions.cs` from `ListFunctions.Extensions` to `ZLinq`.
Enhanced `ConvertToDictionaryCmdlet.cs` with new properties
for key and value selectors, improved error handling, and a
method to determine input object types, supporting both
property-based and script-based extraction.

Updated `NewDictionaryCmdlet.cs` to include nullable
reference types for `KeyType` and `ValueType`, allowing
better handling of undefined types. The `Capacity` property
now includes an alias for "Size" to improve usability.
- Made `ValueSelector` nullable for better optional handling.
- Introduced `ScriptBlockExtensions.cs` with `ReplaceWithArgsZero()` method to enhance script block flexibility.
- Updated `_dictionary` instantiation to use an array for constructor parameters.
- Modified `ValueSelector` invocation to use null-conditional operator for safer code.
- Changed implicit conversion in `DoubleBool` from logical AND (`&&`) to bitwise AND (`&`).
- Improved error handling in `SortingCollectorCtor` with null check on generic method invocation.
- Added `#nullable enable` directive to several files to support nullable reference types.
- Changed `ValuePropertyName` from `string` to `object?` for increased flexibility.
- Updated logic to check if `ValuePropertyName` is a string before string operations.
- Modified handling of `ValueSelector` to accommodate the new `ValuePropertyName` type.
- Refactored `ReplaceWithArgsZero` in `ScriptBlockExtensions.cs` to use a new `ReplaceString` method for improved string replacement logic.
- Simplified string replacement logic and ensured compatibility across different frameworks.
- Introduced nullable reference types in `AssertAnyObjectCmdlet.cs` for properties.
- Enhanced XML documentation in `ArgumentToTypeNameTransformAttribute.cs` and `ListTransformAttribute.cs`.
- Clarified validation logic and variable handling in `ValidateScriptVariableAttribute.cs`.
- Improved structure and added enumerators in `PipelineItem.cs`.
- Updated exception handling in `Guard.cs` for better efficiency based on .NET version.
- Introduced a new `ListPool` class for efficient list management with methods for renting and returning lists.
- Updated `FindIndexCmdletBase.cs` to use nullable reference types, changing `IList InputObject` to `object?[]? InputObject`.
- Simplified `ComparingBase` and derived classes by removing generic type parameters.
- Enhanced `ScriptBlockFilter` to handle collections more generically, improving type safety.
- Refactored variable handling in `PSComparingVariable` and `PSThisVariable` for better performance using `MemoryMarshal` and `Unsafe`.
- Removed conditional compilation directives for .NET version checks, streamlining the codebase.
- Added nullable reference types with `#nullable enable`.
- Updated `InputObject` to use an array of objects.
- Commented out several methods related to index finding.
- Introduced a generic `ListPool` class for efficient list management.
- Added `IPoolable` and `IResettable` interfaces for object pooling.
- Updated `PSThisVariable` to implement `IResettable`.
- Overall improvements for type safety, performance, and list handling in cmdlets.
- Updated `InputObject` in `FindIndexCmdletBase.cs` to support nullable arrays and explicitly rent lists as `ListPool<object?>`.
- Added a new virtual method `Stop(List<object?> list)` in `FindIndexCmdletBase.cs` for future implementation.
- Modified `ListPool<T>` in `ListPool.cs` to allow nullable reference types.
- Enhanced `ObjPool` in `ObjPool.cs` with generic constraints and methods for renting and returning items.
- Implemented `IPoolable` interface in `PSComparingVariable` and added lifecycle management methods.
Updated project version to 3.0.0 across multiple files.
Removed several external library references in favor of modern alternatives.
Added new source file inclusion from `ListFunctions-Next`.
Updated `AssemblyInfo.cs` and `packages.config` for compatibility.
Introduced nullable reference types in `AssertAllObjectsCmdlet.cs`.
Refactored `AssertAnyObjectCmdlet.cs` to improve class hierarchy.
Significant redesign of `ScriptBlockFilter` with backward compatibility.
Modified `PSThisVariable` to implement `IPoolable` for better memory management.
Updated `Debug.ps1` to ensure module imports are forced.
- Introduced nullable reference types with `#nullable enable`.
- Updated `CaseSensitive` property to use `IsParameterValueCaseSensitive`.
- Modified `GetCustomEqualityComparer` to return appropriate `StringComparer`.
- Renamed `RetrieveCaseSensitiveSetting` to `IsParameterValueCaseSensitive` and changed its implementation to use `LanguagePrimitives.IsTrue`.
- Refactored `AssertAllObjectsCmdlet` and `AssertAnyObjectCmdlet` to inherit from `AssertObjectCmdlet`, enhancing their processing logic and allowing nullable collections.
- Updated `AssertObjectCmdlet` with a new `HasCondition` property and improved error handling in processing methods.
- Enhanced `ConvertToDictionaryCmdlet`, `EqualityConstructingCmdlet`, and collection cmdlets (`NewDictionaryCmdlet`, `NewHashSetCmdlet`, `NewListCmdlet`, `NewSortedSetCmdlet`) for better type handling and error reporting.
- Refactored `FindIndexCmdlet` and `FindLastIndexCmdlet` to inherit from `ListFunctionCmdletBase`, improving input handling.
- Improved error handling and processing flow in `ListFunctionCmdletBase` with a new `_wantsToStop` flag.
- Updated project file for assembly visibility changes and modified `ListPool` and `ObjPool` for better framework compatibility.
This commit removes the unused and commented-out `EndProcessing` method in the `AssertAnyObjectCmdlet.cs` file. The method previously contained logic for condition checking and outputting based on `_hasNonNull` and `_stop`. The existing `End` method, which writes the script result, remains unchanged.
This commit removes the entire `ScriptBlockFilterOld.cs` file, including the `ScriptBlockFilterOld` abstract class and its derived class `ScriptBlockFilterOld<T>`. All associated methods, properties, namespaces, and using directives have also been deleted.
Refactor `ListFunctions-NETFramework.csproj` and `ListFunctions-Next.csproj` to conditionally manage the inclusion of `Debug.ps1`. In non-Release configurations, it will be copied to the output directory, while in Release configurations, it will not be copied to either the output or publish directories. Previous entries for `Debug.ps1` have been removed to implement this logic.
- Updated version number in `ListFunctions.psd1` from `2.0.0` to `3.0.0`.
- Changed copyright year in `ListFunctions.psd1` from `2024` to `2025`.
- Modified minimum PowerShell version requirement in `ListFunctions.psd1` from `5.1` to `5.0`.
- Adjusted assembly loading in `ListFunctions.psm1`, commenting out certain modules.
- Inverted logic in `ProcessCore` method of `AssertObjectCmdlet.cs`.
- Added `ZLinq.dll` and deleted `MG.Collections.Resources.dll` and `MG.Collections.dll`.
- Updated PowerShell version requirement to 5.1.
- Added `New-SortedSet` to exported cmdlets.
- Modified file list to include `Core\ZLinq.dll` and retain `Desk\ListFunctions.NETFramework.dll`, removing `Core\MG.Collections.dll` and `Core\MG.Collections.Resources.dll`.
- Expanded tags in `PrivateData` to include 'Convert' and 'ConvertTo'.
- Updated release notes to reflect performance improvements and ZLinq library utilization for PowerShell 7.
Modified the increment of _currentIndex to use the length of
this.InputObject instead of the previous increment value.
Changed the return value from false to true to indicate
that processing should continue.
Updated validation to use IsNullOrWhitespace for name and version checks. Changed Where clause to Where-Object for better clarity. Removed unnecessary commented-out code related to custom object creation.
- Changed language version in `ListFunctions-NETFramework.csproj` from 8.0 to 9.0.
- Added new parameters to ConvertTo-Dictionary (ValueType and DuplicateKeyBehavior).

Update language version and enhance dictionary handling

- Changed language version in `ListFunctions-NETFramework.csproj` from 8.0 to 9.0.
- Added new using directives in `ConvertToDictionaryCmdlet.cs` for `ListFunctions.Modern`, `ListFunctions.Modern.Variables`, and `ListFunctions.Validation`.
- Made `DuplicateKeyBehavior` mandatory and added `KeyComparer` property.
- Updated `ValueSelector` handling with a new nullable `ValueType` property.
- Refactored `BeginCore` to use `GetValueType` for determining value type.
- Modified `ProcessCore` to utilize a new `AddToDictionary` method.
- Introduced `AddToDictionary` method to manage dictionary entries based on `DuplicateKeyBehavior`.
- Added `DuplicateKeyBehavior` enum in `DuplicateKeyBehavior.cs`.
- Created `ObjectList` class in `ObjectList.cs` extending `List<object?>` with an initial capacity of 2.
Changes handling of DuplicateKeyBehavior.Concatenate to always use &AddConcat.
Add warning in GetValueType method when Concatenate is used, indicating that the specified type is ignored and values can be objects or lists of objects.
Return typeof(object) for value type in this case.
Introduced a new private field `_addToDictionaryPtr` to store a pointer to a delegate for handling duplicate key behaviors. This pointer is assigned in the `BeginCore` method based on `DuplicateKeyBehavior`. Removed the delegate instantiation from the `AddToDictionary` method, which now retrieves the delegate pointer from `_addToDictionaryPtr`, improving performance by eliminating the need for multiple switch iterations per InputObject.
This commit introduces the `StoreAddToDictionaryFunction` method to centralize the logic for handling duplicate key behavior, eliminating unsafe code blocks. It improves input object handling with a nullable array for better null checks and updates the `AddToDictionary` method to accept a function pointer directly. The `GetValueType` method is also modified for clearer behavior with the `Concatenate` option. Overall, these changes enhance code organization, readability, and maintainability.
Yevrag35 and others added 6 commits September 8, 2025 17:25
Introduces validation to KeySelector parameter to the `ConvertToDictionaryCmdlet` class. This property includes the `ValidateScriptVariable` attribute to ensure valid script variable names. It is positioned first in the "KeyScript" parameter set and defaults to `null!`, enforcing non-nullability at runtime.
Updated the `ValidateScriptVariable` attribute to include
new parameters for indexed arguments (`ARGS_FIRST` and
`ARGS_SECOND`). Modified cmdlets such as
`AssertAllObjectsCmdlet`, `AssertAnyObjectCmdlet`,
`ConvertToDictionaryCmdlet`, `NewHashSetCmdlet`,
`NewSortedSetCmdlet`, `FindIndexCmdlet`, and
`FindLastIndexCmdlet` to support these changes.
Refactored the `ValidateScriptVariableAttribute` class
and updated the `PSThisVariable` class to define the
new constants, improving the overall validation process
for script blocks.
- Added new using directives and removed duplicates in ConvertToDictionaryCmdlet.cs.
- Improved KeyComparer condition and introduced nullable dictType for better type handling.
- Enhanced error handling with ListFunctionsException to provide more context on failures.
- Updated ValidateScriptVariableAttribute.cs to use HashSet<string> for better performance and null handling.
- Introduced ObjectExtensions class in ObjectExtensions.cs for cloning functionality.
This commit simplifies several cmdlet classes by removing unused methods, including `BeginProcessing`, `ProcessRecord`, and `EndProcessing` from `AssertAllObjectsCmdlet.cs` and `AssertAnyObjectCmdlet.cs`. The `FindIndexCmdlet.cs` file has been streamlined by removing the `End` method and related indexing methods. Additionally, the non-generic `TryGetCount` method in `EnumerableExtensions.cs` has been removed to focus on generics. Unused code has been cleaned up in `ScriptBlockInvocationException.cs`, and abstract methods in `PSComparingVariable.cs` have been eliminated. Finally, the `PSThisVariable<T>` class has been removed, indicating a potential refactor in variable management.
- Added a using directive for `ListFunctions.Extensions`.
- Removed the `CopyObject` method and replaced it with `CloneIf()` for object cloning.
- Simplified the retrieval of the `statement` variable by inlining the call to `_statementProp.Value.GetValue(info)`.
- Updated handling of `variable.Value` to utilize the new `CloneIf()` method, improving clarity and efficiency.
Updated binaries and project files for v3.1.0 release. Key changes include:
- Fixed `Find-IndexOf` cmdlet returning incorrect results.
- Incremented `ModuleVersion`, `AssemblyVersion`, `FileVersion` to 3.1.0.
- Updated copyright years to 2025 across all files.
- Added new source files under `Nullable` directory.
- Updated references and output paths for .NET Framework 4.7.1.
- Minor formatting fixes in project files.
@Yevrag35 Yevrag35 self-assigned this Sep 13, 2025
@Yevrag35 Yevrag35 merged commit ebc9dac into master Sep 13, 2025
1 check failed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants