Skip to content

Commit

Permalink
#113 - expose IProperty.GetMethod and IProperty.SetMethod and
Browse files Browse the repository at this point in the history
  • Loading branch information
NeVeSpl committed Mar 23, 2024
1 parent ef61aed commit d25b13c
Show file tree
Hide file tree
Showing 10 changed files with 123 additions and 0 deletions.
3 changes: 3 additions & 0 deletions NTypewriter.CodeModel.Roslyn/Property.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ internal sealed class Property : SymbolBase, IProperty
public bool IsReadOnly => symbol.IsReadOnly;
public bool IsSealed => symbol.IsSealed;

public IMethod GetMethod => symbol.GetMethod != null ? Method.Create(symbol.GetMethod) : null;
public IMethod SetMethod => symbol.SetMethod != null ? Method.Create(symbol.SetMethod) : null;


private Property(IPropertySymbol symbol) : base (symbol)
{
Expand Down
12 changes: 12 additions & 0 deletions NTypewriter.CodeModel.Tests/NTypewriter.CodeModel.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@
<Compile Remove="Method\ReturnType\inputCode.cs" />
<Compile Remove="Method\TypeParameters\inputCode.cs" />
<Compile Remove="NamedType\TypeParameters\inputCode.cs" />
<Compile Remove="Property\GetMethod_IsPublic\inputCode.cs" />
<Compile Remove="Property\SetMethod_IsPublic\inputCode.cs" />
<Compile Remove="Property\IsWriteOnly\inputCode.cs" />
<Compile Remove="Property\IsReadOnly\inputCode.cs" />
<Compile Remove="Property\Type\inputCode.cs" />
Expand Down Expand Up @@ -151,6 +153,10 @@
<None Remove="Method\TypeParameters\inputTemplate.tsnt" />
<None Remove="NamedType\TypeParameters\expectedResult.txt" />
<None Remove="NamedType\TypeParameters\inputTemplate.tsnt" />
<None Remove="Property\GetMethod_IsPublic\expectedResult.txt" />
<None Remove="Property\GetMethod_IsPublic\inputTemplate.tsnt" />
<None Remove="Property\SetMethod_IsPublic\expectedResult.txt" />
<None Remove="Property\SetMethod_IsPublic\inputTemplate.tsnt" />
<None Remove="Property\IsWriteOnly\expectedResult.txt" />
<None Remove="Property\IsReadOnly\expectedResult.txt" />
<None Remove="Property\IsReadOnly\inputTemplate.tsnt" />
Expand Down Expand Up @@ -332,6 +338,12 @@
<EmbeddedResource Include="NamedType\TypeParameters\expectedResult.txt" />
<EmbeddedResource Include="NamedType\TypeParameters\inputCode.cs" />
<EmbeddedResource Include="NamedType\TypeParameters\inputTemplate.tsnt" />
<EmbeddedResource Include="Property\GetMethod_IsPublic\expectedResult.txt" />
<EmbeddedResource Include="Property\GetMethod_IsPublic\inputCode.cs" />
<EmbeddedResource Include="Property\GetMethod_IsPublic\inputTemplate.tsnt" />
<EmbeddedResource Include="Property\SetMethod_IsPublic\expectedResult.txt" />
<EmbeddedResource Include="Property\SetMethod_IsPublic\inputCode.cs" />
<EmbeddedResource Include="Property\SetMethod_IsPublic\inputTemplate.tsnt" />
<EmbeddedResource Include="Property\IsWriteOnly\expectedResult.txt" />
<EmbeddedResource Include="Property\IsWriteOnly\inputCode.cs" />
<EmbeddedResource Include="Property\IsWriteOnly\inputTemplate.tsnt" />
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
PropGetSet true
PropGet true
PropGetInternalSet true
PropGetPrivateSet true
PropGetProtectedSet true
PropGetInit true
PropRequiredGetSet false
PropRequiredGetInit false
ProtectedPropGetSet false
InternalPropGetSet false
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace NTypewriter.Tests.CodeModel
{



class SampleClass
{
public int PropGetSet { get; set; }
public int PropGet { get; }
public int PropGetInternalSet { get; internal set; }
public int PropGetPrivateSet { get; private set; }
public int PropGetProtectedSet { get; protected set; }
public int PropGetInit { get; init; }
public required string PropRequiredGetSet { get; set; }
public required string PropRequiredGetInit { get; init; }
protected int ProtectedPropGetSet { get; set; }
internal int InternalPropGetSet { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{{- capture captured}}
{{- for class in data.Classes | Symbols.WhereNamespaceStartsWith "NTypewriter.Tests.CodeModel"}}
{{- for property in class.Properties }}
{{- property.Name | String.PadRight 21 }}{{ (property.GetMethod?.IsPublic )}}
{{ end }}
{{- end }}
{{- end }}
{{- Save captured "Some name" }}
12 changes: 12 additions & 0 deletions NTypewriter.CodeModel.Tests/Property/PropertyRenderingTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,18 @@ public async Task IsWriteOnly()
await RunTestForProperty();
}

[TestMethod]
public async Task GetMethod_IsPublic()
{
await RunTestForProperty();
}

[TestMethod]
public async Task SetMethod_IsPublic()
{
await RunTestForProperty();
}


[TestMethod]
public async Task Type()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
PropGetSet true
PropGet
PropGetInternalSet false
PropGetPrivateSet false
PropGetProtectedSet false
PropGetInit true
PropRequiredGetSet false
PropRequiredGetInit false
ProtectedPropGetSet false
InternalPropGetSet false
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace NTypewriter.Tests.CodeModel
{



class SampleClass
{
public int PropGetSet { get; set; }
public int PropGet { get; }
public int PropGetInternalSet { get; internal set; }
public int PropGetPrivateSet { get; private set; }
public int PropGetProtectedSet { get; protected set; }
public int PropGetInit { get; init; }
public required string PropRequiredGetSet { get; set; }
public required string PropRequiredGetInit { get; init; }
protected int ProtectedPropGetSet { get; set; }
internal int InternalPropGetSet { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{{- capture captured}}
{{- for class in data.Classes | Symbols.WhereNamespaceStartsWith "NTypewriter.Tests.CodeModel"}}
{{- for property in class.Properties }}
{{- property.Name | String.PadRight 21 }}{{ (property.SetMethod?.IsPublic )}}
{{ end }}
{{- end }}
{{- end }}
{{- Save captured "Some name" }}
10 changes: 10 additions & 0 deletions NTypewriter.CodeModel/IProperty.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,15 @@ public interface IProperty : ISymbolBase
/// The type of the property.
/// </summary>
IType Type { get; }

/// <summary>
/// Getter
/// </summary>
IMethod GetMethod { get; }

/// <summary>
/// Setter
/// </summary>
IMethod SetMethod { get; }
}
}

0 comments on commit d25b13c

Please sign in to comment.