-
Notifications
You must be signed in to change notification settings - Fork 594
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use records with Bh1745 #1258
Use records with Bh1745 #1258
Conversation
@@ -39,6 +39,10 @@ | |||
</Reference> | |||
</ItemGroup> | |||
|
|||
<ItemGroup Condition="'$(TargetFramework)' != 'netstandard2.0'"> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't this condition be the other way around? Right now it is compiling the file on net5.0 but not on NS2.0
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Discussed offline, we will instead move this type to iot.device.bindings and the binding itself and try to make it internal.
src/devices/Bh1745/Bh1745.cs
Outdated
{ | ||
Red = 2.2, Green = 1.0, Blue = 1.8, Clear = 10.0 | ||
}; | ||
ChannelCompensationMultipliers = new ( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
While I don't have a big preference, I suppose that object initializer still works with records right? Like:
ChannelCompensationMultipliers = new ()
{
Red = 2.2, Green = 1.0, Blue = 1.8, Clear = 10.0
};
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If I do that, then the constructor isn't satisfied, and then I cannot use the pretty records syntax.
src/devices/Bh1745/Bh1745.csproj
Outdated
@@ -8,6 +8,7 @@ | |||
|
|||
<ItemGroup> | |||
<Compile Include="*.cs" /> | |||
<Compile Include="$(MSBuildThisFileDirectory)/../Common/System/Runtime/CompilerServices/IsExternalInit.cs"/> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
<Compile Include="$(MSBuildThisFileDirectory)/../Common/System/Runtime/CompilerServices/IsExternalInit.cs"/> | |
<Compile Include="$(MSBuildThisFileDirectory)/../Common/System/Runtime/CompilerServices/IsExternalInit.cs"> | |
<Link>Common/System/Runtime/CompilerServices/IsExternalInit.cs</Link> | |
</Compile> |
Nit: Add a Link here for VS Experience.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
* Add records to Bh1745: * Add tracking issue for /// docs * Move record to primary class file * Define records first * Simplify sleep * Add extension file * Add object initializers * Remove space * Change extension method name * Move IsExternalInit * Update handling of IsExternalInit
First test of using records in this codebase. This binding seemed like a perfect use case for records.
I made a few choices:
IsExternalInit
as part of thenetstandard2.0
asset (required to use records pre .NET 5.0).These are all a first take. What do you think?
///
doc comments don't currently work for records due to dotnet/roslyn#44571. I don't think this should stop us from getting started with records.Going forward, I think we should convert a small set of data-oriented classes to records, and see if we get any feedback on their usage. For this first case, I've gone with the (very pretty) immutable version of records. That seems to fit this case well. We may find that we want to enable mutable properties for some cases. That said, the
with
syntax is pretty compelling.