Skip to content

Commit

Permalink
Support for C# 9 record, fix for string? type
Browse files Browse the repository at this point in the history
  • Loading branch information
AdaskoTheBeAsT committed Jan 10, 2021
1 parent c90ba6c commit bae691d
Show file tree
Hide file tree
Showing 18 changed files with 554 additions and 6 deletions.
10 changes: 10 additions & 0 deletions docs/pages/changelog.html
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,16 @@
<div class="row">
<div class="col-sm-10 col-sm-push-1">
<h1>Change log</h1>

<h3>Typewriter 1.30</h3>
<p class="lead">Support for C# 9 records.</p>

<h4>1.30.0</h4>
<ul>
<li>Added support for C# 9.0 records</li>
<li>Fixed error for 'string?' type - invalid marked as IsEnumerable</li>
<li>Refreshing project structure - start depending from nuget packages</li>
</ul>

<h3>Typewriter 1.22</h3>
<p class="lead">Support for Visual Studio 2019.</p>
Expand Down
2 changes: 2 additions & 0 deletions src/CodeDom/CodeDomFileMetadata.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ public CodeDomFileMetadata(ProjectItem projectItem)
CodeDomInterfaceMetadata.FromCodeElements(projectItem.FileCodeModel.CodeElements, this)
.Concat(Namespaces.SelectMany(n => CodeDomInterfaceMetadata.FromCodeElements(n.Members, this)));

public IEnumerable<IRecordMetadata> Records => Enumerable.Empty<IRecordMetadata>();

internal CodeType GetType(string fullName)
{
return typeFactory.GetType(fullName);
Expand Down
5 changes: 5 additions & 0 deletions src/CodeModel/CodeModel/File.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@ public abstract class File : Item
/// </summary>
public abstract ClassCollection Classes { get; }

/// <summary>
/// All public records defined in the file.
/// </summary>
public abstract RecordCollection Records { get; }

/// <summary>
/// All public delegates defined in the file.
/// </summary>
Expand Down
141 changes: 141 additions & 0 deletions src/CodeModel/CodeModel/Record.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
using Typewriter.CodeModel.Attributes;

namespace Typewriter.CodeModel
{
/// <summary>
/// Represents a record.
/// </summary>
[Context("Record", "Records")]
public abstract class Record : Item
{
/// <summary>
/// All attributes defined on the record.
/// </summary>
public abstract AttributeCollection Attributes { get; }

/// <summary>
/// The base record of the record.
/// </summary>
public abstract Record BaseRecord { get; }

/// <summary>
/// All constants defined in the record.
/// </summary>
public abstract ConstantCollection Constants { get; }

/// <summary>
/// The containing record of the record if it's nested.
/// </summary>
public abstract Record ContainingRecord { get; }

/// <summary>
/// All delegates defined in the record.
/// </summary>
public abstract DelegateCollection Delegates { get; }

/// <summary>
/// The XML documentation comment of the record.
/// </summary>
public abstract DocComment DocComment { get; }

/// <summary>
/// All events defined in the record.
/// </summary>
public abstract EventCollection Events { get; }

/// <summary>
/// All fields defined in the record.
/// </summary>
public abstract FieldCollection Fields { get; }

/// <summary>
/// The full original name of the record including namespace and containing record names.
/// </summary>
public abstract string FullName { get; }

/// <summary>
/// All interfaces implemented by the record.
/// </summary>
public abstract InterfaceCollection Interfaces { get; }

/// <summary>
/// Determines if the record is abstract.
/// </summary>
public abstract bool IsAbstract { get; }

/// <summary>
/// Determines if the record is generic.
/// </summary>
public abstract bool IsGeneric { get; }

/// <summary>
/// All methods defined in the class.
/// </summary>
public abstract MethodCollection Methods { get; }

/// <summary>
/// The name of the record (camelCased).
/// </summary>
public abstract string name { get; }

/// <summary>
/// The name of the record.
/// </summary>
public abstract string Name { get; }

/// <summary>
/// The namespace of the record.
/// </summary>
public abstract string Namespace { get; }

/// <summary>
/// The parent context of the record.
/// </summary>
public abstract Item Parent { get; }

/// <summary>
/// All properties defined in the record.
/// </summary>
public abstract PropertyCollection Properties { get; }

/// <summary>
/// All generic type arguments of the record.
/// TypeArguments are the specified arguments for the TypeParameters on a generic record e.g. &lt;string&gt;.
/// (In Visual Studio 2013 TypeParameters and TypeArguments are the same)
/// </summary>
public abstract TypeCollection TypeArguments { get; }

/// <summary>
/// All generic type parameters of the record.
/// TypeParameters are the type placeholders of a generic class e.g. &lt;T&gt;.
/// (In Visual Studio 2013 TypeParameters and TypeArguments are the same)
/// </summary>
public abstract TypeParameterCollection TypeParameters { get; }


/// <summary>
/// Converts the current instance to string.
/// </summary>
public static implicit operator string(Record instance)
{
return instance.ToString();
}

protected abstract Type Type { get; }

/// <summary>
/// Converts the current instance to a Type.
/// </summary>
public static implicit operator Type(Record instance)
{
return instance?.Type;
}
}

/// <summary>
/// Represents a collection of records.
/// </summary>
public interface RecordCollection : ItemCollection<Record>
{
}
}
129 changes: 129 additions & 0 deletions src/CodeModel/Typewriter.CodeModel.XML

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions src/CodeModel/Typewriter.CodeModel.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
<Compile Include="CodeModel\ItemCollection.cs" />
<Compile Include="CodeModel\Method.cs" />
<Compile Include="CodeModel\Parameter.cs" />
<Compile Include="CodeModel\Record.cs" />
<Compile Include="Configuration\PartialRenderingMode.cs" />
<Compile Include="Configuration\Settings.cs" />
<Compile Include="Extensions\Types\TypeExtensions.cs" />
Expand Down
1 change: 1 addition & 0 deletions src/Metadata/Interfaces/IFileMetadata.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,6 @@ public interface IFileMetadata
IEnumerable<IDelegateMetadata> Delegates { get; }
IEnumerable<IEnumMetadata> Enums { get; }
IEnumerable<IInterfaceMetadata> Interfaces { get; }
IEnumerable<IRecordMetadata> Records { get; }
}
}
25 changes: 25 additions & 0 deletions src/Metadata/Interfaces/IRecordMetadata.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
using System.Collections.Generic;

