Skip to content

Commit

Permalink
Merge pull request grpc#8438 from jtattermusch/csharp_compiler_warnings
Browse files Browse the repository at this point in the history
Fix a few C# compiler warnings
  • Loading branch information
jtattermusch authored Oct 22, 2016
2 parents 99e61f8 + 9f254c0 commit 8834095
Show file tree
Hide file tree
Showing 7 changed files with 58 additions and 6 deletions.
4 changes: 3 additions & 1 deletion src/csharp/Grpc.Auth/GoogleAuthInterceptors.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@

using System;
using System.Threading;
using System.Threading.Tasks;

using Google.Apis.Auth.OAuth2;
using Grpc.Core;
Expand Down Expand Up @@ -72,9 +73,10 @@ public static AsyncAuthInterceptor FromCredential(ITokenAccess credential)
public static AsyncAuthInterceptor FromAccessToken(string accessToken)
{
GrpcPreconditions.CheckNotNull(accessToken);
return new AsyncAuthInterceptor(async (context, metadata) =>
return new AsyncAuthInterceptor((context, metadata) =>
{
metadata.Add(CreateBearerTokenHeader(accessToken));
return Task.FromResult<object>(null);
});
}

Expand Down
1 change: 1 addition & 0 deletions src/csharp/Grpc.Core/DefaultCallInvoker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ public override AsyncDuplexStreamingCall<TRequest, TResponse> AsyncDuplexStreami
return Calls.AsyncDuplexStreamingCall(call);
}

/// <summary>Creates call invocation details for given method.</summary>
protected virtual CallInvocationDetails<TRequest, TResponse> CreateCall<TRequest, TResponse>(Method<TRequest, TResponse> method, string host, CallOptions options)
where TRequest : class
where TResponse : class
Expand Down
1 change: 0 additions & 1 deletion src/csharp/Grpc.Core/GrpcEnvironment.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ public class GrpcEnvironment

static ILogger logger = new NullLogger();

readonly object myLock = new object();
readonly GrpcThreadPool threadPool;
readonly DebugStats debugStats = new DebugStats();
readonly AtomicCounter cqPickerCounter = new AtomicCounter();
Expand Down
2 changes: 1 addition & 1 deletion src/csharp/Grpc.Core/Internal/InterceptingCallInvoker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ internal class InterceptingCallInvoker : CallInvoker
readonly Func<CallOptions, CallOptions> callOptionsInterceptor;

/// <summary>
/// Initializes a new instance of the <see cref="Grpc.Core.InterceptingCallInvoker"/> class.
/// Initializes a new instance of the <see cref="Grpc.Core.Internal.InterceptingCallInvoker"/> class.
/// </summary>
public InterceptingCallInvoker(CallInvoker callInvoker,
Func<string, string> hostInterceptor = null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,10 @@ private void NativeMetadataInterceptorHandler(IntPtr statePtr, IntPtr serviceUrl
{
var context = new AuthInterceptorContext(Marshal.PtrToStringAnsi(serviceUrlPtr),
Marshal.PtrToStringAnsi(methodNamePtr));
StartGetMetadata(context, callbackPtr, userDataPtr);
// Don't await, we are in a native callback and need to return.
#pragma warning disable 4014
GetMetadataAsync(context, callbackPtr, userDataPtr);
#pragma warning restore 4014
}
catch (Exception e)
{
Expand All @@ -87,7 +90,7 @@ private void NativeMetadataInterceptorHandler(IntPtr statePtr, IntPtr serviceUrl
}
}

private async Task StartGetMetadata(AuthInterceptorContext context, IntPtr callbackPtr, IntPtr userDataPtr)
private async Task GetMetadataAsync(AuthInterceptorContext context, IntPtr callbackPtr, IntPtr userDataPtr)
{
try
{
Expand Down
6 changes: 5 additions & 1 deletion src/csharp/Grpc.Core/Internal/UnmanagedLibrary.cs
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,11 @@ public T GetNativeMethodDelegate<T>(string methodName)
{
throw new MissingMethodException(string.Format("The native method \"{0}\" does not exist", methodName));
}
return Marshal.GetDelegateForFunctionPointer(ptr, typeof(T)) as T;
#if NETSTANDARD1_5
return Marshal.GetDelegateForFunctionPointer<T>(ptr); // non-generic version is obsolete
#else
return Marshal.GetDelegateForFunctionPointer(ptr, typeof(T)) as T; // generic version not available in .NET45
#endif
}

/// <summary>
Expand Down
43 changes: 43 additions & 0 deletions src/csharp/Grpc.Core/Metadata.cs
Original file line number Diff line number Diff line change
Expand Up @@ -95,24 +95,37 @@ internal Metadata Freeze()

#region IList members


/// <summary>
/// <see cref="T:IList`1"/>
/// </summary>
public int IndexOf(Metadata.Entry item)
{
return entries.IndexOf(item);
}

/// <summary>
/// <see cref="T:IList`1"/>
/// </summary>
public void Insert(int index, Metadata.Entry item)
{
GrpcPreconditions.CheckNotNull(item);
CheckWriteable();
entries.Insert(index, item);
}

/// <summary>
/// <see cref="T:IList`1"/>
/// </summary>
public void RemoveAt(int index)
{
CheckWriteable();
entries.RemoveAt(index);
}

/// <summary>
/// <see cref="T:IList`1"/>
/// </summary>
public Metadata.Entry this[int index]
{
get
Expand All @@ -128,55 +141,85 @@ public Metadata.Entry this[int index]
}
}

/// <summary>
/// <see cref="T:IList`1"/>
/// </summary>
public void Add(Metadata.Entry item)
{
GrpcPreconditions.CheckNotNull(item);
CheckWriteable();
entries.Add(item);
}

/// <summary>
/// <see cref="T:IList`1"/>
/// </summary>
public void Add(string key, string value)
{
Add(new Entry(key, value));
}

/// <summary>
/// <see cref="T:IList`1"/>
/// </summary>
public void Add(string key, byte[] valueBytes)
{
Add(new Entry(key, valueBytes));
}

/// <summary>
/// <see cref="T:IList`1"/>
/// </summary>
public void Clear()
{
CheckWriteable();
entries.Clear();
}

/// <summary>
/// <see cref="T:IList`1"/>
/// </summary>
public bool Contains(Metadata.Entry item)
{
return entries.Contains(item);
}

/// <summary>
/// <see cref="T:IList`1"/>
/// </summary>
public void CopyTo(Metadata.Entry[] array, int arrayIndex)
{
entries.CopyTo(array, arrayIndex);
}

/// <summary>
/// <see cref="T:IList`1"/>
/// </summary>
public int Count
{
get { return entries.Count; }
}

/// <summary>
/// <see cref="T:IList`1"/>
/// </summary>
public bool IsReadOnly
{
get { return readOnly; }
}

/// <summary>
/// <see cref="T:IList`1"/>
/// </summary>
public bool Remove(Metadata.Entry item)
{
CheckWriteable();
return entries.Remove(item);
}

/// <summary>
/// <see cref="T:IList`1"/>
/// </summary>
public IEnumerator<Metadata.Entry> GetEnumerator()
{
return entries.GetEnumerator();
Expand Down

0 comments on commit 8834095

Please sign in to comment.