diff --git a/DisCatSharp.Experimental/DisCatSharp.Experimental.csproj b/DisCatSharp.Experimental/DisCatSharp.Experimental.csproj
index 578a04ae6..01614d2c0 100644
--- a/DisCatSharp.Experimental/DisCatSharp.Experimental.csproj
+++ b/DisCatSharp.Experimental/DisCatSharp.Experimental.csproj
@@ -1,44 +1,45 @@
DisCatSharp.Experimental
DisCatSharp.Experimental
DisCatSharp.Experimental
DisCatSharp.Experimental
Experimental changes for DisCatSharp.
DisCatSharp,Experimental,Discord API Wrapper,Discord,Bots,Discord Bots,AITSYS,Net6
Exe
net6
all
runtime; build; native; contentfiles; analyzers; buildtransitive
+
diff --git a/DisCatSharp.Experimental/Program.cs b/DisCatSharp.Experimental/Program.cs
index aa53d547f..16dd000a2 100644
--- a/DisCatSharp.Experimental/Program.cs
+++ b/DisCatSharp.Experimental/Program.cs
@@ -1,23 +1,32 @@
using System;
using DisCatSharp.Attributes;
namespace DisCatSharp.Experimental;
public class Program
{
public static void Main(string[] args = null)
{
- Test2();
+ var test = new Test("test");
+ test.Invoke();
}
+}
+
+[Experimental("class")]
+public class Test
+{
- [Experimental("Something")]
- public static string TestString { get; set; }
+ [Experimental("property")]
+ public string TestString { get; set; }
- [Experimental]
- public static void Test2()
+ [Experimental("construct")]
+ public Test(string test = null)
{
- TestString = "Test";
- Console.WriteLine(TestString);
+ this.TestString = test;
}
+
+ [Experimental("method")]
+ public void Invoke()
+ => Console.WriteLine(this.TestString);
}
diff --git a/DisCatSharp.Tools/DisCatSharp.Analyzer/DisCatSharp.Analyzer/AttributeAnalyzer.cs b/DisCatSharp.Tools/DisCatSharp.Analyzer/DisCatSharp.Analyzer/AttributeAnalyzer.cs
index 755b8494e..c519421a9 100644
--- a/DisCatSharp.Tools/DisCatSharp.Analyzer/DisCatSharp.Analyzer/AttributeAnalyzer.cs
+++ b/DisCatSharp.Tools/DisCatSharp.Analyzer/DisCatSharp.Analyzer/AttributeAnalyzer.cs
@@ -1,92 +1,92 @@
// This file is part of the DisCatSharp project, based off DSharpPlus.
//
// Copyright (c) 2021-2022 AITSYS
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.
using DisCatSharp.Attributes;
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.CSharp;
using Microsoft.CodeAnalysis.CSharp.Syntax;
using Microsoft.CodeAnalysis.Diagnostics;
using System;
using System.Collections.Immutable;
using System.Linq;
namespace DisCatSharp.Analyzer
{
[DiagnosticAnalyzer(LanguageNames.CSharp)]
public class AttributeAnalyzer : DiagnosticAnalyzer
{
public const string DiagnosticIdPrefix = "DCS";
private static readonly LocalizableString Title = new LocalizableResourceString(nameof(Resources.AnalyzerTitle), Resources.ResourceManager, typeof(Resources));
private static readonly LocalizableString MessageFormat = new LocalizableResourceString(nameof(Resources.AnalyzerMessageFormat), Resources.ResourceManager, typeof(Resources));
private static readonly LocalizableString Description = new LocalizableResourceString(nameof(Resources.AnalyzerDescription), Resources.ResourceManager, typeof(Resources));
private const string Category = "Information";
private static readonly DiagnosticDescriptor ExperimentalRule = new DiagnosticDescriptor(DiagnosticIdPrefix + "0001", Title, MessageFormat, Category, DiagnosticSeverity.Warning, true, Description, "https://docs.discatsharp.tech/vs/analyzer/dcs/0001.html");
public override ImmutableArray SupportedDiagnostics { get { return ImmutableArray.Create(ExperimentalRule); } }
public override void Initialize(AnalysisContext context)
{
context.ConfigureGeneratedCodeAnalysis(GeneratedCodeAnalysisFlags.None);
context.EnableConcurrentExecution();
context.RegisterSyntaxNodeAction(AnalyzerInvocation, SyntaxKind.InvocationExpression);
}
private static void AnalyzerInvocation(SyntaxNodeAnalysisContext context)
{
var invocation = (InvocationExpressionSyntax)context.Node;
var declaration = context.SemanticModel.GetSymbolInfo(invocation, context.CancellationToken).Symbol;
var attributes = declaration.GetAttributes();
var attributeData = attributes.FirstOrDefault(attr => IsRequiredAttribute(context.SemanticModel, attr, typeof(ExperimentalAttribute)));
if (null == attributeData)
{
return;
}
var message = GetMessage(attributeData);
var diagnostic = Diagnostic.Create(ExperimentalRule, invocation.GetLocation(), declaration.Kind.ToString(), declaration.Name, message);
context.ReportDiagnostic(diagnostic);
}
static bool IsRequiredAttribute(SemanticModel semanticModel, AttributeData attribute, Type desiredAttributeType)
{
var desiredTypeNamedSymbol = semanticModel.Compilation.GetTypeByMetadataName(desiredAttributeType.FullName);
var result = attribute.AttributeClass.Equals(desiredTypeNamedSymbol, SymbolEqualityComparer.Default);
return result;
}
static string GetMessage(AttributeData attribute)
{
if (attribute.ConstructorArguments.Length < 1)
{
- return "Do not use in production";
+ return "Do not use in production.";
}
return attribute.ConstructorArguments[0].Value as string;
}
}
}
diff --git a/DisCatSharp.Tools/DisCatSharp.Tools.sln b/DisCatSharp.Tools/DisCatSharp.Tools.sln
index 1edccda7b..6220892de 100644
--- a/DisCatSharp.Tools/DisCatSharp.Tools.sln
+++ b/DisCatSharp.Tools/DisCatSharp.Tools.sln
@@ -1,53 +1,60 @@
Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.5.33103.201
MinimumVisualStudioVersion = 10.0.40219.1
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "DisCatSharp.Analyzer", "DisCatSharp.Analyzer", "{122968B7-2707-4FC2-819D-7E90B804A8E4}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DisCatSharp.Analyzer", "DisCatSharp.Analyzer\DisCatSharp.Analyzer\DisCatSharp.Analyzer.csproj", "{DA33A3DA-DD7F-4E16-B503-79581CCEA974}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DisCatSharp.Analyzer.Package", "DisCatSharp.Analyzer\DisCatSharp.Analyzer.Package\DisCatSharp.Analyzer.Package.csproj", "{B3122D6C-A0FE-42C3-9FCE-4A9789E66E1B}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DisCatSharp.Analyzer.Vsix", "DisCatSharp.Analyzer\DisCatSharp.Analyzer.Vsix\DisCatSharp.Analyzer.Vsix.csproj", "{AFEFCFB5-9110-423D-B022-A6AA46307B90}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Ref", "Ref", "{C88304B3-5BF3-4F25-A36A-42CC42BB2D3B}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DisCatSharp.Attributes", "..\DisCatSharp.Attributes\DisCatSharp.Attributes.csproj", "{FBEB40B3-4D62-462D-9F44-2B0BCDA0D2E7}"
EndProject
+Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DisCatSharp.Experimental", "..\DisCatSharp.Experimental\DisCatSharp.Experimental.csproj", "{239A4661-461C-4956-8512-2A3537F6A2E8}"
+EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{DA33A3DA-DD7F-4E16-B503-79581CCEA974}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{DA33A3DA-DD7F-4E16-B503-79581CCEA974}.Debug|Any CPU.Build.0 = Debug|Any CPU
{DA33A3DA-DD7F-4E16-B503-79581CCEA974}.Release|Any CPU.ActiveCfg = Release|Any CPU
{DA33A3DA-DD7F-4E16-B503-79581CCEA974}.Release|Any CPU.Build.0 = Release|Any CPU
{B3122D6C-A0FE-42C3-9FCE-4A9789E66E1B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{B3122D6C-A0FE-42C3-9FCE-4A9789E66E1B}.Debug|Any CPU.Build.0 = Debug|Any CPU
{B3122D6C-A0FE-42C3-9FCE-4A9789E66E1B}.Release|Any CPU.ActiveCfg = Release|Any CPU
{B3122D6C-A0FE-42C3-9FCE-4A9789E66E1B}.Release|Any CPU.Build.0 = Release|Any CPU
{AFEFCFB5-9110-423D-B022-A6AA46307B90}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{AFEFCFB5-9110-423D-B022-A6AA46307B90}.Debug|Any CPU.Build.0 = Debug|Any CPU
{AFEFCFB5-9110-423D-B022-A6AA46307B90}.Release|Any CPU.ActiveCfg = Release|Any CPU
{AFEFCFB5-9110-423D-B022-A6AA46307B90}.Release|Any CPU.Build.0 = Release|Any CPU
{FBEB40B3-4D62-462D-9F44-2B0BCDA0D2E7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{FBEB40B3-4D62-462D-9F44-2B0BCDA0D2E7}.Debug|Any CPU.Build.0 = Debug|Any CPU
{FBEB40B3-4D62-462D-9F44-2B0BCDA0D2E7}.Release|Any CPU.ActiveCfg = Release|Any CPU
{FBEB40B3-4D62-462D-9F44-2B0BCDA0D2E7}.Release|Any CPU.Build.0 = Release|Any CPU
+ {239A4661-461C-4956-8512-2A3537F6A2E8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {239A4661-461C-4956-8512-2A3537F6A2E8}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {239A4661-461C-4956-8512-2A3537F6A2E8}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {239A4661-461C-4956-8512-2A3537F6A2E8}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{DA33A3DA-DD7F-4E16-B503-79581CCEA974} = {122968B7-2707-4FC2-819D-7E90B804A8E4}
{B3122D6C-A0FE-42C3-9FCE-4A9789E66E1B} = {122968B7-2707-4FC2-819D-7E90B804A8E4}
{AFEFCFB5-9110-423D-B022-A6AA46307B90} = {122968B7-2707-4FC2-819D-7E90B804A8E4}
{FBEB40B3-4D62-462D-9F44-2B0BCDA0D2E7} = {C88304B3-5BF3-4F25-A36A-42CC42BB2D3B}
+ {239A4661-461C-4956-8512-2A3537F6A2E8} = {C88304B3-5BF3-4F25-A36A-42CC42BB2D3B}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {C9C1591B-8805-457A-BC51-D975D32BCC3A}
EndGlobalSection
EndGlobal