Giter Club home page Giter Club logo

reinforced.typings's People

Contributors

daveskender avatar dougquidd avatar frederic-cb avatar gajaiswa avatar greg-smulko avatar jannikbuschke avatar johncampionjr avatar kfrancis avatar luhis avatar lukedukeus avatar mpawelski avatar nohwnd avatar nros avatar otto-gebb avatar pandawood avatar pavel-b-novikov avatar radiosterne avatar romansp avatar ruler501 avatar santhoshramachandran avatar smkanadl avatar tobiasfrick avatar viktor-svub avatar vzarytovskii avatar zivillian avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

reinforced.typings's Issues

Inheritance issues

I find that using the Fluent api, my classes being exported to interfaces do not maintain their inheritance chain. I have also not yet found any way to configure it to work. Is it possible i am missing something, or is the feature not implemented?

DateTime? not supported?

I'm trying to generate typescript with Reinforced.Typings and I have a problem with DateTime? type. In build output I have an info that Type resolution failed with code RT0003. I could use builder.Substitute for choose type manually but I think that this type should be resolved automaticly?

Filtering methods

Hi guys,

Is there any way to generate methods, which name doesn't starts with "Begin" or "End" phrase?

Pseudocode:

.ExportAsInterfaces(proxyInterfaces, conf => conf.WithPublicMethods(publicMethod =>
!publicMethod.GetType().Name.StartsWith("Begin")
&&
!publicMethod.GetType().Name.StartsWith("End")));

Generated typescript enum doesn't output all keys correctly when there are duplicate enum values

We came across this issue for some of our bitfield enums. For example, here is a enum that would pose problem:

	[Flags] [TsEnum(IncludeNamespace = false)]
	public enum UserGroup
	{
		None				= 0x00,
		Administrator			= 0x01,
		Standard				= 0x02,
		Restricted			= 0x04,
		Guest				= 0x08,
		RestrictedAndLower	= Restricted | Guest,
		Default				= Standard,
	}

and here is the Typescript generated:

export enum UserGroup {
	None = 0,
	Administrator = 1,
	Standard = 2,
	Standard = 2,
	Restricted = 4,
	Guest = 8,
	RestrictedAndLower = 12,
}

(Notice the the Standard key is duplicated and the Default key is missing)

Is it possible to export enum as `export const enum MyEnum` ?

I am having trouble defining some configurations based on an enum.
[email protected]
[email protected]
[email protected]

eg.
In file MyEnum.ts produced by Reinforced Typings

module Vm {
  export enum MyEnum {
    Created = 0,
    Waiting = 1
  }
}

In file MyConfig

export const MyConfig = {
  [Vm.MyEnum.Created]: {
     shortMessage: 'Created',
     longMessage: 'A much longer explanatory message'
  }
  /* etc */
}

Without the 'const' typescript is leaving the value MyEnum.Created in the output object and run time crash.

I found some info about how adding const to the enum causes the compiler to replace the identifier with the integer, which would at least get this working... [code base came from from typescript 1.8]

It is quite possible I am just being naive and have done it the hard way, I would appreciate a pointer in the right direction if that is the case.

Tsconfig

I have an issue after including reinforced typings, that all my typescript get's compiled in their folder instead of what is specified in the tsconfig.json,

Hopefully, you can point out an error I might have made.

Reinforced.typings.settings.xml:
image

end of csproj:
image

If I put the import project for reinforced typings above, it won't run at all.

tsconfig:
image

Code generator Reinforced.Typings.Generators.ClassCodeGenerator has thrown an error: Length cannot be less than zero.

Hi guys,

I've got compiler error: "Code generator Reinforced.Typings.Generators.ClassCodeGenerator has thrown an error: Length cannot be less than zero."

I'm using fluent configuration.

After building the project only ts.tmp file is generated and there's no ts file.

Everything worked properly before and I can't remember any source code change.

Gist Github with Reinforced.Typings.settings.xml and InterfacesBuilder.cs: https://gist.github.com/urbanmichal/6578576f42f9be2572c575fe5a9d7da5

I will be grateful for any help you can provide.

Assemblies are not signed

Both Reinforced.Typings.dll and Reinforced.Typings.Integrate.dll are distributed via NuGet as not signed assemblies.
This is a blocking problem, since it prevents usage of Reinforced Typings in any project that involves signed assemblies.

