You've already forked linux-packaging-mono
Imported Upstream version 4.6.0.125
Former-commit-id: a2155e9bd80020e49e72e86c44da02a8ac0e57a4
This commit is contained in:
parent
a569aebcfd
commit
e79aa3c0ed
@@ -0,0 +1,71 @@
|
||||
// ==++==
|
||||
//
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
//
|
||||
// ==--==
|
||||
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace System.Runtime.CompilerServices
|
||||
{
|
||||
/// <summary>
|
||||
/// Indicates that the use of <see cref="System.Object"/> on a member is meant to be treated as a dynamically dispatched type.
|
||||
/// </summary>
|
||||
[AttributeUsage(AttributeTargets.Field | AttributeTargets.Parameter | AttributeTargets.Property | AttributeTargets.ReturnValue | AttributeTargets.Class | AttributeTargets.Struct)]
|
||||
public sealed class DynamicAttribute : Attribute
|
||||
{
|
||||
private readonly bool[] _transformFlags;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="DynamicAttribute"/> class.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// When used in an attribute specification, the default constructor is semantically
|
||||
/// equivalent to <c>DynamicAttribute({ true })</c>, and can be considered
|
||||
/// a shorthand for that expression. It should therefore only be used on an element
|
||||
/// of type <see cref="System.Object"/>.
|
||||
/// </remarks>
|
||||
public DynamicAttribute()
|
||||
{
|
||||
this._transformFlags = new bool[] { true };
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="DynamicAttribute"/> class.
|
||||
/// </summary>
|
||||
/// <param name="transformFlags">Specifies, in a prefix traversal of a type's
|
||||
/// construction, which <see cref="System.Object"/> occurrences are meant to
|
||||
/// be treated as a dynamically dispatched type.</param>
|
||||
/// <remarks>
|
||||
/// This constructor is meant to be used on types that are built on an underlying
|
||||
/// occurrence of <see cref="System.Object"/> that is meant to be treated dynamically.
|
||||
/// For instance, if <c>C</c> is a generic type with two type parameters, then a
|
||||
/// use of the constructed type<c>C<<see cref="System.Object"/>, <see cref="System.Object"/>></c>
|
||||
/// might be intended to treat the first type argument dynamically and the second
|
||||
/// normally, in which case the appropriate attribute specification should
|
||||
/// use a <c>transformFlags</c> value of <c>{ false, true, false }</c>.
|
||||
/// </remarks>
|
||||
public DynamicAttribute(bool[] transformFlags)
|
||||
{
|
||||
if (transformFlags == null)
|
||||
{
|
||||
throw new ArgumentNullException("transformFlags");
|
||||
}
|
||||
|
||||
this._transformFlags = transformFlags;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Specifies, in a prefix traversal of a type's
|
||||
/// construction, which <see cref="System.Object"/> occurrences are meant to
|
||||
/// be treated as a dynamically dispatched type.
|
||||
/// </summary>
|
||||
public IList<bool> TransformFlags
|
||||
{
|
||||
get
|
||||
{
|
||||
return Array.AsReadOnly(this._transformFlags);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
using System;
|
||||
using System.Linq.Expressions;
|
||||
|
||||
namespace System.Runtime.CompilerServices
|
||||
{
|
||||
// Kept for backwards compatibility. Unused
|
||||
[Obsolete("do not use this type", true)]
|
||||
public class ExecutionScope
|
||||
{
|
||||
public ExecutionScope Parent;
|
||||
public object[] Globals;
|
||||
public object[] Locals;
|
||||
|
||||
internal ExecutionScope()
|
||||
{
|
||||
Parent = null;
|
||||
Globals = null;
|
||||
Locals = null;
|
||||
}
|
||||
|
||||
public object[] CreateHoistedLocals()
|
||||
{
|
||||
throw new NotSupportedException();
|
||||
}
|
||||
|
||||
public Delegate CreateDelegate(int indexLambda, object[] locals)
|
||||
{
|
||||
throw new NotSupportedException();
|
||||
}
|
||||
|
||||
public Expression IsolateExpression(Expression expression, object[] locals)
|
||||
{
|
||||
throw new NotSupportedException();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,138 @@
|
||||
using System;
|
||||
using System.Security.Permissions;
|
||||
|
||||
namespace System.Runtime.InteropServices {
|
||||
|
||||
|
||||
[System.Security.SecuritySafeCritical]
|
||||
public class ComAwareEventInfo : System.Reflection.EventInfo {
|
||||
|
||||
#region private fields
|
||||
private System.Reflection.EventInfo _innerEventInfo;
|
||||
#endregion
|
||||
|
||||
#region ctor
|
||||
public ComAwareEventInfo(Type type, string eventName) {
|
||||
_innerEventInfo = type.GetEvent(eventName);
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region protected overrides
|
||||
#if FEATURE_NETCORE
|
||||
[System.Security.SecuritySafeCritical]
|
||||
#endif//FEATURE_NETCORE
|
||||
public override void AddEventHandler(object target, Delegate handler) {
|
||||
if (Marshal.IsComObject(target)) {
|
||||
// retrieve sourceIid and dispid
|
||||
Guid sourceIid;
|
||||
int dispid;
|
||||
GetDataForComInvocation(_innerEventInfo, out sourceIid, out dispid);
|
||||
|
||||
#if FEATURE_CAS_POLICY
|
||||
// now validate the caller can call into native and redirect to ComEventHelpers.Combine
|
||||
SecurityPermission perm = new SecurityPermission(SecurityPermissionFlag.UnmanagedCode);
|
||||
perm.Demand();
|
||||
#endif//FEATURE_CAS_POLICY
|
||||
System.Runtime.InteropServices.ComEventsHelper.Combine(target, sourceIid, dispid, handler);
|
||||
} else {
|
||||
// we are dealing with a managed object - just add the delegate through reflection
|
||||
_innerEventInfo.AddEventHandler(target, handler);
|
||||
}
|
||||
}
|
||||
|
||||
#if FEATURE_NETCORE
|
||||
[System.Security.SecuritySafeCritical]
|
||||
#endif//FEATURE_NETCORE
|
||||
public override void RemoveEventHandler(object target, Delegate handler) {
|
||||
if (Marshal.IsComObject(target)) {
|
||||
// retrieve sourceIid and dispid
|
||||
Guid sourceIid;
|
||||
int dispid;
|
||||
GetDataForComInvocation(_innerEventInfo, out sourceIid, out dispid);
|
||||
|
||||
#if FEATURE_CAS_POLICY
|
||||
// now validate the caller can call into native and redirect to ComEventHelpers.Combine
|
||||
SecurityPermission perm = new SecurityPermission(SecurityPermissionFlag.UnmanagedCode);
|
||||
perm.Demand();
|
||||
#endif//FEATURE_CAS_POLICY
|
||||
System.Runtime.InteropServices.ComEventsHelper.Remove(target, sourceIid, dispid, handler);
|
||||
} else {
|
||||
// we are dealing with a managed object - just add the delegate through relection
|
||||
_innerEventInfo.RemoveEventHandler(target, handler);
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region public overrides
|
||||
public override System.Reflection.EventAttributes Attributes {
|
||||
get { return _innerEventInfo.Attributes; }
|
||||
}
|
||||
|
||||
public override System.Reflection.MethodInfo GetAddMethod(bool nonPublic) {
|
||||
return _innerEventInfo.GetAddMethod(nonPublic);
|
||||
}
|
||||
|
||||
public override System.Reflection.MethodInfo GetRaiseMethod(bool nonPublic) {
|
||||
return _innerEventInfo.GetRaiseMethod(nonPublic);
|
||||
}
|
||||
|
||||
public override System.Reflection.MethodInfo GetRemoveMethod(bool nonPublic) {
|
||||
return _innerEventInfo.GetRemoveMethod(nonPublic);
|
||||
}
|
||||
|
||||
public override Type DeclaringType {
|
||||
get { return _innerEventInfo.DeclaringType; }
|
||||
}
|
||||
|
||||
public override object[] GetCustomAttributes(Type attributeType, bool inherit) {
|
||||
return _innerEventInfo.GetCustomAttributes(attributeType, inherit);
|
||||
}
|
||||
|
||||
public override object[] GetCustomAttributes(bool inherit) {
|
||||
return _innerEventInfo.GetCustomAttributes(inherit);
|
||||
}
|
||||
|
||||
public override bool IsDefined(Type attributeType, bool inherit) {
|
||||
return _innerEventInfo.IsDefined(attributeType, inherit);
|
||||
}
|
||||
|
||||
public override string Name {
|
||||
get { return _innerEventInfo.Name; }
|
||||
}
|
||||
|
||||
public override Type ReflectedType {
|
||||
get { return _innerEventInfo.ReflectedType; }
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region private methods
|
||||
|
||||
private static void GetDataForComInvocation(System.Reflection.EventInfo eventInfo, out Guid sourceIid, out int dispid) {
|
||||
object[] comEventInterfaces = eventInfo.DeclaringType.GetCustomAttributes(typeof(ComEventInterfaceAttribute), false);
|
||||
|
||||
if (comEventInterfaces == null || comEventInterfaces.Length == 0) {
|
||||
//
|
||||
throw new InvalidOperationException("event invocation for COM objects requires interface to be attributed with ComSourceInterfaceGuidAttribute");
|
||||
}
|
||||
|
||||
if (comEventInterfaces.Length > 1) {
|
||||
//
|
||||
throw new System.Reflection.AmbiguousMatchException("more than one ComSourceInterfaceGuidAttribute found");
|
||||
}
|
||||
|
||||
Type sourceItf = ((ComEventInterfaceAttribute)comEventInterfaces[0]).SourceInterface;
|
||||
Guid guid = sourceItf.GUID;
|
||||
|
||||
System.Reflection.MethodInfo methodInfo = sourceItf.GetMethod(eventInfo.Name);
|
||||
Attribute dispIdAttribute = Attribute.GetCustomAttribute(methodInfo, typeof(DispIdAttribute));
|
||||
if (dispIdAttribute == null) {
|
||||
//
|
||||
throw new InvalidOperationException("event invocation for COM objects requires event to be attributed with DispIdAttribute");
|
||||
}
|
||||
|
||||
sourceIid = guid;
|
||||
dispid = ((DispIdAttribute)dispIdAttribute).Value;
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user