示例#1
0
        internal static IntPtr DescriptorHandleForType(Type interfaceType)
        {
            // internal version, no exceptions
            var typeAttribute = interfaceType.GetCustomAttribute <SwiftProtocolTypeAttribute> ();

            if (typeAttribute == null)
            {
                return(IntPtr.Zero);
            }
            var desc = SwiftNominalTypeDescriptor.FromDylibFile(typeAttribute.LibraryName, DLOpenMode.Now, typeAttribute.ProtocolDescriptor);

            if (!desc.HasValue)
            {
                return(IntPtr.Zero);
            }
            return(desc.Value.Handle);
        }
示例#2
0
        public static SwiftNominalTypeDescriptor DescriptorForType(Type interfaceType)
        {
            Exceptions.ThrowOnNull(interfaceType, nameof(interfaceType));
            if (!interfaceType.IsInterface)
            {
                throw new SwiftRuntimeException($"Type {interfaceType.Name} is not an interface.");
            }
            var typeAttribute = interfaceType.GetCustomAttribute <SwiftProtocolTypeAttribute> ();

            if (typeAttribute == null)
            {
                throw new SwiftRuntimeException($"Type {interfaceType.Name} does not have a SwiftProtocolType attribute");
            }
            var desc = SwiftNominalTypeDescriptor.FromDylibFile(typeAttribute.LibraryName, DLOpenMode.Now, typeAttribute.ProtocolDescriptor);

            if (!desc.HasValue)
            {
                throw new SwiftRuntimeException($"Unable to find swift protocol type descriptor for {interfaceType.Name} with symbol {typeAttribute.ProtocolDescriptor} in file {typeAttribute.LibraryName}");
            }
            return(desc.Value);
        }