Skip to content

Commit

Permalink
Add required properties from C# 11
Browse files Browse the repository at this point in the history
  • Loading branch information
tuscen committed Feb 25, 2024
1 parent 91f3a7c commit 945cf78
Show file tree
Hide file tree
Showing 172 changed files with 2,735 additions and 1,012 deletions.
@@ -1,3 +1,5 @@
using System.Diagnostics.CodeAnalysis;

// ReSharper disable once CheckNamespace
namespace Telegram.Bot.Requests;

Expand All @@ -19,7 +21,7 @@ public class AnswerCallbackQueryRequest : RequestBase<bool>
/// Unique identifier for the query to be answered
/// </summary>
[JsonProperty(Required = Required.Always)]
public string CallbackQueryId { get; }
public required string CallbackQueryId { get; init; }

/// <summary>
/// Text of the notification. If not specified, nothing will be shown to the user, 0-200 characters
Expand Down Expand Up @@ -54,12 +56,19 @@ public class AnswerCallbackQueryRequest : RequestBase<bool>
[JsonProperty(DefaultValueHandling = DefaultValueHandling.Ignore)]
public int? CacheTime { get; set; }

/// <summary>
/// Initializes a new request with callbackQueryId
/// </summary>
public AnswerCallbackQueryRequest() : base("answerCallbackQuery") { }

/// <summary>
/// Initializes a new request with callbackQueryId
/// </summary>
/// <param name="callbackQueryId">Unique identifier for the query to be answered</param>
[SetsRequiredMembers]
[Obsolete("Use parameterless constructor with required parameters")]
public AnswerCallbackQueryRequest(string callbackQueryId)
: base("answerCallbackQuery")
: this()
{
CallbackQueryId = callbackQueryId;
}
Expand Down
@@ -1,4 +1,5 @@
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;

// ReSharper disable once CheckNamespace
namespace Telegram.Bot.Requests;
Expand All @@ -16,7 +17,7 @@ public class SetMyCommandsRequest : RequestBase<bool>
/// At most 100 commands can be specified.
/// </summary>
[JsonProperty(Required = Required.Always)]
public IEnumerable<BotCommand> Commands { get; }
public required IEnumerable<BotCommand> Commands { get; init; }

/// <summary>
/// An object, describing scope of users for which the commands are relevant.
Expand All @@ -36,9 +37,18 @@ public class SetMyCommandsRequest : RequestBase<bool>
/// Initializes a new request with commands
/// </summary>
/// <param name="commands">A list of bot commands to be set</param>
[SetsRequiredMembers]
[Obsolete("Use parameterless constructor with required parameters")]
public SetMyCommandsRequest(IEnumerable<BotCommand> commands)
: base("setMyCommands")
: this()
{
Commands = commands;
}

/// <summary>
/// Initializes a new request with commands
/// </summary>
public SetMyCommandsRequest()
: base("setMyCommands")
{ }
}
@@ -1,4 +1,7 @@
// ReSharper disable once CheckNamespace

using System.Diagnostics.CodeAnalysis;

namespace Telegram.Bot.Requests;

/// <summary>
Expand All @@ -21,15 +24,24 @@ public class GetFileRequest : RequestBase<File>
/// File identifier to get info about
/// </summary>
[JsonProperty(Required = Required.Always)]
public string FileId { get; }
public required string FileId { get; init; }

/// <summary>
/// Initializes a new request with <see cref="FileId"/>
/// </summary>
/// <param name="fileId">File identifier to get info about</param>
[SetsRequiredMembers]
[Obsolete("Use parameterless constructor with required parameters")]
public GetFileRequest(string fileId)
: base("getFile")
: this()
{
FileId = fileId;
}

/// <summary>
/// Initializes a new request
/// </summary>
public GetFileRequest()
: base("getFile")
{ }
}
@@ -1,3 +1,4 @@
using System.Diagnostics.CodeAnalysis;
using Telegram.Bot.Requests.Abstractions;

// ReSharper disable once CheckNamespace
Expand All @@ -12,7 +13,7 @@ public class GetUserProfilePhotosRequest : RequestBase<UserProfilePhotos>, IUser
{
/// <inheritdoc />
[JsonProperty(Required = Required.Always)]
public long UserId { get; }
public required long UserId { get; init; }

/// <summary>
/// Sequential number of the first photo to be returned. By default, all photos are returned
Expand All @@ -30,9 +31,18 @@ public class GetUserProfilePhotosRequest : RequestBase<UserProfilePhotos>, IUser
/// Initializes a new request with userId
/// </summary>
/// <param name="userId">Unique identifier of the target user</param>
[SetsRequiredMembers]
[Obsolete("Use parameterless constructor with required parameters")]
public GetUserProfilePhotosRequest(long userId)
: base("getUserProfilePhotos")
: this()
{
UserId = userId;
}

/// <summary>
/// Initializes a new request with userId
/// </summary>
public GetUserProfilePhotosRequest()
: base("getUserProfilePhotos")
{ }
}
@@ -1,4 +1,7 @@
// ReSharper disable once CheckNamespace

