Skip to content

Configuration attributes

Pavel Novikov edited this page Jan 8, 2019 · 15 revisions

All attributes are located under Reinforced.Typings.Attributes namespace and has good XMLDOC. Feel free to use it. All atributes are inheritance-friendly and contains overrideable properties. Here is full list with descriptions and purposes. In table below "Required" means that if you wont place mentioned attribute above member then it will NOT be exported.

Table of contents

TsGlobal (not required)

Result in .ts: No result, configures global settings

Applicable to: assembly

[assembly:TsGlobal] is introduced in version 1.3.0. It simply replaces some configuration settings that were previously located in [Reinforced.Typings.settings.xml|Reinforced.Typings.settings.xml]].

Properties:

Property name Type Default Description
WriteWarningComment bool true Boolean parameter that controls writing of "auto-generated warning" comment to each generated file. It meant the comment like // This code was generated blah blah blah.... 'true' (default) to write warning comment about auto-generated to every file. false to do not.
RootNamespace string empty Specifies your app's root namespace. Useful in case of using RtDivideTypesAmongFiles. It is needed to make Reinforced.Typings do not create redundant directories under RtTargetDirectory since there is no way to determine root namespace programmatically.
CamelCaseForMethods bool false When true, forces Reinforced.Typings to generate METHODS names in "camelCase" instead of .NET-common "PascalCase"
CamelCaseForProperties bool false When true, forces Reinforced.Typings to generate PROPERTIES names in "camelCase" instead of .NET-common "PascalCase"
GenerateDocumentation bool false This setting controls JSDOC generation for your exported TypeScript from .NET XMLDOC. Check out how to use JSDOC generation here
TabSymbol string '\t' Specifies symbol used for tabulation. By default tabulation symbol - '\t' is used.
UseModules bool false Switches RT to using TS modules system (--module tsc.exe parameter) with types exports/imports. import directives will not appear in your export results until you swith this parameter to true
DiscardNamespacesWhenUsingModules bool false When true, RT will totally ignore all namespaces when exporting. This parameter does not work without UseModules parameter
ExportPureTypings bool false Since .d.ts has a slightly different syntax than a regular .ts file, RT has that boolean parameter that controls generation mode switch between .ts/.d.ts. If this option set to true, then export will be performed in .d.ts manner (only typings, declare module etc). Otherwise, export will be performed in manner of regular .ts file
Priority double 0 Sets priority of [TsGlobal] attribute. It makes sense when you have many assemblies with many [TsGlobal] attributes. Then, the one with highest priority will be used
ReferenceProcessorType Type null You can specify implementation of reference processor here (any class, derived from Reinforced.Typings.ReferencesInspection.ReferenceProcessorBase) to take full control of references/imports within generated files
ReorderMembers bool false Gets or sets whether class/interface members reordering (aphabetical, constructors-fields-properties-methods) is enabled. Warning! Enabling this option discards .Order fluent calls as well as "Order" member attributes property
AutoOptionalProperties bool false Tells RT to turn all class/interface nullable properties into TypeScript optional (e.g. prop? :boolean) ones

Back to TOC

TsInterface (required)

Result in .ts: TypeScript interface

Applicable to: C# class, C# interface, C# struct

Properties:

