Ejemplo n.º 1
0
 protected override void HeaderOpenStronglyTypedClass(CodeStringBuilder builderHeader, string resourceFilename, string className)
 {
     builderHeader.AppendLine($"struct {className}");
     builderHeader.AppendLine("{");
     builderHeader.AppendLine("private:");
     builderHeader.AddLevel();
     builderHeader.AppendLine("static Windows::ApplicationModel::Resources::ResourceLoader _resourceLoader;");
     builderHeader.AppendLine("static Windows::ApplicationModel::Resources::ResourceLoader GetResourceLoader();");
     builderHeader.RemoveLevel();
     builderHeader.AppendLine("public:");
     builderHeader.AddLevel();
     builderHeader.AppendLine($"{className}() {{}}");
     builderHeader.RemoveLevel();
 }
Ejemplo n.º 2
0
 protected override void HeaderCreateAccessor(CodeStringBuilder builderHeader, string key, string summary)
 {
     builderHeader.AppendLine("public:");
     builderHeader.AddLevel();
     builderHeader.AppendLine("/// <summary>");
     builderHeader.AppendLine($"///   {summary}");
     builderHeader.AppendLine("/// </summary>");
     builderHeader.AppendLine($"static property Platform::String^ {key}");
     builderHeader.AppendLine("{");
     builderHeader.AddLevel();
     builderHeader.AppendLine("Platform::String^ get();");
     builderHeader.RemoveLevel();
     builderHeader.AppendLine("}");
     builderHeader.RemoveLevel();
 }
Ejemplo n.º 3
0
 protected override void CppGenerateStronglyTypedClassStaticFunc(CodeStringBuilder builderHeader, string computedNamespace, string resourceFilename)
 {
     builderHeader.AppendLine($"ResourceLoader^ {computedNamespace}_resourceLoader = nullptr;");
     builderHeader.AppendLine($"ResourceLoader^ {computedNamespace}GetResourceLoader()");
     builderHeader.AppendLine("{");
     builderHeader.AddLevel();
     builderHeader.AppendLine("if (_resourceLoader == nullptr)");
     builderHeader.AppendLine("{");
     builderHeader.AddLevel();
     builderHeader.AppendLine($"_resourceLoader = ResourceLoader::GetForViewIndependentUse(L\"{resourceFilename}\");");
     builderHeader.RemoveLevel();
     builderHeader.AppendLine("}");
     builderHeader.AppendLine("return _resourceLoader;");
     builderHeader.RemoveLevel();
     builderHeader.AppendLine("}");
 }
Ejemplo n.º 4
0
        protected override void HeaderCreateFormatMethod(CodeStringBuilder builderHeader, string key, bool isProperty, IEnumerable <FunctionFormatTagParameter> parameters, string summary = null, IEnumerable <FunctionFormatTagParameter> extraParameters = null)
        {
            IEnumerable <FunctionFormatTagParameter> functionParameters;

            if (extraParameters != null)
            {
                var list = new List <FunctionFormatTagParameter>(parameters);
                list.InsertRange(0, extraParameters);
                functionParameters = list;
            }
            else
            {
                functionParameters = parameters;
            }

            if (isProperty)
            {
                HeaderCreateAccessor(builderHeader, key, summary);
            }
            else
            {
                builderHeader.AppendLine("public:");
                builderHeader.AddLevel();
                builderHeader.AppendLine("/// <summary>");
                builderHeader.AppendLine($"///   {summary}");
                builderHeader.AppendLine("/// </summary>");

                var parametersStr = functionParameters == null || !functionParameters.Any() ?
                                    "" :
                                    functionParameters.Select(p => GetParameterTypeString(p.Type, true) + " " + p.Name).Aggregate((a, b) => a + ", " + b); builderHeader.AppendLine($"static Platform::String^ {key}({parametersStr});");
                builderHeader.RemoveLevel();
            }
        }
Ejemplo n.º 5
0
 protected override void CloseNamespace(CodeStringBuilder builder, IEnumerable <string> namespaces)
 {
     if (namespaces != null && namespaces.Any())
     {
         builder.RemoveLevel();
         builder.AppendLine($"}} //{namespaces.Aggregate((a, b) => a + "." + b)}");
     }
 }
