[Interface2NullObject]Replace default-part 4
So for https://github.com/ignatandrei/rscg_Interface_to_null_object we put the default return value as the default for the return type. For properties, it is enough easy to modify the data. But for functions ? Let’s say we return an array
public IEmployee[] Employees();
The default value is null – so it will be throwing an error when do “foreach ” .
So – I should think about a way to register default values for different methods.
I have the idea to register into the .csproj – so here it is
<ItemGroup> <CompilerVisibleProperty Include="I2NO_String" /> <CompilerVisibleProperty Include="I2NO_IntegrationConsole_IEmployee_Array" /> <CompilerVisibleProperty Include="I2NO_System_Collections_Generic_IAsyncEnumerable_Of_IntegrationConsole_IEmployee_EndOf" /> </ItemGroup> <ItemGroup> <PackageReference Include="System.Linq.Async" Version="6.0.1" /> </ItemGroup> <PropertyGroup> <I2NO_String>return ""</I2NO_String> <I2NO_IntegrationConsole_IEmployee_Array>return []</I2NO_IntegrationConsole_IEmployee_Array> <I2NO_System_Collections_Generic_IAsyncEnumerable_Of_IntegrationConsole_IEmployee_EndOf>return AsyncEnumerable.Empty_Of_IntegrationConsole.IEmployee_EndOf();</I2NO_System_Collections_Generic_IAsyncEnumerable_Of_IntegrationConsole_IEmployee_EndOf> </PropertyGroup>
So this is the result
public virtual string Name { get; set; } = default(string); public virtual IntegrationConsole.IEmployee[] Employees() { return [] ; } public virtual System.Collections.Generic.IAsyncEnumerable<IntegrationConsole.IEmployee> EmployeesAsync() { return AsyncEnumerable.Empty<IntegrationConsole.IEmployee>() ; }
Leave a Reply