-
Notifications
You must be signed in to change notification settings - Fork 109
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Minor attribute cleanups for C# module #1753
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 6 additions & 1 deletion
7
...es/bindings-csharp/Codegen.Tests/fixtures/server/snapshots/Module#PublicTable.verified.cs
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
2 changes: 1 addition & 1 deletion
2
...csharp/Codegen.Tests/fixtures/server/snapshots/Module#Timers.SendMessageTimer.verified.cs
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,73 +1,87 @@ | ||
namespace SpacetimeDB; | ||
|
||
[Flags] | ||
public enum ColumnAttrs : byte | ||
namespace SpacetimeDB | ||
{ | ||
UnSet = 0b0000, | ||
Indexed = 0b0001, | ||
AutoInc = 0b0010, | ||
Unique = Indexed | 0b0100, | ||
Identity = Unique | AutoInc, | ||
PrimaryKey = Unique | 0b1000, | ||
PrimaryKeyAuto = PrimaryKey | AutoInc, | ||
namespace Internal | ||
{ | ||
[Flags] | ||
public enum ColumnAttrs : byte | ||
{ | ||
UnSet = 0b0000, | ||
Indexed = 0b0001, | ||
AutoInc = 0b0010, | ||
Unique = Indexed | 0b0100, | ||
Identity = Unique | AutoInc, | ||
PrimaryKey = Unique | 0b1000, | ||
PrimaryKeyAuto = PrimaryKey | AutoInc, | ||
} | ||
|
||
// A legacy alias, originally defined as `PrimaryKey | Identity` which is numerically same as above. | ||
PrimaryKeyIdentity = PrimaryKeyAuto, | ||
} | ||
[AttributeUsage(AttributeTargets.Field)] | ||
public abstract class ColumnAttribute : Attribute | ||
{ | ||
public string? Table { get; init; } | ||
internal abstract ColumnAttrs Mask { get; } | ||
} | ||
} | ||
|
||
/// <summary> | ||
/// Registers a type as the row structure of a SpacetimeDB table, enabling codegen for it. | ||
/// | ||
/// <para> | ||
/// Multiple [Table] attributes per type are supported. This is useful to reuse row types. | ||
/// Each attribute instance must have a unique name and will create a SpacetimeDB table. | ||
/// </para> | ||
/// </summary> | ||
[AttributeUsage(AttributeTargets.Struct | AttributeTargets.Class, AllowMultiple = true)] | ||
public sealed class TableAttribute : Attribute | ||
{ | ||
/// <summary> | ||
/// This identifier is used to name the SpacetimeDB table on the host as well as the | ||
/// table handle structures generated to access the table from within a reducer call. | ||
/// Registers a type as the row structure of a SpacetimeDB table, enabling codegen for it. | ||
/// | ||
/// <para>Defaults to the <c>nameof</c> of the target type.</para> | ||
/// <para> | ||
/// Multiple [Table] attributes per type are supported. This is useful to reuse row types. | ||
/// Each attribute instance must have a unique name and will create a SpacetimeDB table. | ||
/// </para> | ||
/// </summary> | ||
public string? Name { get; init; } | ||
[AttributeUsage(AttributeTargets.Struct | AttributeTargets.Class, AllowMultiple = true)] | ||
public sealed class TableAttribute : Attribute | ||
{ | ||
/// <summary> | ||
/// This identifier is used to name the SpacetimeDB table on the host as well as the | ||
/// table handle structures generated to access the table from within a reducer call. | ||
/// | ||
/// <para>Defaults to the <c>nameof</c> of the target type.</para> | ||
/// </summary> | ||
public string? Name { get; init; } | ||
|
||
/// <summary> | ||
/// Set to <c>true</c> to make the table visible to everyone. | ||
/// | ||
/// <para>Defaults to the table only being visible to its owner.</para> | ||
/// </summary> | ||
public bool Public { get; init; } = false; | ||
/// <summary> | ||
/// Set to <c>true</c> to make the table visible to everyone. | ||
/// | ||
/// <para>Defaults to the table only being visible to its owner.</para> | ||
/// </summary> | ||
public bool Public { get; init; } = false; | ||
|
||
public string? Scheduled { get; init; } | ||
} | ||
public string? Scheduled { get; init; } | ||
} | ||
|
||
[AttributeUsage(AttributeTargets.Field)] | ||
public abstract class ColumnAttribute : Attribute | ||
{ | ||
public string? Table { get; init; } | ||
} | ||
|
||
public sealed class AutoIncAttribute : ColumnAttribute { } | ||
public sealed class AutoIncAttribute : Internal.ColumnAttribute | ||
{ | ||
internal override Internal.ColumnAttrs Mask => Internal.ColumnAttrs.AutoInc; | ||
} | ||
|
||
public sealed class PrimaryKeyAttribute : ColumnAttribute { } | ||
public sealed class PrimaryKeyAttribute : Internal.ColumnAttribute | ||
{ | ||
internal override Internal.ColumnAttrs Mask => Internal.ColumnAttrs.PrimaryKey; | ||
} | ||
|
||
public sealed class UniqueAttribute : ColumnAttribute { } | ||
public sealed class UniqueAttribute : Internal.ColumnAttribute | ||
{ | ||
internal override Internal.ColumnAttrs Mask => Internal.ColumnAttrs.Unique; | ||
} | ||
|
||
public sealed class IndexedAttribute : ColumnAttribute { } | ||
public sealed class IndexedAttribute : Internal.ColumnAttribute | ||
{ | ||
internal override Internal.ColumnAttrs Mask => Internal.ColumnAttrs.Indexed; | ||
} | ||
|
||
public static class ReducerKind | ||
{ | ||
public const string Init = "__init__"; | ||
public const string Update = "__update__"; | ||
public const string Connect = "__identity_connected__"; | ||
public const string Disconnect = "__identity_disconnected__"; | ||
} | ||
public static class ReducerKind | ||
{ | ||
public const string Init = "__init__"; | ||
public const string Update = "__update__"; | ||
public const string Connect = "__identity_connected__"; | ||
public const string Disconnect = "__identity_disconnected__"; | ||
} | ||
|
||
[AttributeUsage(AttributeTargets.Method, Inherited = false)] | ||
public sealed class ReducerAttribute(string? name = null) : Attribute | ||
{ | ||
public string? Name => name; | ||
[AttributeUsage(AttributeTargets.Method, Inherited = false)] | ||
public sealed class ReducerAttribute(string? name = null) : Attribute | ||
{ | ||
public string? Name => name; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,9 @@ | ||
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> | ||
<!-- Only needed when referencing local dependencies as projects. For published packages, these are imported automatically. --> | ||
<Import Project="../crates/bindings-csharp/Runtime/build/SpacetimeDB.Runtime.props" /> | ||
|
||
<!-- Prevent test projects from being picked up by `dotnet pack`. --> | ||
<PropertyGroup> | ||
<IsPackable>false</IsPackable> | ||
</PropertyGroup> | ||
</Project> |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't think the toplevel ns needs {}; namespace Internal {} is fine to use with namespace SpacetimeDB; afaik
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's necessary here because you can't mix file-scoped and regular namespace syntax, C# will complain. Idk why they made it so, but 🤷♂️