예제 #1
0
        public CallbackNativeType(NativeTypeDesc desc)
            : base(desc)
        {
            Debug.Assert(typeof(Delegate).IsAssignableFrom(desc.Type));

            UnmanagedType[] allowed_unmanaged_types;
            if (desc.IsStructField)
            {
                // fields of delegate type can only marshal as function pointers
                allowed_unmanaged_types = MarshalType.DelegField;
            }
            else
            {
                // parameters of delegate type
                allowed_unmanaged_types = (desc.IsComInterop ? MarshalType.DelegC : MarshalType.DelegP);
            }

            switch (ValidateUnmanagedType(desc, allowed_unmanaged_types))
            {
            case UnmanagedType.FunctionPtr:
            {
                if (!desc.IsCallbackParam)
                {
                    // the "number one" mistake when marshaling delegate to function ptr
                    Log.Add(Errors.INFO_BewarePrematureDelegateRelease);
                }

                this.typeDefinition = FunctionPtrDefinition.Get(desc);
                break;
            }

            case UnmanagedType.Interface:
            {
                this.name         = DelegateInterfaceDefinition.InterfaceName;
                this.nameModifier = StructModifier;

                this.indirections++;

                Log.Add(Errors.INFO_SeeMscorlibTlbForInterface, this.name);

                this.typeDefinition = DelegateInterfaceDefinition.Get(desc);
                break;
            }

            default:
            {
                Debug.Fail(null);
                goto case UnmanagedType.FunctionPtr;
            }
            }
        }
예제 #2
0
 public ForwardDeclaration(FunctionPtrDefinition definition)
 {
     if (definition == null) throw new ArgumentNullException(nameof(definition));
     this.definition = definition;
 }
예제 #3
0
 public ForwardDeclaration(FunctionPtrDefinition definition)
 {
     Debug.Assert(definition != null);
     this.definition = definition;
 }