Partial class?

Is there any problem with generating code for partial class?

Generating "export class" without module/namespace

When generating ts classes with RT, they are either generated within a module as "export class" or without a module (IncludeNamespace=false) - but then without the export keyword.

I miss the option of generating "export class"es without the module/namespace.

The Angular2 team constantly uses "export class" without the module in their examples (for example https://angular.io/docs/ts/latest/guide/displaying-data.html), this leads me to believe that it would be valid to have an export class without a module.

error MSB6006: "rtcli.exe" exited with code -1073741571 + [TsProperty] not working

Hello!

I have a .csproj with circa 250 C# files (a mix of classes, interfaces and enums). I was able to successfully run your translator tool for interfaces and enums, but when including all the classes then I get the error from the title:

packages\Reinforced.Typings.1.3.7\build\Reinforced.Typings.targets(76,3): error MSB6006: "rtcli.exe" exited with code -1073741571.

Could you please help me out on how to narrow down the issue, so I could potentially locate the problematic class and see what's bugging the translator tool or even better is this a sort of a common issue for which you can help me out?

Currently I am narrowing it down by filtering on namespaces as when I cherry pick some classes the translation is successful.

I'm using a custom configure method per instructions on wiki, like this:

public static void Configure(ConfigurationBuilder builder)
		{

// "TranslationConfiguration" below, is the name of this static class which has this method, and 
// which is in the assembly that holds all the view models

			var asm = Assembly.GetAssembly(typeof(TranslationConfiguration));
			var viewModelTypes = asm.GetTypes();

			var classes = new List<Type>();
			var interfaces = new List<Type>();
			var enums = new List<Type>();

			foreach (var t in viewModelTypes)
			{
				if (t.IsClass) classes.Add(t);
				else if (t.IsInterface) interfaces.Add(t);
				else if (t.IsEnum) enums.Add(t);
			}

			var classesConfig = new Action<IClassConfigurationBuilder>(c => c.WithAllProperties());
			var intfConfig = new Action<IInterfaceConfigurationBuilder>(c =>
			{
				c.WithAllFields();
				c.WithAllProperties();
				c.AutoI(false);
			});

			builder.ExportAsClasses(classes, classesConfig);
			builder.ExportAsInterfaces(interfaces, intfConfig);
		        builder.ExportAsEnums(enums);
		}

Hope you can advise me how to debug the rtcli or any ideas would be welcome, thanks.

Thanks for making this great tool.
V.

Inspecting attributes from JSON.NET [JsonObject]

Hi, I just wanted your advice on whether I should create a new project or modify this one.

I'm thinking about using this project code-base to detect Json.NET attributes that we already have on our C# code for deserializing objects into JSON - as well.

So, my idea is to have a configuration option to look for [JsonObject] and [JsonProperty] etc as well as [TsInterface] and [TsProperty].

Because, many of our [TsInterface] attributes are just duplicating the attributes we have already setup using [JsonObject]

But I'm interested in your opinion... do you think this idea would be better as a separate project or as some kind of config/option in this one?

Order of exported classes

Hi.
There is an issue with order of generated export classes. Reinforced.Typings builds following code:

module MyModule {
  export class Abc extends MyModule.Def { }
  export class Def { }
}

And this causes TypeScript error:

error TS2690: A class must be declared after its base class.

DontIncludeToNamespace does nothing when exporting enums

Using the fluent configuration.

public static void Configure(ConfigurationBuilder builder)
{
  builder.ExportAsEnum<MyNamespace.MyEnum>()
    .DontIncludeToNamespace();

  builder.ExportAsInterface<MyNamespace.MyModel>()
    .DontIncludeToNamespace();
}

results in

declare module MyNamespace {
  export enum MyEnum { 
    Foo = 0, 
    Bar = 1, 
  }
}

interface IMyModel
{
}

Generate class from enum

Hi,

Is it possible to generate class from enum without creating specific Code Generator?
I have an c# enum of this kind:
public enum MyEnum { [EnumMember(Value = "Value1")] Member1, [EnumMember(Value = "Value2")] Member2, [EnumMember(Value = "Value3")] Member3, }
I want to have something like this in TypeScript:
export class MyClass { Member1 = "Value1"; Member2 = "Value2"; Member3 = "Value3"; }

Too many references causes rtcli.exe to fail due to > 32000 characters in command line arguments

[EDIT] After further investigation, I found that the culprit is the References parameter in Reinforced.Typings.Targets. When a project has a lot of references, the exe cannot be invoked as the argument becomes too long for Windows to handle (ugh).

If I try changing the code to give a smaller number of References, I get errors that certain assemblies cannot be loaded. Is there a way for the program to infer the references? It seems crazy that all the project's references need to be passed in like this.

I'm happy to work on a fix but I'm not sure what form that fix would take.

[ORIGINAL POST]
When I try to build the project after freshly installing Reinforced.Typings, I get the following error:

The specified task executable "rtcli.exe" could not be run. The filename or extension is too long

I checked, and the full path to rtcli.exe is only ~70 characters long.

Any idea what could be causing this issue?

DateTime -> any

Is it by design that DateTime C# type are translated to any type in TypeScript?

Generate pure typings in different file

Hey,

One question - I'd like to generate the enum declaration in non-definition files (just .ts) while all the interfaces go into .d.ts files. Is that possible?

Inconsistent naming

It appears that a C# class called ExternalUser will produce a TypeScript definition called IExternalUser, as expected, however a C# class called InternalUser will produce a TS defn called InternalUser. There must be some logic to check for leading I's somewhere, but some improvement may be required...

ForceNullable on Class/Interface Level

I would like to use the ForceNullable Attribute on Class/Interface Level so that all Properties of the Class/Interface are optional in the resulting ts.

=>
Forces all properties to be nullable. E.g. field:boolean becomes field?:boolean when you specify [TsInterface(ForceNullable = true)] in attribute configuration

Is that something that could be interesting to others?

Support ValueTuple

Reinforced.Typings.TypeExtensions.IsTuple doesn't check for System.ValueTuple and returns false, causing all ValueTuples to map to any. Can support for ValueTuple be added?

Version for MVC 6.0

I have a very large, very complex multi-solution system spanning both .NET 3.5 and .NET Core 1.0 compilations for my POCO. Now we're doing some Angular stuff for database maintenance chores and need to share out the POCOs as TS files, so I built a skeleton non-core .NET console project, added Reinforced.Typings, then referenced my DLL in the configuration as follows:

<ItemGroup>
<RtAdditionalAssembly Include="$(SolutionDir)....\ClientLibraries\DataDef\bin\Debug\net35\DataDef.dll" />
</ItemGroup>

The problem is that VS says RtAdditionalAssembly is not a valid child of ItemGroup. This is VS2015 Update 3 with all patches as of Aug 2016.

Camel Casing everything, even when option explicitly disabled.

My class/interface members are being camelCased even when I explicitly set them to not be.

I created and use the following extensions:

        public static T WithEverythingThatIsPublic<T>(this T builder) where T : ITypeConfigurationBuilder
        {
            return builder
                .WithPublicMethods(c => c.NotCamelCase())
                .WithPublicFields(c => c.NotCamelCase())
                .WithPublicProperties(c => c.NotCamelCase());
        }

        public static T NotCamelCase<T>(this T config) where T : IExportConfiguration<ICamelCaseableAttribute>
        {
            config.AttributePrototype.ShouldBeCamelCased = false;
            return config;
        }

but the output members are always camelcase.

ShouldBePascalCase

There are times when the interface generated needs to specifically use pascal case (MVC SelectListItem), but we much like setting RtCamelCaseForProperties true. We could do it by setting RtCamelCaseForProperties false and then adding the [TsProperty(ShouldBeCamelCased: true)] on every property but that is pretty messy.

What I'd love is if there would be the opposite, that we could just use [TsProperty(ShouldBePascalCased: true)] on the properties that need it for compatibility with MVC.

Fluent Configuration: Referenced console project assembly is not resolved correctly

I'm using Reinforced.Typing version 1.3.1.

For the case when models are stored within Console Application, that assembly won't be resolved correctly inside CurrentDomainOnAssemblyResolve method.

Actually referenced console assembly will be stored inside Bootstrapper's _referencesCache, but LookupAssemblyPath method will fail to find it. Because it will be looking for {assemblyName}.dll but not for {assemblyName}.exe. '.dll' extension is added to assembly name just before the call.

Line that adds .dll :

string path = LookupAssemblyPath(nm.Name + ".dll", false);

Log and relevant stack-trace:

Reinforced.Typings CLI generator (c) 2015 by Pavel B. Novikov
Reinforced.Typings : Build warning RT0099: Unrecognized parameter: References
Looking up for assembly D:\dev\example\GraphicsTypescript\obj\Debug\GraphicsTypescript.dll
Already have full path to assembly D:\dev\example\GraphicsTypescript\obj\Debug\GraphicsTypescript.dll
Looking up for assembly Example.dll
Reinforced.Typings : Build warning RT0099: Assembly Example.dll may be resolved incorrectly
Reinforced.Typings : Unexpected error RT0999: Exception has been thrown by the target of an invocation.
   at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor)
   at System.Reflection.RuntimeMethodInfo.UnsafeInvokeInternal(Object obj, Object[] parameters, Object[] arguments)
   at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
   at System.Reflection.MethodBase.Invoke(Object obj, Object[] parameters)
   at Reinforced.Typings.Cli.Bootstrapper.<>c__DisplayClass8_0.<ResolveFluentMethod>b__0(ConfigurationBuilder builder) in D:\dev\Reinforced.Typings\Reinforced.Typings.Cli\Bootstrapper.cs:line 105
   at Reinforced.Typings.TsExporter.Initialize() in D:\dev\Reinforced.Typings\Reinforced.Typings\TsExporter.cs:line 83
   at Reinforced.Typings.TsExporter.Export() in D:\dev\Reinforced.Typings\Reinforced.Typings\TsExporter.cs:line 180
   at Reinforced.Typings.Cli.Bootstrapper.Main(String[] args) in D:\dev\Reinforced.Typings\Reinforced.Typings.Cli\Bootstrapper.cs:line 48

