When I try to instantiate this variable I am told I am missing the required parameter "xAxis". However, when I try to define "xAxis" I am told the class does not contain a definition for "xAxis".
Here are the pop ups:
Attempting to instantiate the variable:
var rule = new ScottPlot.AxisRules.MaximumBoundary
{
xAxis = thisPlot.Axes.Left,
yAxis = thisPlot.Axes.Bottom,
Limits = new AxisLimits(thisPlot.Axes.GetDataLimits().Left * 0.05, thisPlot.Axes.GetDataLimits().Right * 0.05, 0, 100)
};
These are the 2 warnings I get:
There is no argument given that corresponds to the required parameter
'type' does not contain a definition for 'identifier'
And here is the full class definition:
namespace ScottPlot.AxisRules;
public class MaximumBoundary(IXAxis xAxis, IYAxis yAxis, AxisLimits limits) : IAxisRule
{
readonly IXAxis XAxis = xAxis;
readonly IYAxis YAxis = yAxis;
public AxisLimits Limits { get; set; } = limits;
public void Apply(RenderPack rp, bool beforeLayout)
{
double horizontalSpan = Math.Min(Math.Abs(XAxis.Range.Span), Limits.XRange.Span);
double verticalSpan = Math.Min(Math.Abs(YAxis.Range.Span), Limits.YRange.Span);
if (XAxis.IsInverted())
{
if (XAxis.Range.Min > Limits.XRange.Max)
{
XAxis.Range.Min = Limits.XRange.Max;
XAxis.Range.Max = Limits.XRange.Max - horizontalSpan;
}
if (XAxis.Range.Max < Limits.XRange.Min)
{
XAxis.Range.Max = Limits.XRange.Min;
XAxis.Range.Min = Limits.XRange.Min + horizontalSpan;
}
}
else
{
if (XAxis.Range.Max > Limits.XRange.Max)
{
XAxis.Range.Max = Limits.XRange.Max;
XAxis.Range.Min = Limits.XRange.Max - horizontalSpan;
}
if (XAxis.Range.Min < Limits.XRange.Min)
{
XAxis.Range.Min = Limits.XRange.Min;
XAxis.Range.Max = Limits.XRange.Min + horizontalSpan;
}
}
if (YAxis.IsInverted())
{
if (YAxis.Range.Min > Limits.YRange.Max)
{
YAxis.Range.Min = Limits.YRange.Max;
YAxis.Range.Max = Limits.YRange.Max - verticalSpan;
}
if (YAxis.Range.Max < Limits.YRange.Min)
{
YAxis.Range.Max = Limits.YRange.Min;
YAxis.Range.Min = Limits.YRange.Min + verticalSpan;
}
}
else
{
if (YAxis.Range.Max > Limits.YRange.Max)
{
YAxis.Range.Max = Limits.YRange.Max;
YAxis.Range.Min = Limits.YRange.Max - verticalSpan;
}
if (YAxis.Range.Min < Limits.YRange.Min)
{
YAxis.Range.Min = Limits.YRange.Min;
YAxis.Range.Max = Limits.YRange.Min + verticalSpan;
}
}
}
}
I noticed that if I try to create a class of my own with a "readonly" property, I am met with the message "Feature 'readonly members' is not available in C# 7.3. Please use language version 8.0 or greater"
Is it possible it isn't recognizing the readonly properties because of my C# version? I'd like to not have to change my target framework or downgrade my scottPlot version. Is there a way to get this to work?
I am running this on .NET Framework 4.8 and ScottPlot version 5.0
I is unclear why do you think two error messages are contradicting. It looks like they are complementary.
The issue with the first code sample is very simple.xAxis = thisPlot.Axes.Left, yAxis = thisPlot.Axes.Bottom
is wrong because there are no such members in the class MaximumBoundary
. You are dealing with the primary constructor of this class, where xAxis
and yAxis
are not members, but the constructor parameters, so you have to use the constructor and not the initialization block:
var rule = new ScottPlot.AxisRules.MaximumBoundary(
thisPlot.Axes.Left,
thisPlot.Axes.Bottom,
new AxisLimits(
thisPlot.Axes.GetDataLimits().Left * 0.05,
thisPlot.Axes.GetDataLimits().Right * 0.05, 0, 100))
);
As people say in such cases, “find ten differences”. 😃
Unfortunately, you did not provide the code sample with this bug, but I can explain the error message no matter what you have tried. Indeed, the class
MaximumBoundary
does not contain a definition of xAxis
, as I explained above. You only say:
However, when I try to define
xAxis
I am told the class does not contain a definition forxAxis
.
You get to get to understanding if you read some original documentation and/or tutorials, for example, Tutorial: Explore primary constructors.