using System.Diagnostics.CodeAnalysis;

namespace Telegram.Bot.Requests;

/// <summary>
Expand Down
@@ -1,3 +1,5 @@
using System.Diagnostics.CodeAnalysis;

// ReSharper disable once CheckNamespace
namespace Telegram.Bot.Requests;

Expand All @@ -13,13 +15,20 @@ public class GetUserChatBoostsRequest : RequestBase<UserChatBoosts>
/// Unique identifier for the chat or username of the channel (in the format <c>@channelusername</c>)
/// </summary>
[JsonProperty(Required = Required.Always)]
public ChatId ChatId { get; }
public required ChatId ChatId { get; init; }

/// <summary>
/// Unique identifier of the target user
/// </summary>
[JsonProperty(Required = Required.Always)]
public long UserId { get; }
public required long UserId { get; init; }

/// <summary>
/// Initializes a new request
/// </summary>
public GetUserChatBoostsRequest()
: base("getUserChatBoosts")
{ }

/// <summary>
/// Initializes a new request with chatId and userId
Expand All @@ -28,8 +37,10 @@ public class GetUserChatBoostsRequest : RequestBase<UserChatBoosts>
/// Unique identifier for the chat or username of the channel (in the format <c>@channelusername</c>)
/// </param>
/// <param name="userId">Unique identifier of the target user</param>
[SetsRequiredMembers]
[Obsolete("Use parameterless constructor with required parameters")]
public GetUserChatBoostsRequest(ChatId chatId, long userId)
: base("getUserChatBoosts")
: this()
{
ChatId = chatId;
UserId = userId;
Expand Down
@@ -1,3 +1,4 @@
using System.Diagnostics.CodeAnalysis;
using Newtonsoft.Json.Converters;
using Telegram.Bot.Requests.Abstractions;

Expand All @@ -16,11 +17,11 @@ public class BanChatMemberRequest : RequestBase<bool>, IChatTargetable, IUserTar
{
/// <inheritdoc />
[JsonProperty(Required = Required.Always)]
public ChatId ChatId { get; }
public required ChatId ChatId { get; init; }

/// <inheritdoc />
[JsonProperty(Required = Required.Always)]
public long UserId { get; }
public required long UserId { get; init; }

/// <summary>
/// Date when the user will be unbanned. If user is banned for more than 366 days or less
Expand All @@ -46,10 +47,19 @@ public class BanChatMemberRequest : RequestBase<bool>, IChatTargetable, IUserTar
/// (in the format <c>@channelusername</c>)
/// </param>
/// <param name="userId">Unique identifier of the target user</param>
[SetsRequiredMembers]
[Obsolete("Use parameterless constructor with required parameters")]
public BanChatMemberRequest(ChatId chatId, long userId)
: base("banChatMember")
: this()
{
ChatId = chatId;
UserId = userId;
}

/// <summary>
/// Initializes a new request
/// </summary>
public BanChatMemberRequest()
: base("banChatMember")
{ }
}
@@ -1,3 +1,4 @@
using System.Diagnostics.CodeAnalysis;
using Newtonsoft.Json.Converters;
using Telegram.Bot.Requests.Abstractions;

Expand All @@ -15,13 +16,13 @@ public class BanChatSenderChatRequest : RequestBase<bool>, IChatTargetable
{
/// <inheritdoc />
[JsonProperty(Required = Required.Always)]
public ChatId ChatId { get; }
public required ChatId ChatId { get; init; }

/// <summary>
/// Unique identifier of the target sender chat
/// </summary>
[JsonProperty(Required = Required.Always)]
public long SenderChatId { get; }
public required long SenderChatId { get; init; }

/// <summary>
/// Date when the sender chat will be unbanned, unix time. If the chat is banned for more than 366 days or
Expand All @@ -40,10 +41,19 @@ public class BanChatSenderChatRequest : RequestBase<bool>, IChatTargetable
/// <param name="senderChatId">
/// Unique identifier of the target sender chat
/// </param>
[SetsRequiredMembers]
[Obsolete("Use parameterless constructor with required parameters")]
public BanChatSenderChatRequest(ChatId chatId, long senderChatId)
: base("banChatSenderChat")
: this()
{
ChatId = chatId;
SenderChatId = senderChatId;
}

/// <summary>
/// Initializes a new request
/// </summary>
public BanChatSenderChatRequest()
: base("banChatSenderChat")
{ }
}
@@ -1,3 +1,4 @@
using System.Diagnostics.CodeAnalysis;
using Telegram.Bot.Requests.Abstractions;

// ReSharper disable once CheckNamespace
Expand All @@ -13,13 +14,13 @@ public class ApproveChatJoinRequest : RequestBase<bool>, IChatTargetable, IUserT
{
/// <inheritdoc/>
[JsonProperty(Required = Required.Always)]
public ChatId ChatId { get; }
public required ChatId ChatId { get; init; }

/// <summary>
/// Unique identifier of the target user
/// </summary>
[JsonProperty(Required = Required.Always)]
public long UserId { get; }
public required long UserId { get; init; }

/// <summary>
/// Initializes a new request with chatId and userId
Expand All @@ -28,10 +29,19 @@ public class ApproveChatJoinRequest : RequestBase<bool>, IChatTargetable, IUserT
/// (in the format <c>@channelusername</c>)
/// </param>
/// <param name="userId">Unique identifier of the target user</param>
[SetsRequiredMembers]
[Obsolete("Use parameterless constructor with required parameters")]
public ApproveChatJoinRequest(ChatId chatId, long userId)
: base("approveChatJoinRequest")
: this()
{
ChatId = chatId;
UserId = userId;
}

/// <summary>
/// Initializes a new request with chatId and userId
/// </summary>
public ApproveChatJoinRequest()
: base("approveChatJoinRequest")
{ }
}
@@ -1,3 +1,4 @@
using System.Diagnostics.CodeAnalysis;
using Newtonsoft.Json.Converters;
using Telegram.Bot.Requests.Abstractions;

Expand All @@ -15,7 +16,7 @@ public class CreateChatInviteLinkRequest : RequestBase<ChatInviteLink>, IChatTar
{
/// <inheritdoc />
[JsonProperty(Required = Required.Always)]
public ChatId ChatId { get; }
public required ChatId ChatId { get; init; }

/// <summary>
/// Invite link name; 0-32 characters
Expand Down Expand Up @@ -50,9 +51,18 @@ public class CreateChatInviteLinkRequest : RequestBase<ChatInviteLink>, IChatTar
/// <param name="chatId">Unique identifier for the target chat or username of the target channel
/// (in the format <c>@channelusername</c>)
/// </param>
[SetsRequiredMembers]
[Obsolete("Use parameterless constructor with required parameters")]
public CreateChatInviteLinkRequest(ChatId chatId)
: base("createChatInviteLink")
: this()
{
ChatId = chatId;
}

/// <summary>
/// Initializes a new request
/// </summary>
public CreateChatInviteLinkRequest()
: base("createChatInviteLink")
{ }
}
@@ -1,3 +1,4 @@
using System.Diagnostics.CodeAnalysis;
using Telegram.Bot.Requests.Abstractions;

// ReSharper disable once CheckNamespace
Expand All @@ -13,13 +14,13 @@ public class DeclineChatJoinRequest : RequestBase<bool>, IChatTargetable, IUserT
{
/// <inheritdoc/>
[JsonProperty(Required = Required.Always)]
public ChatId ChatId { get; }
public required ChatId ChatId { get; init; }

/// <summary>
/// Unique identifier of the target user
/// </summary>
[JsonProperty(Required = Required.Always)]
public long UserId { get; }
public required long UserId { get; init; }

/// <summary>
/// Initializes a new request with chatId and userId
Expand All @@ -28,10 +29,19 @@ public class DeclineChatJoinRequest : RequestBase<bool>, IChatTargetable, IUserT
/// (in the format <c>@channelusername</c>)
/// </param>
/// <param name="userId">Unique identifier of the target user</param>
[SetsRequiredMembers]
[Obsolete("Use parameterless constructor with required parameters")]
public DeclineChatJoinRequest(ChatId chatId, long userId)
: base("declineChatJoinRequest")
: this()
{
ChatId = chatId;
UserId = userId;
}

/// <summary>
/// Initializes a new request with chatId and userId
/// </summary>
public DeclineChatJoinRequest()
: base("declineChatJoinRequest")
{ }
}

0 comments on commit 945cf78

Please sign in to comment.