-
I have a read-only structure where properties are dependent from other properties in the same structure. It would be completely sufficient to have everything set in the initialization using a compound initialization with var gridSize1 = new CudaGridBlockSize
{
BlocksizeX = 64,
BlocksizeY = 1,
BlocksizeZ = 1,
GridsizeX = ((width - 1) / BlocksizeX / 4) + 1,
GridsizeY = ((height - 1) / BlocksizeY) + 1,
GridsizeZ = ((depth - 1) / BlocksizeZ) + 1
} so I came up with the idea of using withers but found that also here I have no access to the original. Is this even possible? var gridSize1 = new CudaGridBlockSize
{
BlocksizeX = 64,
BlocksizeY = 1,
BlocksizeZ = 1
}
with
{
// Accessing gridsize1 does not work
GridsizeX = ((width - 1) / gridSize1.BlocksizeX / 4) + 1,
GridsizeY = ((height - 1) / gridSize1.BlocksizeY) + 1,
GridsizeZ = ((depth - 1) / gridSize1.BlocksizeZ) + 1
}; |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
You can't access If you assign the variable first you can use var gridSize1 = new CudaGridBlockSize
{
BlocksizeX = 64,
BlocksizeY = 1,
BlocksizeZ = 1
} ;
gridSize1 = gridSize1 with
{
GridsizeX = ((width - 1) / gridSize1.BlocksizeX / 4) + 1,
GridsizeY = ((height - 1) / gridSize1.BlocksizeY) + 1,
GridsizeZ = ((depth - 1) / gridSize1.BlocksizeZ) + 1
}; There is a separate issue where improvements to initializers/withers are being considered but I don't think it includes attempting to reference other properties like this: #5176 |
Beta Was this translation helpful? Give feedback.
You can't access
gridSize1
until after it has been assigned, which in your expression isn't until after thewith
expression which is why it's not accessible there.If you assign the variable first you can use
with
in this manner:There is a separate issue wher…