Skip to content
This repository has been archived by the owner on Oct 26, 2018. It is now read-only.

Commit

Permalink
Target .NET Standard 2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
Nate McMaster committed Jun 8, 2017
1 parent e4e3f22 commit cc834bf
Show file tree
Hide file tree
Showing 10 changed files with 48 additions and 24 deletions.
4 changes: 2 additions & 2 deletions build/common.props
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
<PackageReference Include="Internal.AspNetCore.Sdk" Version="$(InternalAspNetCoreSdkVersion)" PrivateAssets="All" />
</ItemGroup>

<ItemGroup Condition="'$(TargetFrameworkIdentifier)'=='.NETFramework' AND '$(OutputType)'=='library'">
<PackageReference Include="NETStandard.Library" Version="$(BundledNETStandardPackageVersion)" />
<ItemGroup Condition="'$(TargetFrameworkIdentifier)'=='.NETFramework'">
<PackageReference Include="NETStandard.Library.NETFramework" Version="$(NETStandardLibraryNETFrameworkVersion)" PrivateAssets="All" />
</ItemGroup>

</Project>
4 changes: 2 additions & 2 deletions build/dependencies.props
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<Project>
<PropertyGroup>
<AspNetCoreVersion>2.0.0-*</AspNetCoreVersion>
<CoreFxVersion>4.3.0</CoreFxVersion>
<CoreFxVersion>4.4.0-*</CoreFxVersion>
<InternalAspNetCoreSdkVersion>2.1.0-*</InternalAspNetCoreSdkVersion>
<NETStandardImplicitPackageVersion>$(BundledNETStandardPackageVersion)</NETStandardImplicitPackageVersion>
<NETStandardLibraryNETFrameworkVersion>2.0.0-*</NETStandardLibraryNETFrameworkVersion>
<RuntimeFrameworkVersion Condition="'$(TargetFramework)'=='netcoreapp2.0'">2.0.0-*</RuntimeFrameworkVersion>
<TestSdkVersion>15.3.0-*</TestSdkVersion>
<XunitVersion>2.3.0-beta2-*</XunitVersion>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public static class DiagnosticListenerExtensions
public static IDisposable SubscribeWithAdapter(this DiagnosticListener diagnostic, object target)
{
var adapter = new DiagnosticSourceAdapter(target);
return diagnostic.Subscribe(adapter, adapter.IsEnabled);
return diagnostic.Subscribe(adapter, s => adapter.IsEnabled(s));
}

public static IDisposable SubscribeWithAdapter(
Expand All @@ -19,7 +19,7 @@ public static IDisposable SubscribeWithAdapter(
Func<string, bool> isEnabled)
{
var adapter = new DiagnosticSourceAdapter(target, isEnabled);
return diagnostic.Subscribe(adapter, adapter.IsEnabled);
return diagnostic.Subscribe(adapter, s => adapter.IsEnabled(s));
}

public static IDisposable SubscribeWithAdapter(
Expand All @@ -28,7 +28,7 @@ public static IDisposable SubscribeWithAdapter(
Func<string, object, object, bool> isEnabled)
{
var adapter = new DiagnosticSourceAdapter(target, isEnabled);
return diagnostic.Subscribe(adapter, adapter.IsEnabled);
return diagnostic.Subscribe(adapter, s => adapter.IsEnabled(s));
}
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.

#if NETCOREAPP2_0 || NET461
using System;
using System.Reflection;
using System.Reflection.Emit;
Expand Down Expand Up @@ -49,4 +50,8 @@ public static string Save()
}
#endif
}
}
}
#elif NETSTANDARD2_0
#else
#error Target frameworks should be updated
#endif
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,14 @@ public TProxy CreateProxy<TProxy>(object obj)
return (TProxy)obj;
}

#if NETCOREAPP2_0 || NET461
var type = ProxyTypeEmitter.GetProxyType(_cache, typeof(TProxy), obj.GetType());
return (TProxy)Activator.CreateInstance(type, obj);
#elif NETSTANDARD2_0
throw new PlatformNotSupportedException("Cannot create a proxy type on this platform");
#else
#error Target frameworks should be updated
#endif
}
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.

#if NETCOREAPP2_0 || NET461
using System;
using System.Linq;
using System.Reflection;
Expand All @@ -20,13 +21,13 @@ public static class ProxyMethodEmitter

private static readonly AssemblyBuilder AssemblyBuilder;
private static readonly ModuleBuilder ModuleBuilder;

static ProxyMethodEmitter()
{
var name = new AssemblyName("Microsoft.Extensions.DiagnosticAdapter.ProxyMethodAssembly");
AssemblyBuilder = AssemblyBuilder.DefineDynamicAssembly(name, AssemblyBuilderAccess.RunAndSave);
ModuleBuilder = AssemblyBuilder.DefineDynamicModule(name.Name + ".dll");
}
}
#endif

