Skip to content

Commit

Permalink
Enable dynamically generated metadata views to implement internal int…
Browse files Browse the repository at this point in the history
…erfaces

Closes #9
  • Loading branch information
AArnott committed May 20, 2017
1 parent a4a4dbf commit 9d15d50
Showing 1 changed file with 5 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,14 @@
namespace Microsoft.VisualStudio.Composition
{
using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Globalization;
using System.Linq;
using System.Reflection;
using System.Reflection.Emit;
using System.Security;
using System.Threading;
using Microsoft.Internal;
using Microsoft.VisualStudio.Composition.Reflection;

/// <summary>
/// Constructs concrete types for metadata view interfaces.
Expand Down Expand Up @@ -90,6 +88,7 @@ internal static class MetadataViewGenerator
private static readonly ConstructorInfo ObjectCtor = typeof(object).GetConstructor(Type.EmptyTypes);

private static ModuleBuilder transparentProxyModuleBuilder;
private static SkipClrVisibilityChecks skipClrVisibilityChecks;

public delegate object MetadataViewFactory(IReadOnlyDictionary<string, object> metadata, IReadOnlyDictionary<string, object> defaultMetadata);

Expand All @@ -106,6 +105,7 @@ private static ModuleBuilder GetProxyModuleBuilder()
// make a new assemblybuilder and modulebuilder
var assemblyBuilder = CreateProxyAssemblyBuilder(typeof(SecurityTransparentAttribute).GetConstructor(Type.EmptyTypes));
transparentProxyModuleBuilder = assemblyBuilder.DefineDynamicModule("MetadataViewProxiesModule");
skipClrVisibilityChecks = new SkipClrVisibilityChecks(assemblyBuilder, transparentProxyModuleBuilder);
}

return transparentProxyModuleBuilder;
Expand Down Expand Up @@ -142,6 +142,8 @@ private static Type GenerateInterfaceViewProxyType(Type viewType)
Type[] interfaces = { viewType };

var proxyModuleBuilder = GetProxyModuleBuilder();
skipClrVisibilityChecks.SkipVisibilityChecksFor(viewType.GetTypeInfo());

proxyTypeBuilder = proxyModuleBuilder.DefineType(
string.Format(CultureInfo.InvariantCulture, "_proxy_{0}_{1}", viewType.FullName, Guid.NewGuid()),
TypeAttributes.Public,
Expand Down

0 comments on commit 9d15d50

Please sign in to comment.