Browse Source

Refactor CLITypePrinter.cs to use string interpolation.

pull/1300/head
João Matos 6 years ago committed by João Matos
parent
commit
c88ddcc60d
  1. 27
      src/Generator/Generators/CLI/CLITypePrinter.cs

27
src/Generator/Generators/CLI/CLITypePrinter.cs

@ -30,7 +30,6 @@ namespace CppSharp.Generators.CLI
} }
Declaration decl = tag.Declaration; Declaration decl = tag.Declaration;
if (decl == null) if (decl == null)
return string.Empty; return string.Empty;
@ -46,7 +45,7 @@ namespace CppSharp.Generators.CLI
array.QualifiedType.Qualifiers.IsConst) array.QualifiedType.Qualifiers.IsConst)
return "System::String^"; return "System::String^";
return string.Format("cli::array<{0}>^", array.Type.Visit(this)); return $"cli::array<{array.Type.Visit(this)}>^";
} }
public override TypePrinterResult VisitFunctionType(FunctionType function, public override TypePrinterResult VisitFunctionType(FunctionType function,
@ -62,14 +61,14 @@ namespace CppSharp.Generators.CLI
if (returnType.Type.IsPrimitiveType(PrimitiveType.Void)) if (returnType.Type.IsPrimitiveType(PrimitiveType.Void))
{ {
if (!string.IsNullOrEmpty(args)) if (!string.IsNullOrEmpty(args))
args = string.Format("<{0}>", args); args = $"<{args}>";
return string.Format("System::Action{0}", args); return $"System::Action{args}";
} }
if (!string.IsNullOrEmpty(args)) if (!string.IsNullOrEmpty(args))
args = string.Format(", {0}", args); args = $", {args}";
return string.Format("System::Func<{0}{1}>", returnType.Visit(this), args); return $"System::Func<{returnType.Visit(this)}{args}>";
} }
public override TypePrinterResult VisitParameter(Parameter param, public override TypePrinterResult VisitParameter(Parameter param,
@ -125,7 +124,7 @@ namespace CppSharp.Generators.CLI
if (pointee is FunctionType) if (pointee is FunctionType)
{ {
var function = pointee as FunctionType; var function = pointee as FunctionType;
return string.Format("{0}^", function.Visit(this, quals)); return $"{function.Visit(this, quals)}^";
} }
// From http://msdn.microsoft.com/en-us/library/y31yhkeb.aspx // From http://msdn.microsoft.com/en-us/library/y31yhkeb.aspx
@ -157,9 +156,9 @@ namespace CppSharp.Generators.CLI
// Skip one indirection if passed by reference // Skip one indirection if passed by reference
if (Parameter != null && (Parameter.IsOut || Parameter.IsInOut) if (Parameter != null && (Parameter.IsOut || Parameter.IsInOut)
&& pointee == finalPointee) && pointee == finalPointee)
return string.Format("{0}", typeName); return typeName;
return string.Format("{0}*", typeName); return $"{typeName}*";
} }
return pointer.QualifiedPointee.Visit(this); return pointer.QualifiedPointee.Visit(this);
@ -218,7 +217,7 @@ namespace CppSharp.Generators.CLI
if (decl.Type.IsPointerTo(out func)) if (decl.Type.IsPointerTo(out func))
{ {
// TODO: Use SafeIdentifier() // TODO: Use SafeIdentifier()
return string.Format("{0}^", VisitDeclaration(decl)); return $"{VisitDeclaration(decl)}^";
} }
return decl.Type.Visit(this); return decl.Type.Visit(this);
@ -285,6 +284,7 @@ namespace CppSharp.Generators.CLI
{ {
if (unaryTransformType.Desugared.Type != null) if (unaryTransformType.Desugared.Type != null)
return unaryTransformType.Desugared.Visit(this); return unaryTransformType.Desugared.Visit(this);
return unaryTransformType.BaseType.Visit(this); return unaryTransformType.BaseType.Visit(this);
} }
@ -293,6 +293,7 @@ namespace CppSharp.Generators.CLI
var result = type.Type.FullName.Replace(".", "::"); var result = type.Type.FullName.Replace(".", "::");
if (!type.Type.IsValueType) if (!type.Type.IsValueType)
result += "^"; result += "^";
return result; return result;
} }
@ -331,8 +332,7 @@ namespace CppSharp.Generators.CLI
if (@class.CompleteDeclaration != null) if (@class.CompleteDeclaration != null)
return VisitClassDecl(@class.CompleteDeclaration as Class); return VisitClassDecl(@class.CompleteDeclaration as Class);
return string.Format("{0}{1}", @class.Name, @class.IsRefType ? "^" return $"{@class.Name}{(@class.IsRefType ? "^" : string.Empty)}";
: string.Empty);
} }
public override TypePrinterResult VisitTypedefDecl(TypedefDecl typedef) public override TypePrinterResult VisitTypedefDecl(TypedefDecl typedef)
@ -352,8 +352,7 @@ namespace CppSharp.Generators.CLI
public override TypePrinterResult VisitEnumItemDecl(Enumeration.Item item) public override TypePrinterResult VisitEnumItemDecl(Enumeration.Item item)
{ {
return string.Format("{0}::{1}", return $"{VisitEnumDecl((Enumeration)item.Namespace)}::{VisitDeclaration(item)}";
VisitEnumDecl((Enumeration) item.Namespace), VisitDeclaration(item));
} }
public override string ToString(Type type) public override string ToString(Type type)

Loading…
Cancel
Save