Skip to content

Const strings are not handled #56

@jprokopski

Description

@jprokopski

Report

When using const strings in the code, the generated XML is incorrect. Instead of correctly including the value of the constant in the XML, it generates empty sting.

Expected Behavior

[Document]
public class ExamplePolicy : IDocument
{
    public void Inbound(IInboundContext c)
    {
        c.SetHeader(Headers.Example, "Test");
    }
}

public static class Headers
{
    public const string Example = "X-Example";
}

should return

<!-- This file is generated by the Azure API Management Policy Toolkit -->
<!-- Version: 0.0.1.0 -->
<policies>
  <inbound>
    <set-header name="X-Example" exists-action="override">
      <value>Test</value>
    </set-header>
  </inbound>
</policies>

Actual Behavior

[Document]
public class ExamplePolicy : IDocument
{
    public void Inbound(IInboundContext c)
    {
        c.SetHeader(Headers.Example, "Test");
    }
}

public static class Headers
{
    public const string Example = "X-Example";
}

returns

<!-- This file is generated by the Azure API Management Policy Toolkit -->
<!-- Version: 0.0.1.0 -->
<policies>
  <inbound>
    <set-header name="" exists-action="override">
      <value>Test</value>
    </set-header>
  </inbound>
</policies>

Steps to Reproduce the Problem

  1. Create an example policy with a header as const string.
[Document]
public class ExamplePolicy : IDocument
{
    public void Inbound(IInboundContext c)
    {
        c.SetHeader(Headers.Example, "Test");
    }
}

public static class Headers
{
    public const string Example = "X-Example";
}
  1. Run compiler.

Component

Compiler

Version

v1.0.0

Contact Details

No response

Additional Information

No response

Metadata

Metadata

Assignees

Labels

enhancementNew feature or request

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions