Skip to content
This repository has been archived by the owner on Jan 23, 2023. It is now read-only.
/ corefx Public archive

Commit

Permalink
Merge pull request #20585 from norek/master
Browse files Browse the repository at this point in the history
Remove dead code from System.ComonentModel.TypeConverter for issue #1
  • Loading branch information
stephentoub authored Jun 1, 2017
2 parents ff83c16 + d067d8d commit 2ad4073
Show file tree
Hide file tree
Showing 3 changed files with 1 addition and 241 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,6 @@ public void DangerousSet(int bit, bool value)
_data = value ? _data | bit : _data & ~bit;
}

public int Data => _data;

public static int CreateMask() => CreateMask(0);

public static int CreateMask(int previous)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -389,229 +389,5 @@ public static License Validate(Type type, object instance)

return lic;
}

// FxCop complaint about uninstantiated internal classes
// Re-activate if this class proves to be useful.

// This is a helper class that supports the CLR's IClassFactory2 marshaling
// support.
//
// When a managed object is exposed to COM, the CLR invokes
// AllocateAndValidateLicense() to set up the appropriate
// license context and instantiate the object.
//
// When the CLR consumes an unmanaged COM object, the CLR invokes
// GetCurrentContextInfo() to figure out the licensing context
// and decide whether to call ICF::CreateInstance() (designtime) or
// ICF::CreateInstanceLic() (runtime). In the former case, it also
// requests the class factory for a runtime license key and invokes
// SaveKeyInCurrentContext() to stash a copy in the current licensing
// context
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1812:AvoidUninstantiatedInternalClasses")]
private class LicenseInteropHelper
{
// Define some common HRESULTs.
private const int S_OK = 0;
private const int E_NOTIMPL = unchecked((int)0x80004001);
private const int CLASS_E_NOTLICENSED = unchecked((int)0x80040112);
private const int E_FAIL = unchecked((int)0x80000008);

private DesigntimeLicenseContext _helperContext;
private LicenseContext _savedLicenseContext;
private Type _savedType;

// The CLR invokes this whenever a COM client invokes
// IClassFactory::CreateInstance() or IClassFactory2::CreateInstanceLic()
// on a managed managed that has a LicenseProvider custom attribute.
//
// If we are being entered because of a call to ICF::CreateInstance(),
// fDesignTime will be "true".
//
// If we are being entered because of a call to ICF::CreateInstanceLic(),
// fDesignTime will be "false" and bstrKey will point a non-null
// license key.
private static object AllocateAndValidateLicense(RuntimeTypeHandle rth, IntPtr bstrKey, int fDesignTime)
{
Type type = Type.GetTypeFromHandle(rth);
CLRLicenseContext licensecontext = new CLRLicenseContext(fDesignTime != 0 ? LicenseUsageMode.Designtime : LicenseUsageMode.Runtime, type);
if (fDesignTime == 0 && bstrKey != (IntPtr)0)
{
licensecontext.SetSavedLicenseKey(type, Marshal.PtrToStringBSTR(bstrKey));
}


try
{
return LicenseManager.CreateWithContext(type, licensecontext);
}
catch (LicenseException lexp)
{
throw new COMException(lexp.Message, CLASS_E_NOTLICENSED);
}
}

// The CLR invokes this whenever a COM client invokes
// IClassFactory2::RequestLicKey on a managed class.
//
// This method should return the appropriate HRESULT and set pbstrKey
// to the licensing key.
private static int RequestLicKey(RuntimeTypeHandle rth, ref IntPtr pbstrKey)
{
Type type = Type.GetTypeFromHandle(rth);
License license;
string licenseKey;

// license will be null, since we passed no instance,
// however we can still retrieve the "first" license
// key from the file. This really will only
// work for simple COM-compatible license providers
// like LicFileLicenseProvider that don't require the
// instance to grant a key.
//
if (!LicenseManager.ValidateInternalRecursive(LicenseManager.CurrentContext,
type,
null,
false,
out license,
out licenseKey))
{
return E_FAIL;
}

if (licenseKey == null)
{
return E_FAIL;
}

pbstrKey = Marshal.StringToBSTR(licenseKey);

if (license != null)
{
license.Dispose();
license = null;
}

return S_OK;
}


// The CLR invokes this whenever a COM client invokes
// IClassFactory2::GetLicInfo on a managed class.
//
// COM normally doesn't expect this function to fail so this method
// should only throw in the case of a catastrophic error (stack, memory, etc.)
private void GetLicInfo(RuntimeTypeHandle rth, ref int pRuntimeKeyAvail, ref int pLicVerified)
{
pRuntimeKeyAvail = 0;
pLicVerified = 0;

Type type = Type.GetTypeFromHandle(rth);
License license;
string licenseKey;

if (_helperContext == null)
{
_helperContext = new DesigntimeLicenseContext();
}
else
{
_helperContext.savedLicenseKeys.Clear();
}

if (LicenseManager.ValidateInternalRecursive(_helperContext, type, null, false, out license, out licenseKey))
{
if (_helperContext.savedLicenseKeys.Contains(type.AssemblyQualifiedName))
{
pRuntimeKeyAvail = 1;
}

if (license != null)
{
license.Dispose();
license = null;

pLicVerified = 1;
}
}
}

// The CLR invokes this when instantiating an unmanaged COM
// object. The purpose is to decide which classfactory method to
// use.
//
// If the current context is design time, the CLR will
// use ICF::CreateInstance().
//
// If the current context is runtime and the current context
// exposes a non-null license key and the COM object supports
// IClassFactory2, the CLR will use ICF2::CreateInstanceLic().
// Otherwise, the CLR will use ICF::CreateInstance.
//
// Arguments:
// ref int fDesignTime: on exit, this will be set to indicate
// the nature of the current license context.
// ref int bstrKey: on exit, this will point to the
// licensekey saved inside the license context.
// (only if the license context is runtime)
// RuntimeTypeHandle rth: the managed type of the wrapper
private void GetCurrentContextInfo(ref int fDesignTime, ref IntPtr bstrKey, RuntimeTypeHandle rth)
{
_savedLicenseContext = LicenseManager.CurrentContext;
_savedType = Type.GetTypeFromHandle(rth);
if (_savedLicenseContext.UsageMode == LicenseUsageMode.Designtime)
{
fDesignTime = 1;
bstrKey = (IntPtr)0;
}
else
{
fDesignTime = 0;
String key = _savedLicenseContext.GetSavedLicenseKey(_savedType, null);
bstrKey = Marshal.StringToBSTR(key);
}
}

// The CLR invokes this when instantiating a licensed COM
// object inside a designtime license context.
// It's purpose is to save away the license key that the CLR
// retrieved using RequestLicKey(). This license key can be NULL.
private void SaveKeyInCurrentContext(IntPtr bstrKey)
{
if (bstrKey != (IntPtr)0)
{
_savedLicenseContext.SetSavedLicenseKey(_savedType, Marshal.PtrToStringBSTR(bstrKey));
}
}

// A private implementation of a LicenseContext used for instantiating
// managed objects exposed to COM. It has memory for the license key
// of a single Type.
internal class CLRLicenseContext : LicenseContext
{
private Type _type;
private string _key;

public CLRLicenseContext(LicenseUsageMode usageMode, Type type)
{
UsageMode = usageMode;
_type = type;
}

public override LicenseUsageMode UsageMode { get; }


public override string GetSavedLicenseKey(Type type, Assembly resourceAssembly)
{
return type == _type ? _key : null;
}
public override void SetSavedLicenseKey(Type type, string key)
{
if (type == _type)
{
_key = key;
}
}
}
}
}
}
16 changes: 1 addition & 15 deletions src/System.ComponentModel.TypeConverter/src/System/misc.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ namespace System.ComponentModel
internal static class CompModSwitches
{
private static volatile BooleanSwitch commonDesignerServices;
private static volatile TraceSwitch eventLog;

public static BooleanSwitch CommonDesignerServices
{
Expand All @@ -67,19 +66,6 @@ public static BooleanSwitch CommonDesignerServices
}
return commonDesignerServices;
}
}

public static TraceSwitch EventLog
{
get
{
if (eventLog == null)
{
eventLog = new TraceSwitch("EventLog", "Enable tracing for the EventLog component.");
}
return eventLog;
}
}

}
}
}

0 comments on commit 2ad4073

Please sign in to comment.