private static readonly MethodInfo ProxyFactoryGenericMethod =
Expand Down Expand Up @@ -210,9 +211,9 @@ private static void AddToAssembly(
var typeBuilder = ModuleBuilder.DefineType(typeName, TypeAttributes.Abstract);
var methodBuilder = typeBuilder.DefineMethod(
"Proxy",
MethodAttributes.Public,
CallingConventions.Standard,
returnType: typeof(bool),
MethodAttributes.Public,
CallingConventions.Standard,
returnType: typeof(bool),
parameterTypes: new Type[] { typeof(object), typeof(object), typeof(IProxyFactory) });

var il = methodBuilder.GetILGenerator();
Expand All @@ -230,4 +231,8 @@ public static string Save()
}
#endif
}
}
}
#elif NETSTANDARD2_0
#else
#error Target frameworks should be updated
#endif
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.

#if NETCOREAPP2_0 || NET461
using System;
using System.Collections.Generic;
using System.Diagnostics;
Expand Down Expand Up @@ -116,7 +117,7 @@ internal static bool VerifyProxySupport(ProxyBuilderContext context, Tuple<Type,

if (targetType == sourceType || targetType.GetTypeInfo().IsAssignableFrom(sourceType.GetTypeInfo()))
{
// If we find a trivial conversion, then that will work.
// If we find a trivial conversion, then that will work.
return true;
}

Expand All @@ -128,7 +129,7 @@ internal static bool VerifyProxySupport(ProxyBuilderContext context, Tuple<Type,
return false;
}

// This is a combination we haven't seen before, and it *might* support proxy generation, so let's
// This is a combination we haven't seen before, and it *might* support proxy generation, so let's
// start trying.
context.Visited.Add(key, verificationResult);

Expand All @@ -154,7 +155,7 @@ internal static bool VerifyProxySupport(ProxyBuilderContext context, Tuple<Type,
VerificationResult elementResult;
context.Visited.TryGetValue(elementKey, out elementResult);

var proxyType = elementResult?.Type?.GetTypeInfo() ?? (TypeInfo)elementResult?.TypeBuilder;
var proxyType = elementResult?.Type?.GetTypeInfo() ?? elementResult?.TypeBuilder as Type;
if (proxyType == null)
{
// No proxy needed for elements.
Expand All @@ -164,7 +165,7 @@ internal static bool VerifyProxySupport(ProxyBuilderContext context, Tuple<Type,
else
{
// We need to proxy each of the elements. Let's generate a type.
GenerateProxyTypeForList(elementKey.Item1, elementKey.Item2, proxyType.AsType(), verificationResult);
GenerateProxyTypeForList(elementKey.Item1, elementKey.Item2, proxyType, verificationResult);
}

return true;
Expand Down Expand Up @@ -212,7 +213,7 @@ internal static bool VerifyProxySupport(ProxyBuilderContext context, Tuple<Type,
return false;
}

// To allow for flexible versioning, we want to allow missing properties in the source.
// To allow for flexible versioning, we want to allow missing properties in the source.
//
// For now we'll just store null, and later generate a stub getter that returns default(T).
var sourceProperty = sourceProperties.Where(p => p.Name == targetProperty.Name).FirstOrDefault();
Expand Down Expand Up @@ -492,3 +493,7 @@ internal class VerificationResult
}
}
}
#elif NETSTANDARD2_0
#else
#error Target frameworks should be updated
#endif
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,14 @@

<PropertyGroup>
<Description>Microsoft extension adapter feature to extend DiagnosticListener. Contains extension methods that extend System.Diagnostics.DiagnosticListener, and enables duck-typing based event handling by using dynamically generated proxy types.</Description>
<TargetFramework>netstandard1.1</TargetFramework>
<TargetFrameworks>netstandard2.0;netcoreapp2.0;net461</TargetFrameworks>
<NoWarn>$(NoWarn);CS1591</NoWarn>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<PackageTags>diagnosticadapter;diagnosticlistener;diagnostics</PackageTags>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="System.ComponentModel" Version="$(CoreFxVersion)" />
<PackageReference Include="System.Diagnostics.DiagnosticSource" Version="$(CoreFxVersion)" />
<PackageReference Include="System.Reflection.Emit" Version="$(CoreFxVersion)" />
<PackageReference Include="System.Reflection.Emit.Lightweight" Version="$(CoreFxVersion)" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,14 @@ public class ProxyDiagnosticSourceMethodAdapter : IDiagnosticSourceMethodAdapter

public Func<object, object, bool> Adapt(MethodInfo method, Type inputType)
{
#if NETCOREAPP2_0 || NET461
var proxyMethod = ProxyMethodEmitter.CreateProxyMethod(method, inputType);
return (listener, data) => proxyMethod(listener, data, _factory);
#elif NETSTANDARD2_0
throw new PlatformNotSupportedException("This platform does not support creating proxy types and methods");
#else
#error Target frameworks should be updated
#endif
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<Import Project="..\..\build\common.props" />

<PropertyGroup>
<TargetFrameworks>netcoreapp2.0;net46</TargetFrameworks>
<TargetFrameworks>netcoreapp2.0;net461</TargetFrameworks>
<TargetFrameworks Condition=" '$(OS)' != 'Windows_NT' ">netcoreapp2.0</TargetFrameworks>
</PropertyGroup>

Expand Down

0 comments on commit cc834bf

Please sign in to comment.