Ejemplo n.º 6
0
 protected override void CppCreateAccessor(CodeStringBuilder builderHeader, string computedNamespace, string key)
 {
     builderHeader.AppendLine($"String^ {computedNamespace}{key}::get()");
     builderHeader.AppendLine("{");
     builderHeader.AddLevel();
     builderHeader.AppendLine($"return GetResourceLoader()->GetString(L\"{key}\");");
     builderHeader.RemoveLevel();
     builderHeader.AppendLine("}");
 }
Ejemplo n.º 7
0
 public void HeaderCloseNamespace(CodeStringBuilder builderHeader, IEnumerable <string> namespaces, bool supportNestedMamespacesAtOnce)
 {
     if (namespaces != null && namespaces.Any())
     {
         if (supportNestedMamespacesAtOnce)
         {
             builderHeader.RemoveLevel();
             builderHeader.AppendLine($"}} // namespace {namespaces.Aggregate((a, b) => a + "::" + b)}");
         }
         else
         {
             foreach (var n in namespaces.Reverse())
             {
                 builderHeader.RemoveLevel();
                 builderHeader.AppendLine($"}} // namespace {n}");
             }
         }
     }
 }
Ejemplo n.º 8
0
 protected override void HeaderCreateAccessor(CodeStringBuilder builderHeader, string key, string summary)
 {
     builderHeader.AppendLine("public:");
     builderHeader.AddLevel();
     builderHeader.AppendLine("/// <summary>");
     builderHeader.AppendLine($"///   {summary}");
     builderHeader.AppendLine("/// </summary>");
     builderHeader.AppendLine($"static hstring {key}();");
     builderHeader.RemoveLevel();
 }
Ejemplo n.º 9
0
 protected override void OpenStronglyTypedClass(CodeStringBuilder builder, string resourceFilename, string className)
 {
     builder.AppendLine($"<System.CodeDom.Compiler.GeneratedCodeAttribute(\"{Constants.ReswPlusName}\", \"{Constants.ReswPlusExtensionVersion}\")>");
     builder.AppendLine("<System.Diagnostics.DebuggerNonUserCodeAttribute()>");
     builder.AppendLine("<System.Runtime.CompilerServices.CompilerGeneratedAttribute()>");
     builder.AppendLine($"Public Class {className}");
     builder.AddLevel();
     builder.AppendLine("Private Shared _resourceLoader as ResourceLoader");
     builder.AppendEmptyLine();
     builder.AppendLine($"Shared Sub New()");
     builder.AddLevel();
     builder.AppendLine($"_resourceLoader = ResourceLoader.GetForViewIndependentUse(\"{resourceFilename}\")");
     builder.RemoveLevel();
     builder.AppendLine("End Sub");
 }
Ejemplo n.º 10
0
 protected override void OpenStronglyTypedClass(CodeStringBuilder builder, string resourceFilename, string className)
 {
     builder.AppendLine($"[global::System.CodeDom.Compiler.GeneratedCodeAttribute(\"{Constants.ReswPlusName}\", \"{Constants.ReswPlusExtensionVersion}\")]");
     builder.AppendLine("[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]");
     builder.AppendLine("[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]");
     builder.AppendLine($"public static class {className} {{");
     builder.AddLevel();
     builder.AppendLine("private static ResourceLoader _resourceLoader;");
     builder.AppendLine($"static {className}()");
     builder.AppendLine("{");
     builder.AddLevel();
     builder.AppendLine($"_resourceLoader = ResourceLoader.GetForViewIndependentUse(\"{resourceFilename}\");");
     builder.RemoveLevel();
     builder.AppendLine("}");
 }
Ejemplo n.º 11
0
 private void IdlCreateMarkupExtension(CodeStringBuilder builderHeader, string className, IEnumerable <string> keys)
 {
     builderHeader.AppendLine("enum KeyEnum");
     builderHeader.AppendLine("{");
     builderHeader.AddLevel();
     builderHeader.AppendLine("__Undefined = 0,");
     foreach (var key in keys)
     {
         builderHeader.AppendLine($"{key},");
     }
     builderHeader.RemoveLevel();
     builderHeader.AppendLine("};");
     builderHeader.AppendEmptyLine();
     builderHeader.AppendLine($"runtimeclass {className}: Windows.UI.Xaml.Markup.MarkupExtension");
     builderHeader.AppendLine("{");
     builderHeader.AddLevel();
     builderHeader.AppendLine($"{className}();");
     builderHeader.AppendLine("KeyEnum Key;");
     builderHeader.AppendLine("Windows.UI.Xaml.Data.IValueConverter Converter;");
     builderHeader.AppendLine("Object ConverterParameter;");
     builderHeader.AppendLine("overridable Object ProvideValue();");
     builderHeader.RemoveLevel();
     builderHeader.AppendLine("};");
 }