Example is an .exe not .dll.

That was somewhat mentioned in #5.

1.3.7 no longer forces nullable (typescript optional) on nullable types

I just wanted to check that this is deliberate
On updating to 1.3.7 from 1.3.0 I found that this C# field, decorated with attribute [TsClass] now creates a typescript field that isn't optional

public int? StartPageID { get; set; }

TypeScript output:

    public startPageID?: number;  // 1.3.0
    public startPageID: number;   // 1.3.7

Admittedly, I wanted to use TsInterface for this but my team mate has forced me to use TsClass for some reason

ShouldBeCamelCased=false doesn't override config settings

TsProperty(ShouldBeCamelCased=false) property only works half-way ;-)
I gather if you set it to true, then it will override the default config settings of false - this is what it claims to do but I have no need for this

But I do want it to do the opposite... and it will not

eg the below example, still outputs "originalName" camel cased - even though I've explicitly set it to not camel case - where my settings are CamelCase by default

[TsProperty(ShouldBeCamelCased = false)]
public virtual string OriginalName { get; set; }

Support for .NET Core v1/v2 (netcoreapp1.1 / 2.0)?

It seems that .NET Core is unsupported.
However, it allowed to install the NuGet package (not specified framework versions in the .nuspec files?) for a netcoreapp1.1 project, but any references to the classes can't be resolved.