namespace Typewriter.Metadata.Interfaces
{
public interface IRecordMetadata : INamedItem
{
string DocComment { get; }
bool IsAbstract { get; }
bool IsGeneric { get; }
string Namespace { get; }
ITypeMetadata Type { get; }
IEnumerable<IAttributeMetadata> Attributes { get; }
IRecordMetadata BaseRecord { get; }
IRecordMetadata ContainingRecord { get; }
IEnumerable<IConstantMetadata> Constants { get; }
IEnumerable<IDelegateMetadata> Delegates { get; }
IEnumerable<IEventMetadata> Events { get; }
IEnumerable<IFieldMetadata> Fields { get; }
IEnumerable<IInterfaceMetadata> Interfaces { get; }
IEnumerable<IMethodMetadata> Methods { get; }
IEnumerable<IPropertyMetadata> Properties { get; }
IEnumerable<ITypeParameterMetadata> TypeParameters { get; }
IEnumerable<ITypeMetadata> TypeArguments { get; }
}
}
1 change: 1 addition & 0 deletions src/Metadata/Typewriter.Metadata.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
<Compile Include="Interfaces\INamedItem.cs" />
<Compile Include="Interfaces\IParameterMetadata.cs" />
<Compile Include="Interfaces\IPropertyMetadata.cs" />
<Compile Include="Interfaces\IRecordMetadata.cs" />
<Compile Include="Interfaces\ITypeParameterMetadata.cs" />
<Compile Include="Interfaces\ITypeMetadata.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
Expand Down
3 changes: 3 additions & 0 deletions src/Roslyn/RoslynFileMetadata.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ public RoslynFileMetadata(Document document, Settings settings, Action<string[]>
public IEnumerable<IEnumMetadata> Enums => RoslynEnumMetadata.FromNamedTypeSymbols(GetNamespaceChildNodes<EnumDeclarationSyntax>());
public IEnumerable<IInterfaceMetadata> Interfaces => RoslynInterfaceMetadata.FromNamedTypeSymbols(GetNamespaceChildNodes<InterfaceDeclarationSyntax>(), this);

public IEnumerable<IRecordMetadata> Records =>
RoslynRecordMetadata.FromNamedTypeSymbols(GetNamespaceChildNodes<RecordDeclarationSyntax>(), this);

private void LoadDocument(Document document)
{
_document = document;
Expand Down

0 comments on commit bae691d

Please sign in to comment.