Ejemplo n.º 12
0
 protected override void CreateMarkupExtension(CodeStringBuilder builder, string resourceFileName, string className, IEnumerable <string> keys)
 {
     builder.AppendLine($"[global::System.CodeDom.Compiler.GeneratedCodeAttribute(\"{Constants.ReswPlusName}\", \"{Constants.ReswPlusExtensionVersion}\")]");
     builder.AppendLine("[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]");
     builder.AppendLine("[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]");
     builder.AppendLine("[MarkupExtensionReturnType(ReturnType = typeof(string))]");
     builder.AppendLine($"public class {className}: MarkupExtension");
     builder.AppendLine("{");
     builder.AddLevel();
     builder.AppendLine("public enum KeyEnum");
     builder.AppendLine("{");
     builder.AddLevel();
     builder.AppendLine("__Undefined = 0,");
     foreach (var key in keys)
     {
         builder.AppendLine($"{key},");
     }
     builder.RemoveLevel();
     builder.AppendLine("}");
     builder.AppendEmptyLine();
     builder.AppendLine("private static ResourceLoader _resourceLoader;");
     builder.AppendLine($"static {className}()");
     builder.AppendLine("{");
     builder.AddLevel();
     builder.AppendLine($"_resourceLoader = ResourceLoader.GetForViewIndependentUse(\"{resourceFileName}\");");
     builder.RemoveLevel();
     builder.AppendLine("}");
     builder.AppendLine("public KeyEnum Key { get; set;}");
     builder.AppendLine("public IValueConverter Converter { get; set;}");
     builder.AppendLine("public object ConverterParameter { get; set;}");
     builder.AppendLine("protected override object ProvideValue()");
     builder.AppendLine("{");
     builder.AddLevel();
     builder.AppendLine("string res;");
     builder.AppendLine("if(Key == KeyEnum.__Undefined)");
     builder.AppendLine("{");
     builder.AddLevel();
     builder.AppendLine("res = \"\";");
     builder.RemoveLevel();
     builder.AppendLine("}");
     builder.AppendLine("else");
     builder.AppendLine("{");
     builder.AddLevel();
     builder.AppendLine("res = _resourceLoader.GetString(Key.ToString());");
     builder.RemoveLevel();
     builder.AppendLine("}");
     builder.AppendLine("return Converter == null ? res : Converter.Convert(res, typeof(String), ConverterParameter, null);");
     builder.RemoveLevel();
     builder.AppendLine("}");
     builder.RemoveLevel();
     builder.AppendLine("}");
 }
Ejemplo n.º 13
0
 protected override void CreateMarkupExtension(CodeStringBuilder builder, string resourceFileName, string className, IEnumerable <string> keys)
 {
     builder.AppendLine($"<System.CodeDom.Compiler.GeneratedCodeAttribute(\"{Constants.ReswPlusName}\", \"{Constants.ReswPlusExtensionVersion}\")>");
     builder.AppendLine("<System.Diagnostics.DebuggerNonUserCodeAttribute()>");
     builder.AppendLine("<System.Runtime.CompilerServices.CompilerGeneratedAttribute()>");
     builder.AppendLine("<MarkupExtensionReturnType(ReturnType:=GetType(String))>");
     builder.AppendLine($"Public Class {className}");
     builder.AddLevel();
     builder.AppendLine("Inherits MarkupExtension");
     builder.AppendLine("Public Enum KeyEnum");
     builder.AddLevel();
     builder.AppendLine("__Undefined = 0");
     foreach (var key in keys)
     {
         builder.AppendLine(key);
     }
     builder.RemoveLevel();
     builder.AppendLine("End Enum");
     builder.AppendEmptyLine();
     builder.AppendLine("Private Shared _resourceLoader as ResourceLoader");
     builder.AppendLine("Shared Sub New()");
     builder.AddLevel();
     builder.AppendLine($"_resourceLoader = ResourceLoader.GetForViewIndependentUse(\"{resourceFileName}\")");
     builder.RemoveLevel();
     builder.AppendLine("End Sub");
     builder.AppendEmptyLine();
     builder.AppendLine("Public Property Key As KeyEnum");
     builder.AppendLine("Public Property Converter As IValueConverter");
     builder.AppendLine("Public Property ConverterParameter As Object");
     builder.AppendLine("Protected Overrides Function ProvideValue() As Object");
     builder.AddLevel();
     builder.AppendLine("Dim res As String");
     builder.AppendLine("If Key = KeyEnum.__Undefined Then");
     builder.AddLevel();
     builder.AppendLine("res = \"\"");
     builder.RemoveLevel();
     builder.AppendLine("Else");
     builder.AddLevel();
     builder.AppendLine("res = _resourceLoader.GetString(Key.ToString())");
     builder.RemoveLevel();
     builder.AppendLine("End If");
     builder.AppendLine("Return If(Converter Is Nothing, res, Converter.Convert(res, GetType(String), ConverterParameter, Nothing))");
     builder.RemoveLevel();
     builder.AppendLine("End Function");
     builder.RemoveLevel();
     builder.AppendLine("End Class");
 }
