fixed to useoOpenfeature model value & structure builder

Signed-off-by: bbland1 <104288486+bbland1@users.noreply.github.com>
This commit is contained in:
bbland1 2025-06-19 01:32:39 -04:00
parent 9e89319097
commit 43157a98bf
3 changed files with 16 additions and 24 deletions

View File

@ -158,15 +158,15 @@ namespace TestNamespace
/// </summary>
/// <remarks>
/// <para>Flag key: themeCustomization</para>
/// <para>Default value: new Dictionary<string, object>{{ "primaryColor", "#007bff" }, { "secondaryColor", "#6c757d" }}</para>
/// <para>Default value: new Value(new Structure.Builder().Set("primaryColor", "#007bff").Set("secondaryColor", "#6c757d").Build())</para>
/// <para>Type: object</para>
/// </remarks>
/// <param name="evaluationContext">Optional context for the flag evaluation</param>
/// <param name="options">Options for flag evaluation</param>
/// <returns>The flag value</returns>
public async Task<object> ThemeCustomizationAsync(EvaluationContext? evaluationContext = null, FlagEvaluationOptions? options = null)
public async Task<Value> ThemeCustomizationAsync(EvaluationContext? evaluationContext = null, FlagEvaluationOptions? options = null)
{
return await _client.GetObjectValueAsync("themeCustomization", new Dictionary<string, object>{{ "primaryColor", "#007bff" }, { "secondaryColor", "#6c757d" }}, evaluationContext, options);
return await _client.GetObjectValueAsync("themeCustomization", new Value(new Structure.Builder().Set("primaryColor", "#007bff").Set("secondaryColor", "#6c757d").Build()), evaluationContext, options);
}
/// <summary>
@ -174,15 +174,15 @@ namespace TestNamespace
/// </summary>
/// <remarks>
/// <para>Flag key: themeCustomization</para>
/// <para>Default value: new Dictionary<string, object>{{ "primaryColor", "#007bff" }, { "secondaryColor", "#6c757d" }}</para>
/// <para>Default value: new Value(new Structure.Builder().Set("primaryColor", "#007bff").Set("secondaryColor", "#6c757d").Build())</para>
/// <para>Type: object</para>
/// </remarks>
/// <param name="evaluationContext">Optional context for the flag evaluation</param>
/// <param name="options">Options for flag evaluation</param>
/// <returns>The evaluation details containing the flag value and metadata</returns>
public async Task<FlagEvaluationDetails<object>> ThemeCustomizationDetailsAsync(EvaluationContext? evaluationContext = null, FlagEvaluationOptions? options = null)
public async Task<FlagEvaluationDetails<Value>> ThemeCustomizationDetailsAsync(EvaluationContext? evaluationContext = null, FlagEvaluationOptions? options = null)
{
return await _client.GetObjectValueAsync("themeCustomization", new Dictionary<string, object>{{ "primaryColor", "#007bff" }, { "secondaryColor", "#6c757d" }}, evaluationContext, options);
return await _client.GetObjectValueAsync("themeCustomization", new Value(new Structure.Builder().Set("primaryColor", "#007bff").Set("secondaryColor", "#6c757d").Build()), evaluationContext, options);
}
/// <summary>

View File

@ -2,7 +2,6 @@ package csharp
import (
_ "embed"
"encoding/json"
"fmt"
"maps"
"slices"
@ -65,17 +64,14 @@ func toCSharpDict(value any) string {
keys := slices.Sorted(maps.Keys(assertedMap))
var builder strings.Builder
builder.WriteString("new Dictionary<string, object>{")
builder.WriteString("new Value(new Structure.Builder()")
for index, key := range keys {
if index > 0 {
builder.WriteString(", ")
}
for _, key := range keys {
val := assertedMap[key]
builder.WriteString(fmt.Sprintf("{ %q, %s }", key, formatNestedValue(val)))
builder.WriteString(fmt.Sprintf(".Set(%q, %s)", key, formatNestedValue(val)))
}
builder.WriteString("}")
builder.WriteString(".Build())")
return builder.String()
}
@ -110,22 +106,18 @@ func formatNestedValue(value any) string {
return toCSharpDict(val)
case []any:
var sliceBuilder strings.Builder
sliceBuilder.WriteString("new List<object>{")
sliceBuilder.WriteString("new Value(new List<Value>{")
for index, elem := range val {
if index > 0 {
sliceBuilder.WriteString(",")
sliceBuilder.WriteString(", ")
}
sliceBuilder.WriteString(formatNestedValue(elem))
}
sliceBuilder.WriteString("}")
sliceBuilder.WriteString("})")
return sliceBuilder.String()
default:
jsonBytes, err := json.Marshal(val)
if err != nil {
return "null"
}
return fmt.Sprintf("%q", string(jsonBytes))
return fmt.Sprintf("new Value(%s)", val)
}
}

View File

@ -70,7 +70,7 @@ namespace {{ if .Params.Custom.Namespace }}{{ .Params.Custom.Namespace }}{{ else
/// <param name="evaluationContext">Optional context for the flag evaluation</param>
/// <param name="options">Options for flag evaluation</param>
/// <returns>The flag value</returns>
public async Task<{{ .Type | OpenFeatureType }}> {{ .Key | ToPascal }}Async(EvaluationContext? evaluationContext = null, FlagEvaluationOptions? options = null)
public async Task<{{ if eq (.Type | OpenFeatureType) "object" }}Value{{ else }}{{ .Type | OpenFeatureType }}{{ end }}> {{ .Key | ToPascal }}Async(EvaluationContext? evaluationContext = null, FlagEvaluationOptions? options = null)
{
{{- if eq .Type 1 }}
return await _client.GetIntegerValueAsync("{{ .Key }}", {{ . | FormatDefaultValue }}, evaluationContext, options);
@ -98,7 +98,7 @@ namespace {{ if .Params.Custom.Namespace }}{{ .Params.Custom.Namespace }}{{ else
/// <param name="evaluationContext">Optional context for the flag evaluation</param>
/// <param name="options">Options for flag evaluation</param>
/// <returns>The evaluation details containing the flag value and metadata</returns>
public async Task<FlagEvaluationDetails<{{ .Type | OpenFeatureType }}>> {{ .Key | ToPascal }}DetailsAsync(EvaluationContext? evaluationContext = null, FlagEvaluationOptions? options = null)
public async Task<FlagEvaluationDetails<{{ if eq (.Type | OpenFeatureType) "object" }}Value{{ else }}{{ .Type | OpenFeatureType }}{{ end }}>> {{ .Key | ToPascal }}DetailsAsync(EvaluationContext? evaluationContext = null, FlagEvaluationOptions? options = null)
{
{{- if eq .Type 1 }}
return await _client.GetIntegerDetailsAsync("{{ .Key }}", {{ . | FormatDefaultValue }}, evaluationContext, options);