Property name Type Default Description
AutoI bool true Controls automatical placement on I letter before interface name (e.g. if true then MyClass in C# will be translated to IMyClass in TypeScript and left unchanged in case of false)
AutoExportMethods bool true Controls automatic export of all interface/class methods. If false then you will have to manually arrange [TsFunction] above methods being exported
AutoExportProperties bool true Similar to AutoExportMethods but for properties
IncludeNamespace bool true If true then exported member will be placed to corresponding module. Otherwise will be left in root namespace
Name string null Overrides name
Namespace string null Overrides namespace (module)
Order double 0 Defines order this interface will be exported in. Greater order means that interface will be placed placed lower in resulting file
FlattenHierarchy bool false Tells RT to "flatten" class/interface hierarchy. All methods/properties from base classes will be brought to TS interface itself, extends clause will be eliminated
FlattenLimiter Type typeof(object) Limits flattering by disallowing to export members "lower" than flatten limiter class
Back to TOC

TsClass (required)

Result in .ts: TypeScript class

Applicable to: C# class, C# struct

Properties:

Property name Type Default Description
AutoExportMethods bool true Controls automatic export of all interface/class methods. If false then you will have to manually arrange [TsFunction] above methods being exported
AutoExportProperties bool true Similar to AutoExportMethods but for properties
AutoExportFields bool true Similar to AutoExportProperties but for fields
AutoExportConstructors bool false Enables automatic export of class constructor
IncludeNamespace bool true If true then exported member will be placed to corresponding module. Otherwise will be left in root namespace
Name string null Overrides name
Namespace string null Overrides namespace (module)
DefaultMethodCodeGenerator Type null Specifies code generator for each class method (see Code generation part for details)
Order double 0 Defines order this class will be exported in. Greater order means that class will be placed lower in resulting file
FlattenHierarchy bool false Tells RT to "flatten" class/interface hierarchy. All methods/properties from base classes will be brought to TS interface itself, extends clause will be eliminated
FlattenLimiter Type typeof(object) Limits flattering by disallowing to export members "lower" than flatten limiter class
Back to TOC

TsProperty (not required)

Result in .ts: TypeScript interface/class field

Applicable to: C# class/struct/interface property or field

Properties:

Property name Type Default Description
Type string null Overrides member typename in resulting TypeScript. Helpful when property type is not present in your project. E.g. - JQquery object.
StrongType Type null Similar to Type, but you can specify .NET type using typeof. It is useful e.g. for delegates.
Name string null Overrides name
ForceNullable bool false Forces property to be nullable. E.g. field:boolean becomes field?:boolean when you specify [TsProperty(ForceNullable = true)] in attribute configuration
ShouldBeCamelCased bool false When true then member name will be automatically converted to camelCase
Order double 0 Defines order this class member will be exported in. Greater order means that member will be placed lower in resulting file
Back to TOC

TsFunction (not required)

Result in .ts: TypeScript interface/class function (in case of class method body will be exported as return null; if method is non-void. Otherwise empty body will be exported)

Applicable to: C# class/structure method (warning! access modified will be persisted!)

Properties:

Property name Type Default Description
Type string null Overrides member typename in resulting TypeScript. Helpful when property type is not present in your project. E.g. - JQquery object.
StrongType Type null Similar to Type, but you can specify .NET type using typeof. It is useful e.g. for delegates.
Name string null Overrides name
ShouldBeCamelCased bool false When true then member name will be automatically converted to camelCase
Order double 0 Defines order this class member will be exported in. Greater order means that member will be placed lower in resulting file
Implementation string empty Inline function code to be converted to RtRaw and used as function body

Back to TOC

TsEnum (required)

Result in .ts: TypeScript enumeration

Applicable to: C# enumeration

Properties:

Property name Type Default Description
IncludeNamespace bool true If true then exported member will be placed to corresponding module. Otherwise will be left in root namespace
Name string null Overrides name
Namespace string null Overrides interface namespace (module)
IsConst boolean false Produces const enum (TS 2.4.2) instead of regular one
Order double 0 Defines order this enum will be exported in. Greater order - enum is placed lower in target file
UseString boolean false Gets or sets whetner enum fields must be exported with string initializers (TypeScript 2.4)

Back to TOC

TsValue (not required)

Result in .ts: TypeScript enumeration value

Applicable to: C# enumeration value

Properties:

Property name Type Default Description
Name string null Overrides name
Initializer string null Overrides enum value's string initializer. Works only usage of string initializers either with [TsEnum] attribute or fluent configuration. Please escape quotes manually.

Back to TOC

TsParameter (not required)

Result in .ts: TypeScript function parameter

Applicable to: C# method parameter

Properties:

Property name Type Default Description
Type string null Overrides member typename in resulting TypeScript. Helpful when property type is not present in your project. E.g. - JQquery object.
StrongType Type null Similar to Type, but you can specify .NET type using typeof. It is useful e.g. for delegates.
Name string null Overrides name
DefaultValue string null Specifies defaul parameter value. Helps to turn f(arg:boolean) to f(arg:boolean = false)
ShouldBeCamelCased bool false When true then member name will be automatically converted to camelCase
Back to TOC

TsGeneric (not required)

Result in .ts: TypeScript function/class generic parameter

Applicable to: C# method/class generic parameter

Properties:

Property name Type Default Description
Type string null Overrides generic parameter typename in resulting TypeScript. Helpful when property type is not present in your project. E.g. - JQquery object.
StrongType Type null Similar to Type, but you can specify .NET type using typeof. It is useful e.g. for delegates.
Back to TOC

TsBaseParam (partially required)

Result in .ts: super(...) call

Applicable to: C# class constructor

RT can export classes including constructors. In case of inherited classes and explicit calling of base constructor using :base(...) there is no way to retrieve information about base call using reflection. To handle those cases correctly RT has [TsBaseParam] attribute. It defines single constructor and it consumes array of strings representing raw TypeScript expressions. They will be used during export and substituted to super(...) call in order they follows.

In case of no inheritance you can enable AutoExportConstructors within [TsClass]. Constructors will be exported correctly with empty bodies. So there are no more special attributes for constructors.

Properties:

Property name Type Default Description
Values string[] null Array of strings representing TypeScript expressions. They will be used for super(...) call generation in case of TypeScript class exporting
Back to TOC

TsIgnore (not required)

Result in .ts: member will not be exported

Applicable to: anything

This attribute has no properties

Back to TOC

TsAddTypeImport / TsImport (not required)

Result in .ts: import ... directive

Applicable to: class, interface

This attribute only makes sense in case of Export to multiple files

Property name Type Default Description
ImportTarget string null What is being imported from module. Literally, everything that is placed after import keyword and before from or = require(..). If ImportTarget is null then side-effect import will be generated.
ImportSource string null Import source is everything that follows after from keyword. Please note that you do not have to specify quotes here! Quotes will be added automatically
ImportRequire bool null When true, require-import will be generated like: import %ImportTarget% = require('%ImportSource%')

Examples of ImportTarget parameter:

  • import * as shape from './Shapes' -> * as shape is target
  • import { Foo } from 'Bar' -> { Foo } is target
  • import { Bar2 as bar } from 'Baz' -> { Bar2 as bar } is target

[TsImport] results import directive in each exported files when exporting to multiple files. It does exactly the same as [TsAddTypeImport] but for whole assembly. [TsImport] attribute should be used like [assembly:TsImport("* as '$'","JQuery")] at any place.

This attribute will not take effect until TsGlobal.UseModules will be set to true.

Back to TOC

TsAddTypeReference / TsReference (not required)

Result in .ts: ///<reference ...> directive

Applicable to: class, interface

This attribute only makes sense in case of Export to multiple files

Property name Type Default Description
RawPath string null Path to file that will be written in ///<reference path="..."> directive that will be placed on top of file containing current class
Type Type null Path to file that contains specified type that will be written in ///<reference path="..."> directive that will be placed on top of file containing current class

[TsReference] results import directive in each exported files when exporting to multiple files. It does exactly the same as [TsAddTypeReference] but for whole assembly. [TsReference] attribute should be used like [assembly:TsReference("path_to_file.d.ts")] at any place.

Please note that AddReference will not stop work even if you are using modules export

Back to TOC

TsFile (not required)

Result in .ts: none

Applicable to: class

This attribute only makes sense in case of Export to multiple files

Property name Type Default Description
FileName string null Path to file where to put generated code for current class

Back to TOC

TsDecorator (not required)

Result in .ts: TypeScript decorator

Applicable to: class, enum, method, property, parameter

Property name Type Default Description
Decorator string null Decorator text - everything that must follow after @. E.g. if you want to produce @apicall() decorator on your method then add [TsDecorator("apicall()")] on it. @ will be added automatically because RT must have something to do
Order double 0 Specifies decorator order. Ther greater order is - the "righter" decorator will appear

Back to TOC

TsThirdParty (not required)

Result in .ts: every time you are using type marked with [TsThirdParty] - RT will produce its full qualified name, but will not generate its code. It is useful to make C# dummies for some types from third-party libraries using this attribute. By using [TsThirdPartyImport] / [TsThirdPartyReference] you can specify set of imports and references that will be added to every file where mentioned third-party type is used. The syntax of [TsThirdPartyImport] / [TsThirdPartyReference] is same as for [TsAddTypeImport] / [TsAddTypeReference] attributes. Also works on generic types (generics will be correctly substituted)

Applicable to: C# enumeration / class / interface

Properties:

Property name Type Default Description
Name string null Full quialified name of third party type to avoid dealing with namespaces, I letters etc

Back to TOC

You can’t perform that action at this time.