Exemplo n.º 1
0
 void LoadSecondaryCacheFromAssemblies()
 {
     foreach (var assembly in AppDomain.CurrentDomain.GetAssemblies())
     {
         if (cachedAssemblies.Contains(assembly))
         {
             continue;
         }
         cachedAssemblies.Add(assembly);
         if (NoSwiftRuntimeReferences(assembly))
         {
             continue;
         }
         foreach (var t in assembly.GetTypes())
         {
             string swiftTypeName;
             if (SwiftTypeNameAttribute.TryGetSwiftName(t, out swiftTypeName))
             {
                 if (t.IsInterface)
                 {
                     var handle = SwiftProtocolTypeAttribute.DescriptorHandleForType(t);
                     if (handle != IntPtr.Zero)
                     {
                         protocolDescriptorCache.Add(handle, t);
                     }
                 }
                 else
                 {
                     secondaryCache.Add(swiftTypeName, t);
                 }
             }
         }
     }
 }
        public unsafe void Combine <T>(T thing) where T : ISwiftHashable
        {
            fixed(byte *thisSwiftDataPtr = StructMarshal.Marshaler.PrepareNominal(this))
            {
                IntPtr       thingIntPtr;
                ISwiftObject thingProxy       = null;
                var          thingIsSwiftable = StructMarshal.Marshaler.IsSwiftRepresentable(typeof(T));

                if (thingIsSwiftable)
                {
                    byte *thingPtr = stackalloc byte [StructMarshal.Marshaler.Strideof(typeof(T))];
                    thingIntPtr = new IntPtr(thingPtr);
                    StructMarshal.Marshaler.ToSwift(thing, thingIntPtr);
                }
                else
                {
                    if (SwiftProtocolTypeAttribute.IsAssociatedTypeProxy(typeof(ISwiftHashable)))
                    {
                        byte *thingPtr0 = stackalloc byte [IntPtr.Size];
                        thingIntPtr = new IntPtr(thingPtr0);
                        Marshal.WriteIntPtr(thingIntPtr, thingProxy.SwiftObject);
                    }
                    else
                    {
                        var   thingExistentialContainer = SwiftObjectRegistry.Registry.ExistentialContainerForProtocols(thing, typeof(ISwiftHashable));
                        byte *thingProtoPtr             = stackalloc byte [thingExistentialContainer.SizeOf];
                        thingIntPtr = new IntPtr(thingProtoPtr);
                        thingExistentialContainer.CopyTo(thingIntPtr);
                    }
                }
                NativeMethodsForSwiftHasher.PI_hasherCombine((IntPtr)thisSwiftDataPtr, thingIntPtr,
                                                             StructMarshal.Marshaler.Metatypeof(typeof(T), new Type [] { typeof(ISwiftHashable) }),
                                                             StructMarshal.Marshaler.ProtocolWitnessof(typeof(ISwiftHashable), typeof(T)));
                if (thingIsSwiftable)
                {
                    StructMarshal.Marshaler.ReleaseSwiftPointer(typeof(T), thingIntPtr);
                }
                else
                {
                    if (thingProxy != null)
                    {
                        StructMarshal.ReleaseSwiftObject(thingProxy);
                    }
                }
            }
        }