Should we expect .NET Core support of the project?

RTCLI throws an exception whenever a specific class exists in the project

Something about the below class being present in the project causes RTCLI to throw an exception.

    public class Broken : Swashbuckle.Swagger.IOperationFilter
    {
        public void Apply(Swashbuckle.Swagger.Operation operation, Swashbuckle.Swagger.SchemaRegistry schemaRegistry, System.Web.Http.Description.ApiDescription apiDescription)
        {
            
        }
    }

The class requires the library Swashbuckle.

The exception:

Reinforced.Typings : Unexpected error RT0999: Exception has been thrown by the target of an invocation.
                        at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor) (TaskId:47)
                        at System.Reflection.RuntimeMethodInfo.UnsafeInvokeInternal(Object obj, Object[] parameters, Object[] arguments) (TaskId:47)
                        at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture) (TaskId:47)
                        at Reinforced.Typings.Cli.Bootstrapper.<>c__DisplayClass2.<ResolveFluentMethod>b__0(ConfigurationBuilder builder) (TaskId:47)
                        at Reinforced.Typings.TsExporter.Initialize() (TaskId:47)
                        at Reinforced.Typings.TsExporter.Export() (TaskId:47)
                        at Reinforced.Typings.Cli.Bootstrapper.Main(String[] args) (TaskId:47)

Object reference not set to an instance of an object

