Skip to content
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

Some petit non-functionals #59

Merged
merged 4 commits into from
Sep 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 3 additions & 8 deletions AutomaticInterface/AutomaticInterfaceExample/DemoClass.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,12 @@
/// <summary>
/// Property Documentation will be copied
/// </summary>
public string Hello { get; set; } // included, get and set are copied to the interface when public

Check warning on line 21 in AutomaticInterface/AutomaticInterfaceExample/DemoClass.cs

View workflow job for this annotation

GitHub Actions / test

Non-nullable property 'Hello' must contain a non-null value when exiting constructor. Consider declaring the property as nullable.

Check warning on line 21 in AutomaticInterface/AutomaticInterfaceExample/DemoClass.cs

View workflow job for this annotation

GitHub Actions / test

Non-nullable property 'Hello' must contain a non-null value when exiting constructor. Consider declaring the property as nullable.

public string OnlyGet { get; } // included, get and set are copied to the interface when public

Check warning on line 23 in AutomaticInterface/AutomaticInterfaceExample/DemoClass.cs

View workflow job for this annotation

GitHub Actions / test

Non-nullable property 'OnlyGet' must contain a non-null value when exiting constructor. Consider declaring the property as nullable.

public string? NullableProperty { get; set; }
[IgnoreAutomaticInterface]
public string? AnotherGet { get; } // ignored with help of attribute

/// <summary>
/// Method Documentation will be copied
Expand All @@ -46,13 +47,7 @@
return "Ok";
}

[IgnoreAutomaticInterface]
public string IgnoreMethod(string x, string y) // // ignored because of attribute
{
return BMethod(x, y);
}

public Task<string?> ASync(string x, string y)
public Task<string> ASync(string x, string y)
{
return Task.FromResult("");
}
Expand All @@ -68,18 +63,18 @@
/// event Documentation will be copied
/// </summary>
#pragma warning disable S3264 // Events should be invoked
public event EventHandler ShapeChanged; // included

Check warning on line 66 in AutomaticInterface/AutomaticInterfaceExample/DemoClass.cs

View workflow job for this annotation

GitHub Actions / test

Non-nullable event 'ShapeChanged' must contain a non-null value when exiting constructor. Consider declaring the event as nullable.

Check warning on line 66 in AutomaticInterface/AutomaticInterfaceExample/DemoClass.cs

View workflow job for this annotation

GitHub Actions / test

The event 'DemoClass.ShapeChanged' is never used
#pragma warning restore S3264 // Events should be invoked

#pragma warning disable S3264 // Events should be invoked
#pragma warning disable IDE0051 // Remove unused private members
private event EventHandler ShapeChanged2; // ignored because not public

Check warning on line 71 in AutomaticInterface/AutomaticInterfaceExample/DemoClass.cs

View workflow job for this annotation

GitHub Actions / test

Non-nullable event 'ShapeChanged2' must contain a non-null value when exiting constructor. Consider declaring the event as nullable.

Check warning on line 71 in AutomaticInterface/AutomaticInterfaceExample/DemoClass.cs

View workflow job for this annotation

GitHub Actions / test

The event 'DemoClass.ShapeChanged2' is never used
#pragma warning restore IDE0051 // Remove unused private members
#pragma warning restore S3264 // Events should be invoked

public event EventHandler? ShapeChangedNullable; // included

Check warning on line 75 in AutomaticInterface/AutomaticInterfaceExample/DemoClass.cs

View workflow job for this annotation

GitHub Actions / test

The event 'DemoClass.ShapeChangedNullable' is never used

public event EventHandler<string?> ShapeChangedNullable2; // included

Check warning on line 77 in AutomaticInterface/AutomaticInterfaceExample/DemoClass.cs

View workflow job for this annotation

GitHub Actions / test

Non-nullable event 'ShapeChangedNullable2' must contain a non-null value when exiting constructor. Consider declaring the event as nullable.

Check warning on line 77 in AutomaticInterface/AutomaticInterfaceExample/DemoClass.cs

View workflow job for this annotation

GitHub Actions / test

The event 'DemoClass.ShapeChangedNullable2' is never used

private readonly int[] arr = new int[100];

