Skip to content

Commit

Permalink
context
Browse files Browse the repository at this point in the history
  • Loading branch information
StefH committed Jan 16, 2021
1 parent 3931003 commit 1b20da0
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 0 deletions.
55 changes: 55 additions & 0 deletions src/WireMock.Net/Transformers/Scriban/WireMockListAccessor.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
using System;
using System.Collections.Generic;
using Scriban;
using Scriban.Parsing;
using Scriban.Runtime;

namespace WireMock.Transformers.Scriban
{
internal class WireMockListAccessor : IListAccessor, IObjectAccessor
{
#region IListAccessor
public int GetLength(TemplateContext context, SourceSpan span, object target)
{
throw new NotImplementedException();
}

public object GetValue(TemplateContext context, SourceSpan span, object target, int index)
{
return target.ToString();
}

public void SetValue(TemplateContext context, SourceSpan span, object target, int index, object value)
{
throw new NotImplementedException();
}
#endregion

#region IObjectAccessor
public int GetMemberCount(TemplateContext context, SourceSpan span, object target)
{
throw new NotImplementedException();
}

public IEnumerable<string> GetMembers(TemplateContext context, SourceSpan span, object target)
{
throw new NotImplementedException();
}

public bool HasMember(TemplateContext context, SourceSpan span, object target, string member)
{
throw new NotImplementedException();
}

public bool TryGetValue(TemplateContext context, SourceSpan span, object target, string member, out object value)
{
throw new NotImplementedException();
}

public bool TrySetValue(TemplateContext context, SourceSpan span, object target, string member, object value)
{
throw new NotImplementedException();
}
#endregion
}
}
19 changes: 19 additions & 0 deletions src/WireMock.Net/Transformers/Scriban/WireMockTemplateContext.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
using Scriban;
using Scriban.Runtime;
using WireMock.Types;

namespace WireMock.Transformers.Scriban
{
internal class WireMockTemplateContext: TemplateContext
{
protected override IObjectAccessor GetMemberAccessorImpl(object target)
{
if (target?.GetType().GetGenericTypeDefinition() == typeof(WireMockList<>))
{
return new WireMockListAccessor();
}

return base.GetMemberAccessorImpl(target);
}
}
}
2 changes: 2 additions & 0 deletions src/WireMock.Net/WireMock.Net.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@

<ItemGroup>
<Compile Remove="Transformers\Scriban\ScribanTransformer.cs" />
<Compile Remove="Transformers\Scriban\WireMockListAccessor.cs" />
<Compile Remove="Transformers\Scriban\WireMockTemplateContext.cs" />
</ItemGroup>

<ItemGroup>
Expand Down

0 comments on commit 1b20da0

Please sign in to comment.