Skip to content

Commit b4baba7

Browse files
1.4.2
1 parent aa776e4 commit b4baba7

File tree

6 files changed

+136
-12
lines changed

6 files changed

+136
-12
lines changed

Reinforced.Typings.Tests/Reinforced.Typings.Tests.csproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,8 @@
8282
<Compile Include="SpecificCases\SpecificTestCases.RluitenConstEnums.cs" />
8383
<Compile Include="SpecificCases\SpecificTestCases.TsFunctionWorks.cs" />
8484
<Compile Include="SpecificCases\SpecificTestCases.TsPropertyWorks.cs" />
85+
<Compile Include="SpecificCases\SpecificTestCases.OverridenNamesNotCamelCased.cs" />
86+
<Compile Include="SpecificCases\SpecificTestCases.NestedClassInheritance.cs" />
8587
<Compile Include="SpecificCases\SpecificTestCases._CopyMe_.cs" />
8688
<Compile Include="SpecificCases\SpecificTestCases.JonsaEnumWithouNamespaceTest.cs" />
8789
<Compile Include="SpecificCases\SpecificTestCases.PandaWoodCamelCase.cs" />
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
using Reinforced.Typings.Fluent;
2+
using Xunit;
3+
4+
namespace TestA
5+
{
6+
public class TestParentClassA
7+
{
8+
public string Id { get; set; }
9+
public string Name { get; set; }
10+
}
11+
12+
}
13+
14+
namespace TestB
15+
{
16+
using TestA;
17+
public class SomeOtherClass
18+
{
19+
public class SomeDerivedClass : TestParentClassA
20+
{
21+
public int OtherId { get; set; }
22+
}
23+
}
24+
}
25+
26+
namespace Reinforced.Typings.Tests.SpecificCases
27+
{
28+
29+
public partial class SpecificTestCases
30+
{
31+
[Fact]
32+
public void NestedClassInheritance()
33+
{
34+
const string result = @"
35+
module TestB {
36+
export interface ISomeDerivedClass extends TestB.ITestParentClassA
37+
{
38+
OtherId: number;
39+
}
40+
export interface ITestParentClassA
41+
{
42+
id: string;
43+
text: string;
44+
}
45+
}
46+
";
47+
AssertConfiguration(s =>
48+
{
49+
s.Global(a => a.DontWriteWarningComment());
50+
s.ExportAsInterface<TestB.SomeOtherClass.SomeDerivedClass>()
51+
.WithPublicProperties();
52+
s.ExportAsInterface<TestA.TestParentClassA>()
53+
.WithProperty(c => c.Id, v => v.OverrideName("id"))
54+
.WithProperty(c => c.Name, v => v.OverrideName("text"))
55+
.OverrideNamespace("TestB");
56+
}, result);
57+
}
58+
}
59+
}
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
using Reinforced.Typings.Attributes;
2+
using Reinforced.Typings.Fluent;
3+
using Xunit;
4+
5+
namespace Reinforced.Typings.Tests.SpecificCases
6+
{
7+
public class TestOverrides
8+
{
9+
[TsProperty(Name = "ID", ForceNullable = true)]
10+
public virtual int _id { get { return 0; } }
11+
12+
[TsFunction(Name = "DO_DOMETHING")]
13+
public void DoSomething() { }
14+
15+
public void AnotherMethod() { }
16+
17+
public string AnotherProeprty { get; set; }
18+
}
19+
public partial class SpecificTestCases
20+
{
21+
22+
23+
[Fact]
24+
public void OverridenNamesNotCamelCased()
25+
{
26+
const string result = @"
27+
module Reinforced.Typings.Tests.SpecificCases {
28+
export interface ITestOverrides
29+
{
30+
ID?: number;
31+
Another_Property: string;
32+
DO_DOMETHING() : void;
33+
Another_Method() : void;
34+
}
35+
}";
36+
AssertConfiguration(s =>
37+
{
38+
s.Global(a => a.DontWriteWarningComment().CamelCaseForMethods().CamelCaseForProperties());
39+
s.ExportAsInterface<TestOverrides>()
40+
.WithPublicProperties()
41+
.WithPublicMethods()
42+
.WithMethod(x=>x.AnotherMethod(),x=>x.OverrideName("Another_Method"))
43+
.WithProperty(x=>x.AnotherProeprty,x=>x.OverrideName("Another_Property"))
44+
;
45+
}, result);
46+
}
47+
}
48+
}

