Skip to content

Commit

Permalink
Updated null checking and variable declaration for modern language:
Browse files Browse the repository at this point in the history
IDE0016  C# Null check can be simplified
IDE0018  C# Variable declaration can be inlined
IDE0044 ... well, yes, why not for this place :)
+CA1063 another way
  • Loading branch information
3F committed Aug 12, 2018
1 parent c8c9903 commit 6d4e368
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 15 deletions.
3 changes: 2 additions & 1 deletion Conari/Conari.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<NoWarn>IDE1006</NoWarn>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
Expand All @@ -30,7 +31,7 @@
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<DocumentationFile>bin\Release\Conari.XML</DocumentationFile>
<NoWarn>CS1591</NoWarn>
<NoWarn>CS1591,IDE1006</NoWarn>
</PropertyGroup>
<PropertyGroup>
<SignAssembly>true</SignAssembly>
Expand Down
17 changes: 11 additions & 6 deletions Conari/ConariL.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@

namespace net.r_eg.Conari
{
[SuppressMessage("Microsoft.Design", "CA1063:ImplementIDisposableCorrectly", Justification = "Bug. False positive. The IDisposable is already implemented correctly !")]
public class ConariL: Provider, IConari, ILoader, IProvider, IBinder, IDisposable
{
protected IConfig config;
Expand Down Expand Up @@ -171,11 +170,7 @@ public ConariL(string lib, string prefix = null)

protected void init(IConfig cfg)
{
if(cfg == null) {
throw new ArgumentNullException("Configuration cannot be null.");
}

config = cfg;
config = cfg ?? throw new ArgumentNullException("Configuration cannot be null.");
Mangling = cfg.Mangling;

if(cfg.LazyLoading) {
Expand All @@ -200,5 +195,15 @@ private void onConventionChanged(object sender, DataArgs<CallingConvention> e)
DLR = newDLR(e.Data);
LSender.Send(sender, $"DLR has been updated with new CallingConvention: {e.Data}", Message.Level.Info);
}

#region IDisposable

// CA1063
protected override void Dispose(bool disposing)
{
base.Dispose(disposing);
}

#endregion
}
}
5 changes: 1 addition & 4 deletions Conari/Core/ExVar.cs
Original file line number Diff line number Diff line change
Expand Up @@ -198,10 +198,7 @@ public override IEnumerable<string> GetDynamicMemberNames()

public ExVar(IProvider p)
{
if(p == null) {
throw new ArgumentException("Provider cannot be null.");
}
provider = p;
provider = p ?? throw new ArgumentException("Provider cannot be null.");
}

protected dynamic getFieldDLR(Type type, string variable)
Expand Down
2 changes: 1 addition & 1 deletion Conari/Extensions/ObjectExtension.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public static object Invoke(this Object obj, string name, BindingFlags flags, pa

return new Act(
mi != null,
mi?.Invoke(obj, (args == null) ? new object[0] : args)
mi?.Invoke(obj, args ?? new object[0])
);
},
obj, name);
Expand Down
3 changes: 1 addition & 2 deletions Conari/Native/Core/BReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -142,8 +142,7 @@ public bool tryNext(Type type, int tsize, out dynamic value)
/// <exception cref="IndexOutOfRangeException"></exception>
public dynamic next(Type type, int tsize)
{
dynamic value;
if(tryNext(type, tsize, out value)) {
if(tryNext(type, tsize, out dynamic value)) {
return value;
}

Expand Down
2 changes: 1 addition & 1 deletion Conari/Native/NativeData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public class NativeData
{
protected Fields map = new Fields();
protected byte[] local;
private IntPtr pointer;
private readonly IntPtr pointer;

/// <summary>
/// Get raw-data of complex native structure.
Expand Down
1 change: 1 addition & 0 deletions ConariTest/ConariTest.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<PlatformTarget>x86</PlatformTarget>
<NoWarn>IDE1006</NoWarn>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
Expand Down

0 comments on commit 6d4e368

Please sign in to comment.