Ejemplo n.º 14
0
        protected override void CreateFormatMethod(CodeStringBuilder builder, string key, bool isProperty, IEnumerable <IFormatTagParameter> parameters, string summary = null, IEnumerable <FunctionFormatTagParameter> extraParameters = null, FunctionFormatTagParameter parameterForPluralization = null, bool supportNoneState = false, FunctionFormatTagParameter parameterForVariant = null)
        {
            builder.AppendLine("/// <summary>");
            builder.AppendLine($"///   {summary}");
            builder.AppendLine("/// </summary>");

            if (isProperty)
            {
                builder.AppendLine($"public static string {key}");
                builder.AppendLine("{");
                builder.AddLevel();
                builder.AppendLine("get");
            }
            else
            {
                var functionParameters = parameters != null?parameters.OfType <FunctionFormatTagParameter>().ToList() :
                                             new List <FunctionFormatTagParameter>();

                if (extraParameters != null && extraParameters.Any())
                {
                    functionParameters.InsertRange(0, extraParameters);
                }

                if (parameters.Any(p => p is FunctionFormatTagParameter functionParam && functionParam.IsVariantId) || extraParameters.Any(p => p.IsVariantId))
                {
                    // one of the parameter is a variantId, we must create a second method with object as the variantId type.
                    var genericParametersStr = functionParameters.Select(p => (p.IsVariantId ? "object" : GetParameterTypeString(p.Type)) + " " + p.Name).Aggregate((a, b) => a + ", " + b);
                    builder.AppendLine($"public static string {key}({genericParametersStr})");
                    builder.AppendLine("{");
                    builder.AddLevel();
                    builder.AppendLine("try");
                    builder.AppendLine("{");
                    builder.AddLevel();
                    builder.AppendLine($"return {key}({functionParameters.Select(p => p.IsVariantId ? $"Convert.ToInt64({p.Name})" : p.Name).Aggregate((a, b) => a + ", " + b)});");
                    builder.RemoveLevel();
                    builder.AppendLine("}");
                    builder.AppendLine("catch");
                    builder.AppendLine("{");
                    builder.AddLevel();
                    builder.AppendLine("return \"\";");
                    builder.RemoveLevel();
                    builder.AppendLine("}");
                    builder.RemoveLevel();
                    builder.AppendLine("}");
                    builder.AppendEmptyLine();
                    builder.AppendLine("/// <summary>");
                    builder.AppendLine($"///   {summary}");
                    builder.AppendLine("/// </summary>");
                }

                var parametersStr = functionParameters.Select(p => GetParameterTypeString(p.Type) + " " + p.Name).Aggregate((a, b) => a + ", " + b);
                builder.AppendLine($"public static string {key}({parametersStr})");
            }
            builder.AppendLine("{");
            builder.AddLevel();

            string keyToUseStr = $"\"{key}\"";

            if (parameterForVariant != null)
            {
                keyToUseStr = $"\"{key}_Variant\" + {parameterForVariant.Name}";
            }

            string localizationStr;

            if (parameterForPluralization != null)
            {
                var pluralNumber = parameterForPluralization.TypeToCast.HasValue ? $"({GetParameterTypeString(parameterForPluralization.TypeToCast.Value)}){parameterForPluralization.Name}" : parameterForPluralization.Name;

                var supportNoneStateStr = supportNoneState ? "true" : "false";
                localizationStr = $"ReswPlusLib.ResourceLoaderExtension.GetPlural(_resourceLoader, {keyToUseStr}, {pluralNumber}, {supportNoneStateStr})";
            }
            else
            {
                localizationStr = $"_resourceLoader.GetString({keyToUseStr})";
            }

            if (parameters != null && parameters.Any())
            {
                var formatParameters = parameters.Select(p =>
                {
                    switch (p)
                    {
                    case FunctionFormatTagParameter functionParam:
                        return(functionParam.Name);

                    case MacroFormatTagParameter macroParam:
                        return($"ReswPlusLib.Macros.{macroParam.Id}");

                    case LiteralStringFormatTagParameter constStringParameter:
                        return($"\"{constStringParameter.Value}\"");

                    case StringRefFormatTagParameter localizationStringParameter:
                        return(localizationStringParameter.Id);

                    default:
                        //should not happen
                        return("");
                    }
                }).Aggregate((a, b) => a + ", " + b);
                builder.AppendLine($"return string.Format({localizationStr}, {formatParameters});");
            }
            else
            {
                builder.AppendLine($"return {localizationStr};");
            }

            if (isProperty)
            {
                builder.RemoveLevel();
                builder.AppendLine("}");
            }
            builder.RemoveLevel();
            builder.AppendLine("}");
        }