Expand Down
14 changes: 0 additions & 14 deletions AutomaticInterface/TestNuget/RemoveThisOnNextVersionAttribute.cs

This file was deleted.

2 changes: 1 addition & 1 deletion AutomaticInterface/TestNuget/TestNuget.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="AutomaticInterface" Version="2.0.0">
<PackageReference Include="AutomaticInterface" Version="4.1.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
Expand Down
57 changes: 33 additions & 24 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,30 +26,29 @@ namespace AutomaticInterfaceExample
class DemoClass: IDemoClass // You Interface will get the Name I+classname, here IDemoclass.
// Generics, including constraints are allowed, too. E.g. MyClass<T> where T: class
{

/// <summary>
/// Property Documentation will be copied
/// </summary>
public string Hello { get; set; } // included, get and set are copied to the interface when public
public string Hello { get; set; } // included, get and set are copied to the interface when public

public string OnlyGet { get; } // included, get and set are copied to the interface when public

[IgnoreAutomaticInterface]
public string OnlyGet { get; } // ignored with help of attribute
[IgnoreAutomaticInterface]
public string? AnotherGet { get; } // ignored with help of attribute

/// <summary>
/// Method Documentation will be copied
/// </summary>
public string AMethod(string x, string y) // included
{
return BMethod(x,y);
return BMethod(x, y);
}

private string BMethod(string x, string y) // ignored because not public
{
return x + y;
}

public string CMethod<T, T1, T2, T3, T4>(string? x, string y) // included
where T : class
where T1 : struct
Expand All @@ -59,9 +58,14 @@ namespace AutomaticInterfaceExample
return "Ok";
}

public Task<string> ASync(string x, string y)
{
return Task.FromResult("");
}

public static string StaticProperty => "abc"; // static property, ignored

public static string StaticMethod() // static method, ignored
public static string StaticMethod() // static method, ignored
{
return "static" + DateTime.Now;
}
Expand Down Expand Up @@ -104,25 +108,30 @@ namespace AutomaticInterfaceExample
[GeneratedCode("AutomaticInterface", "")]
public partial interface IDemoClass
{
/// <summary>
/// Property Documentation will be copied
/// </summary>
/// <inheritdoc />
string Hello { get; set; }


/// <inheritdoc />
string OnlyGet { get; }

/// <summary>
/// Method Documentation will be copied
/// </summary>

/// <inheritdoc />
string AMethod(string x, string y);


/// <inheritdoc />
string CMethod<T, T1, T2, T3, T4>(string? x, string y) where T : class where T1 : struct where T3 : DemoClass where T4 : IDemoClass;

/// <summary>
/// event Documentation will be copied
/// </summary>

/// <inheritdoc />
System.Threading.Tasks.Task<string> ASync(string x, string y);

/// <inheritdoc />
event System.EventHandler ShapeChanged;


/// <inheritdoc />
event System.EventHandler? ShapeChangedNullable;

/// <inheritdoc />
event System.EventHandler<string?> ShapeChangedNullable2;

}
}
#nullable restore
Expand All @@ -131,7 +140,7 @@ namespace AutomaticInterfaceExample
## How to use it?

1. Install the nuget: `dotnet add package AutomaticInterface`.
2. Add `using AutomaticInterface;` or (Pro-tip) add `global using AutomaticInterface;` to you GlobalUsings.
2. Add `using AutomaticInterface;` or (Pro-tip) add `global using AutomaticInterface;` to your GlobalUsings.
3. Tag your class with the `[GenerateAutomaticInterface]` attribute.
4. The Interface should now be available.

Expand Down Expand Up @@ -170,7 +179,7 @@ Please make sure that you run [CSharpier](https://csharpier.com/) on the code fo
- mohummedibrahim for code and idea
- simonmckenzie for PR
- avtc for PR
- crwsolutions for PR
- crwsolutions for PRs
- FinnAngelo for PR

## Run tests
Expand All @@ -182,7 +191,7 @@ Should be simply a build and run Tests
### 4.1.0

- Adds ability to use `init` in property setters
-

### 4.0.0

- Breaking change in how generated code qualifies parameters, e.g. `async Task` should no longer generated as `System.Threading.Task`. I hope this does not break things
Expand Down
Loading