publish-cs

Introduction

Generates C# classes for all Item types and Composite types in the model. The generated classes can be serialized to JSON, populated from JSON, and serialized to XML.

Requires that dotnet is installed.

Command Line Arguments

Required inputs for the publish-cs command (must be specified in order).

  • [CogsLocation]

    The location of the folder containing the model.

  • [TargetLocation]

    The location of the folder where the output will be created.

Command Line Flags

Optional inputs for the publish-cs command.

  • -?|-h|--help

    Displays all possible command arguments and flags for the publish-cs command.

  • -o|--overwrite

    If the [TargetLocation] is not empty, erase all files in the folder before generation.

  • -n|--namespace

    Allows the user to specify the XMI of desired XML namespace used in XML creation from generated C# classes.

  • -p|--prefix

    Allows the user to specify the prefix for XML namespace used in XML creation from generated C# classes.

Command Line Usage

Format

$ publish-cs (-h) (-o) (-n [namespace]) (-p [prefix]) [CogsLocation] [TargetLocation]

Examples

A few examples of how the command line arguments and flags can be used together.

$ publish-cs -h
$ publish-cs MyCogsModelDirectory MyOutputDirectory
$ publish-cs -o MyCogsModelDirectory MyOutputDirectory
$ publish-cs -n http://example.org/cogs -p cogs -o MyCogsModelDirectory MyOutputDirectory

Primitive Type Mappings to C#

Primitive Type C# representation
AnyURI Uri
Boolean bool
CogsDate Custom CogsDate class
Date DateTimeOffset
DateTime DateTimeOffset
Decimal decimal
Double double
Duration TimeSpan
Float float
GDay Custom GDay class
GMonth Custom GMonth class
GMonthDay Custom GMonthDay class
GYear Custom GYear class
GYearMonth Custom GYearMonth class
Integer int
Integer int
Language String
Long long
NegativeInteger int
NonNegativeInteger int
NonPositiveInteger int
PositiveInteger int
String String
Time DateTimeOffset
UnsignedLong ulong

Custom Primitive Types in C#

CogsDate
  • Constructors:
    • public CogsDate(DateTimeOffset item, bool isDate = false)
      Initializes the Cogsdate to either the Date or DateTime of the DateTimeOffset provided based on bool argument.
    • public CogsDate(GYearMonth item)
      Initializes the Cogsdate to the GYearMonth value provided.
    • public CogsDate(GYear item)
      Initializes the Cogsdate to the GYear value provided.
    • public CogsDate(TimeSpan item)
      Initializes the Cogsdate to the Duration value provided.
  • public string GetUsedType()
    Returns which type is being used (“date”, “datetime”, “yearMonth”, “year” or “duration”).
  • ToString()
    Returns a string representation of the CogsDate. Used for XML serialization.
  • public object GetValue()
    Returns the value of the CogsDate. The result can be a string, long, JObject, or null depending on the CogsDate value. Used for Json serialization.
GDay
  • Constructors:
    • public GYear(int day)
      Initializes the day value (timezone still null).
    • public GYear(int day, string zone)
      Initializes the day and timezone values.
  • ToString()
    Returns a string representation of the GDay. Timezone is only included if it has been initialized.
  • public JObject ToJson()
    Returns a JObject representation of the GDay. Timezone is only included if it has been initialized.
  • public int CompareTo(object obj)
    Implements IComparable to allow GDay comparisons.
GMonth
  • Constructors:
    • public GYear(int month)
      Initializes the month value (timezone still null).
    • public GYear(int month, string zone)
      Initializes the month and timezone values.
  • ToString()
    Returns a string representation of the GMonth. Timezone is only included if it has been initialized.
  • public JObject ToJson()
    Returns a JObject representation of the GMonth. Timezone is only included if it has been initialized.
  • public int CompareTo(object obj)
    Implements IComparable to allow GMonth comparisons.
GMonthDay
  • Constructors:
    • public GMonthDay(int month, int day)
      Initializes the month and day values (timezone still null).
    • public GMonthDay(int month, int day, string zone)
      Initializes the month, day and timezone values.
  • ToString()
    Returns a string representation of the GMonthDay. Timezone is only included if it has been initialized.
  • public JObject ToJson()
    Returns a JObject representation of the GMonthDay. Timezone is only included if it has been initialized.
  • public int CompareTo(object obj)
    Implements IComparable to allow GMonthDay comparisons.
GYear
  • Constructors:
    • public GYear(int year)
      Initializes the year value (timezone still null).
    • public GYear(int year, string zone)
      Initializes the year and timezone values.
  • ToString()
    Returns a string representation of the GYear. Timezone is only included if it has been initialized.
  • public JObject ToJson()
    Returns a JObject representation of the GYear. Timezone is only included if it has been initialized.
  • public int CompareTo(object obj)
    Implements IComparable to allow GYear comparisons.
GYearMonth
  • Constructors:
    • public GYearMonth(int year, int month)
      Initializes the year and month values (timezone still null).
    • public GYearMonth(int year, int month, string zone)
      Initializes the year, month and timezone values.
  • ToString()
    Returns a string representation of the GYearMonth. Timezone is only included if it has been initialized.
  • public JObject ToJson()
    Returns a JObject representation of the GYearMonth. Timezone is only included if it has been initialized.
  • public int CompareTo(object obj)
    Implements IComparable to allow GYearMonth comparisons.