Ejemplo n.º 15
0
        protected override void CppCreateFormatMethod(CodeStringBuilder builderCpp, string computedNamespace, string key, bool isProperty, bool isDotNetFormatting, IEnumerable <IFormatTagParameter> parameters, IEnumerable <FunctionFormatTagParameter> extraParameters = null, FunctionFormatTagParameter parameterForPluralization = null, bool supportNoneState = false, FunctionFormatTagParameter parameterForVariant = null)
        {
            if (isProperty)
            {
                builderCpp.AppendLine($"String^ {computedNamespace}{key}::get()");
            }
            else
            {
                var functionParameters = parameters != null?parameters.OfType <FunctionFormatTagParameter>().ToList() :
                                             new List <FunctionFormatTagParameter>();

                if (extraParameters != null && extraParameters.Any())
                {
                    functionParameters.InsertRange(0, extraParameters);
                }

                var parametersStr = functionParameters.Any() ?
                                    functionParameters.Select(p => GetParameterTypeString(p.Type, false) + " " + p.Name).Aggregate((a, b) => a + ", " + b)
                : "";

                builderCpp.AppendLine($"String^ {computedNamespace}{key}({parametersStr})");
            }

            builderCpp.AppendLine("{");
            builderCpp.AddLevel();

            string keyToUseStr = parameterForVariant != null ? $"ref new String(L\"{key}_Variant\") + {parameterForVariant.Name}" : $"L\"{key}\"";

            string localizationStr;

            if (parameterForPluralization != null)
            {
                var pluralNumber = parameterForPluralization.TypeToCast.HasValue ? $"static_cast<{GetParameterTypeString(parameterForPluralization.TypeToCast.Value, false)}>({parameterForPluralization.Name})" : parameterForPluralization.Name;

                var supportNoneStateStr = supportNoneState ? "true" : "false";

                localizationStr = $"ReswPlusLib::ResourceLoaderExtension::GetPlural(GetResourceLoader(), {keyToUseStr}, {pluralNumber}, {supportNoneStateStr})";
            }
            else
            {
                localizationStr = $"GetResourceLoader()->GetString({keyToUseStr})";
            }

            if (parameters != null && parameters.Any())
            {
                var formatParameters = parameters
                                       .Select(p =>
                {
                    switch (p)
                    {
                    case LiteralStringFormatTagParameter constStringParam:
                        {
                            return(isDotNetFormatting ? $"ref new String(L\"{constStringParam.Value}\")" : $"L\"{constStringParam.Value}\"");
                        }

                    case MacroFormatTagParameter macroParam:
                        {
                            return(isDotNetFormatting ? $"ReswPlusLib::Macros::{macroParam.Id}" : $"ReswPlusLib::Macros::{macroParam.Id}->Data()");
                        }

                    case StringRefFormatTagParameter localizationStringParameter:
                        {
                            return(isDotNetFormatting ? $"{localizationStringParameter.Id}" : $"{localizationStringParameter.Id}->Data()");
                        }

                    case FunctionFormatTagParameter functionParam:
                        {
                            switch (functionParam.Type)
                            {
                            case ParameterType.String:
                                return(isDotNetFormatting ? functionParam.Name : functionParam.Name + "->Data()");

                            case ParameterType.Object:
                                return(isDotNetFormatting ? functionParam.Name + "->ToString()" : functionParam.Name + "->ToString()->Data()");

                            default:
                                return(functionParam.Name);
                            }
                        }

                    default:
                        //should not happen
                        return("");
                    }
                }).Aggregate((a, b) => a + ", " + b);

                if (isDotNetFormatting)
                {
                    builderCpp.AppendLine($"return ReswPlusLib::StringFormatting::FormatDotNet({localizationStr}, ref new Array<Object^>({parameters.Count()}){{{formatParameters}}});");
                }
                else
                {
                    builderCpp.AppendLine($"size_t needed = _swprintf_p(nullptr, 0, {localizationStr}->Data(), {formatParameters});");
                    builderCpp.AppendLine($"wchar_t *buffer = new wchar_t[needed + 1];");
                    builderCpp.AppendLine($"_swprintf_p(buffer, needed + 1, {localizationStr}->Data(), {formatParameters});");
                    builderCpp.AppendLine($"return ref new String(buffer);");
                }
            }
            else
            {
                builderCpp.AppendLine($"return {localizationStr};");
            }
            builderCpp.RemoveLevel();
            builderCpp.AppendLine("}");
        }
