Synchronize Constants across Different Languages

Below are several different language files that all contain a definition of the same constants. SyncBlock gives you a single source to unify these different languages to ensure they are always synchronized.

Here Are Just a Few Examples

JavaScript

export default class consts {
//<syncblock id="My.Constants" version="JavaScript">
static UriScheme = 'http';
static UriHost = 'localhost';
static UriPort = 3000;
static UriPath = '/';
static Uri = `${this.UriScheme}://${this.UriHost}:${this.UriPort}${this.UriPath}`;

static MessageId = 'app.message';
//</syncblock>
}

C-Sharp

namespace dotnet_app
{
class Consts
{
//<syncblock id="My.Constants" version="CSharp">
public static string UriScheme = "http";
public static string UriHost = "localhost";
public static int UriPort = 3000;
public static string UriPath = "/";
public static string Uri = UriScheme + "://" + UriHost + ":" + UriPort.ToString() + UriPath;

public static string MessageId = "app.message";
//</syncblock>
}
}

Xml

<XmlData>
<Consts>
<!--<syncblock id="My.Constants" version="Xml">-->
<Value Name="UriScheme">http</Value>
<Value Name="UriHost">localhost</Value>
<Value Name="UriPort">3000</Value>
<Value Name="UriPath">/</Value>
<Value Name="Uri">http://localhost:3000/</Value>
<Value Name="MessageId">app.message</Value>
<!--</syncblock>-->
</Consts>
</XmlData>

Delphi

unit Consts;

interface

//<syncblock id="My.Constants" version="Delphi.Top">
type
TConsts = record
strict private
function GetUri: string;
public
UriScheme: string;
UriHost: string;
UriPort: integer;
UriPath: string;
MessageId: string;
property Uri: string read GetUri;
end;

var
Consts: TConsts = (
UriScheme: 'http';
UriHost: 'localhost';
UriPort: 3000;
UriPath: '/';
MessageId: 'app.message';
);
//</syncblock>

implementation

uses
System.SysUtils;

//<syncblock id="My.Constants" version="Delphi.Bottom">
function TConsts.GetUri: string;
begin
Result := Format('%s://%s:%d%s', [UriScheme, UriHost, UriPort, UriPath]);
end;
//</syncblock>

end.

And Many, Many More…

SyncBlock supports just about any language or file format that can have comments, including:

  • PowerShell
  • TypeScript
  • C++
  • Go
  • Ruby
  • YAML
  • Text Files
  • Bash Scripts
  • Batch Files

© 2024 OCERIS, Inc. All rights reserved.