Home > Software engineering >  VB.net need to Override in parameter from C# library
VB.net need to Override in parameter from C# library

Time:11-30

I am trying to figure out how to inherit from the C# Sampler class from OpenTelemetry.Trace into VB.net class.

When I use Visual Studio to auto implement the abstract class it provides the following code below, however I can't find "IsReadOnlyAttribute" in any dll for any .net framework 4.6.2 which is what our project is using.

Searching online finds me enter image description here

To find out if this was to do with the parameters or the "in" modifier I added a function as per below which shows that this does work and the issue is still with the "in" parameter modifier.

Public Function Test(ByRef samplingParameters As SamplingParameters) As SamplingResult
    Return New SamplingResult(True)
End Function

I am wondering if this a defect of C# to VB or some limitation I am hitting.

CodePudding user response:

The best path forward that I found here was to create the following class in a C# project and then reference this in the VB.net project.

  public abstract class SamplerAdapter : Sampler
  {
    public override SamplingResult ShouldSample(in SamplingParameters samplingParameters)
    {
      return ShouldSampleAdapter(samplingParameters);
    }

    public abstract SamplingResult ShouldSampleAdapter(SamplingParameters samplingParameters);
  }
  • Related