Ejemplo n.º 16
0
 protected override void CloseStronglyTypedClass(CodeStringBuilder builder)
 {
     builder.RemoveLevel();
     builder.AppendLine("}");
 }
Ejemplo n.º 17
0
 private void IdlCloseStronglyTypedClass(CodeStringBuilder builderHeader)
 {
     builderHeader.RemoveLevel();
     builderHeader.AppendLine("};");
 }
Ejemplo n.º 18
0
        protected override void CppCreateMarkupExtension(CodeStringBuilder builderCpp, string computedNamespace, string resourceFileName, string className, IEnumerable <string> keys)
        {
            builderCpp.AppendLine($"{computedNamespace}{className}()");
            builderCpp.AppendLine("{");
            builderCpp.AddLevel();
            builderCpp.AppendLine($"_resourceLoader = ResourceLoader::GetForViewIndependentUse(L\"{resourceFileName}\");");
            builderCpp.RemoveLevel();
            builderCpp.AppendLine("}");
            builderCpp.AppendEmptyLine();
            builderCpp.AppendLine($"IInspectable {computedNamespace}ProvideValue()");
            builderCpp.AppendLine("{");
            builderCpp.AddLevel();
            builderCpp.AppendLine("hstring res;");
            builderCpp.AppendLine("if(Key() == KeyEnum::__Undefined)");
            builderCpp.AppendLine("{");
            builderCpp.AddLevel();
            builderCpp.AppendLine("res = L\"\";");
            builderCpp.RemoveLevel();
            builderCpp.AppendLine("}");
            builderCpp.AppendLine("else");
            builderCpp.AppendLine("{");
            builderCpp.AddLevel();

            builderCpp.AppendLine("auto keyStr = KeyEnumToString(Key());");
            builderCpp.AppendLine("if(keyStr == L\"\")");
            builderCpp.AppendLine("{");
            builderCpp.AddLevel();
            builderCpp.AppendLine("return box_value(L\"\");");
            builderCpp.RemoveLevel();
            builderCpp.AppendLine("}");
            builderCpp.AppendLine("res = _resourceLoader.GetString(keyStr);");
            builderCpp.RemoveLevel();
            builderCpp.AppendLine("}");
            builderCpp.AppendLine("return Converter() == nullptr ? box_value(res) : Converter().Convert(box_value(res), xaml_typename<hstring>(), ConverterParameter(), L\"\");");
            builderCpp.RemoveLevel();
            builderCpp.AppendLine("}");

            builderCpp.AppendEmptyLine();

            builderCpp.AppendLine($"hstring {computedNamespace}KeyEnumToString(KeyEnum key)");
            builderCpp.AppendLine("{");
            builderCpp.AddLevel();
            builderCpp.AppendLine("switch(key)");
            builderCpp.AppendLine("{");
            builderCpp.AddLevel();
            foreach (var key in keys)
            {
                builderCpp.AppendLine($"case KeyEnum::{key}:");
                builderCpp.AddLevel();
                builderCpp.AppendLine($"return hstring(L\"{key}\");");
                builderCpp.RemoveLevel();
            }
            builderCpp.AppendLine("default:");
            builderCpp.AddLevel();
            builderCpp.AppendLine("return hstring(L\"\");");
            builderCpp.RemoveLevel();
            builderCpp.RemoveLevel();
            builderCpp.AppendLine("}");
            builderCpp.RemoveLevel();
            builderCpp.AppendLine("}");
        }