Code generator Reinforced.Typings.Generators.EnumGenerator has thrown an error: Object reference not set to an instance of an object.

I'm trying to work with Enums, using two projects - the main website (which has some TsInterface use in it including TsEnum which works nicely) and a "core" dll that is referenced by the main website, which also contains some models. I've added the "core" library to the settings.xml using RtAdditionalAssembly and it sort of works, but I get this error.

Could you output symbols on the nuget package so I could see line numbers to help diagnose/fix this issue?

Nuget dlls not signed

When building a signed module that makes use of reinforced.typings, I get the following compiler error:

CSC : error CS1577: Assembly generation failed -- Referenced assembly 'Reinforced.Typings' does not have a strong name

Can you update the nuget package with a signed library?

Add index.ts file when using modules

Automatic generation of index.ts file containing imports would be a pretty neat feature. AFAIK right now if we're using modules we need to import each file independently in TS code:

import { ContractA } from "contracts/ContractA";
import { ContractB } from "contracts/ContractB";
import { ContractC } from "contracts/ContractC";
import { ContractD } from "contracts/sub/ContractD";
import { ContractE } from "contracts/sub/ContractE";

If Reinforced.Typings would generate two index.ts files inside contracts and contracts/sub directories we would be able to improve readability:

import { ContractA, ContractB, ContractC } from "contracts";
import { ContractD, ContractE } from "contracts/sub";

Type guards

Is it possible to write C# code to generate TypeScript type guards?

My case if the following:

export interface IBaseClass
{
	Id: number;
	Name: string;
}
export interface IFirstClass extends IBaseClass
{
	SomeProperty: number;
}
export interface ISecondClass extends IBaseClass
{
            SomeOtherProperty: string;
}

and wanting to use it in a method like

    doStuff(value: IBaseClass): void
    {
            if (value is IFirstClass) {
                    //Do something with value.SomeProperty 
            }
    }

I know that in order to do this, I need some type guarding code like this:

export function isFirstClass(item: IFirstClass | ISecondClass): item is IFirstClass {
    return (<IFirstClass>item).SomeProperty !== undefined;
}

Writing it, is not a big deal as such, but I wanted to know if there are any built in options to generate this so I don't have to maintain it manually when the file is updated?

TsProperty Name override, is itself overridden by config settings

[JsonIgnore,TsProperty(Name = "ID", ForceNullable = true)]
protected virtual int _id { get { return 0; }}

Gives me below, when settings are for Camel Case, but I don't expect camel case settings to override an explicit setting of the "Name"

export interface IDomainObject
{	
	id?: number;
}

[TsClass] attribute does not apply 'ForceNullable = true'

Hi, I believe this should work, given the documentation?

That is, if I adorn my C# class with [TsClass] and set the attribute [TsProperty(ForceNullable = true)] - it should generate the TypeScript nullable "?" syntax

I believe it's due to this line of code in PropertyCodeGenerator.cs ?:
if (tp.ForceNullable && element.DeclaringType.IsExportingAsInterface() && !Context.SpecialCase)

Which seems to limit the ForceNullable generation to interfaces (TsInterface)

MSB4044: The "RemoveTypeScriptStep" task was not given a value for the required parameter "Original".

The only thing I've changed in my codebase, to get this error, is to move my tsconfig.json
Which technically, has nothing to do with Reinforced.Typings, since it doesn't build my typescript or need to know anything about it.

So maybe this is an issue to request that if RtBypassTypeScriptCompilation=true, then cater for not finding or having anything to do with my tsconfig.json file?

Reinforced.Typings.settings.xml : warning : TypeScript sources will not be built before project compile because it is disabled by Reinforced.Typings configuration [C: \code\src\Web.Site\Web.Site.csproj]
RT is fixing build tasks
RT has fixed build tasks:ResolveReferences;ResolveKeySource;SetWin32ManifestProperties;_GenerateCompileInputs;BeforeCompile;_TimeStampBeforeCompile;CoreCompile;_TimeStampAfterCompile;AfterCompile;;_AfterCompileWinFXInternal
C:\code\packages\Reinforced.Typings.1.3.0\build\Reinforced.Typings.targets(58,3): error MSB4044: The "RemoveTypeScriptStep" task was not given a value for the
required parameter "Original". [C:\code\src\Web.Site\Web.Site.csproj]

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.