Reinforced.Typings/Generators/MethodCodeGenerator.cs

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -83,11 +83,16 @@ public override RtFuncion GenerateNode(MethodInfo element, RtFuncion result, Typ
8383
protected virtual void GetFunctionNameAndReturnType(MethodInfo element, TypeResolver resolver, out string name, out RtTypeName type)
8484
{
8585
name = element.Name;
86+
bool isNameOverridden = false;
8687
var fa = ConfigurationRepository.Instance.ForMember(element);
8788

8889
if (fa != null)
8990
{
90-
if (!string.IsNullOrEmpty(fa.Name)) name = fa.Name;
91+
if (!string.IsNullOrEmpty(fa.Name))
92+
{
93+
name = fa.Name;
94+
isNameOverridden = true;
95+
}
9196

9297
if (!string.IsNullOrEmpty(fa.Type)) type = new RtSimpleTypeName(fa.Type);
9398
else if (fa.StrongType != null) type = resolver.ResolveTypeName(fa.StrongType);
@@ -99,9 +104,12 @@ protected virtual void GetFunctionNameAndReturnType(MethodInfo element, TypeReso
99104
type = resolver.ResolveTypeName(element.ReturnType);
100105
}
101106

102-
name = Context.ConditionallyConvertMethodNameToCamelCase(name);
103-
name = element.CamelCaseFromAttribute(name);
104-
name = element.PascalCaseFromAttribute(name);
107+
if (!isNameOverridden)
108+
{
109+
name = Context.ConditionallyConvertMethodNameToCamelCase(name);
110+
name = element.CamelCaseFromAttribute(name);
111+
name = element.PascalCaseFromAttribute(name);
112+
}
105113
if (element.IsGenericMethod)
106114
{
107115
if (!(name.Contains("<") || name.Contains(">")))

Reinforced.Typings/Generators/PropertyCodeGenerator.cs

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public override RtField GenerateNode(MemberInfo element, RtField result, TypeRes
3434
var t = GetType(element);
3535
RtTypeName type = null;
3636
var propName = new RtIdentifier(element.Name);
37-
37+
bool isNameOverridden = false;
3838
var tp = ConfigurationRepository.Instance.ForMember<TsPropertyAttribute>(element);
3939
if (tp != null)
4040
{
@@ -49,7 +49,11 @@ public override RtField GenerateNode(MemberInfo element, RtField result, TypeRes
4949

5050
type = tp.TypeInferers.Infer(element, resolver) ?? type;
5151

52-
if (!string.IsNullOrEmpty(tp.Name)) propName.IdentifierName = tp.Name;
52+
if (!string.IsNullOrEmpty(tp.Name))
53+
{
54+
propName.IdentifierName = tp.Name;
55+
isNameOverridden = true;
56+
}
5357
if (tp.NilForceNullable.HasValue && !Context.SpecialCase)
5458
{
5559
propName.IsNullable = tp.NilForceNullable.Value;
@@ -64,14 +68,16 @@ public override RtField GenerateNode(MemberInfo element, RtField result, TypeRes
6468
propName.IsNullable = true;
6569
}
6670
}
67-
68-
if (element is PropertyInfo)
71+
if (!isNameOverridden)
6972
{
70-
propName.IdentifierName = Context.ConditionallyConvertPropertyNameToCamelCase(propName.IdentifierName);
73+
if (element is PropertyInfo)
74+
{
75+
propName.IdentifierName =
76+
Context.ConditionallyConvertPropertyNameToCamelCase(propName.IdentifierName);
77+
}
78+
propName.IdentifierName = element.CamelCaseFromAttribute(propName.IdentifierName);
79+
propName.IdentifierName = element.PascalCaseFromAttribute(propName.IdentifierName);
7180
}
72-
propName.IdentifierName = element.CamelCaseFromAttribute(propName.IdentifierName);
73-
propName.IdentifierName = element.PascalCaseFromAttribute(propName.IdentifierName);
74-
7581
result.Identifier = propName;
7682
result.AccessModifier = Context.SpecialCase ? AccessModifier.Public : element.GetModifier();
7783
result.Type = type;

package/Reinforced.Typings.nuspec

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
<licenseUrl>https://github.com/reinforced/Reinforced.Typings/blob/master/LICENSE.md</licenseUrl>
1818
<releaseNotes>
1919
- Additional assemblies resolvation fix
20+
- Explicitly overriden names are no more subjects of casing change
2021
</releaseNotes>
2122
<dependencies>
2223
<group targetFramework=".NETFramework4.5" />

0 commit comments

Comments
 (0)