reinforced / Reinforced.Typings

Converts C# classes to TypeScript interfaces (and many more) within project build. 0-dependency, minimal, gluten-free
MIT License
499 stars 80 forks source link

Documentation changes #204

Open tonyhallett opened 3 years ago

tonyhallett commented 3 years ago

Just a few thoughts.

Fluent configuration for generic types. Perhaps mention ExportAsClasses/Interfaces necessary for generics ( ExportAsClassUntyped )


Generate any custom glue code Perhaps in addition to linking to custom code generators the fluent WithConstructor for constructor body / Implement for methods. Perhaps the home page should also be clear that there is no method body code generated unless you do one of the above.

--

Substitutions Mention that substitutions is not only available to the fluent api. Globally it is but a custom code generator has access to TypeBlueprint.Substitutions

https://github.com/reinforced/Reinforced.Typings/blob/8434c570aa97721690a93602604f75c2bb162c5b/Reinforced.Typings/TypeResolver.cs#L201

https://github.com/reinforced/Reinforced.Typings/blob/ef433b532a47f1fb91bc0312d351835398ac5c13/Reinforced.Typings/TypeBlueprint.cs#L152

-- Inference Mention that type inference is not only available to the fluent api. It is possible to get the same result by deriving from TsFunctionAttribute, TsParameterAttribute, TsPropertyAttribute and TsGenericAttribute

public class InferringPropertyAttribute : TsPropertyAttribute
    {
        public InferringPropertyAttribute()
        {
            this.InferType(...........................................
        }
    }

Also through the TypeBluePrint ( ExportContext.Project.BluePrint ) there is the ForMember methods. These get or create the attributes above. This could be particularly important for someone wanting to use the Fluent API with reflection for configuring parameters and does not have access to WithMethod.

https://github.com/reinforced/Reinforced.Typings/wiki/Fluent-configuration#method-parameter

Method parameter To specify configuration for method parameter you should use .WithMethod fluent configuration method for class/interface and specify exported method using lambda expression replacing all parameters with Ts.Parameter call. Like this:

public interface IMyInterface
{
    void DoSomething(int a, string b);
}

public static void Configure(ConfigurationBuilder builder)
{
    builder.ExportAsInterface<IMyInterface>()
        .WithMethod(c => 
            c.DoSomething(
                // conf is parameter configuration builder
                Ts.Parameter<int>(conf => conf.OverrideName("blah")), 
                Ts.Parameter<string>()));
}
pavel-b-novikov commented 3 years ago

Feel free to branch & PR.

alastair-todd commented 3 years ago

Pretty stuck with the existing docco.

I just want camel-case properties. Why not default?