Exemplo n.º 1
0
        private static bool TryLoadMembers()
        {
            // .NET Core, .NET 4.6+
            s_lazyCreateFromFile = LightUpHelper.GetMethod(
                s_lazyMemoryMappedFileType,
                "CreateFromFile",
                FileStreamReadLightUp.FileStreamType.Value,
                typeof(string),
                typeof(long),
                s_lazyMemoryMappedFileAccessType,
                s_lazyHandleInheritabilityType,
                typeof(bool)
                );

            // .NET < 4.6
            if (s_lazyCreateFromFile == null)
            {
                if (s_lazyMemoryMappedFileSecurityType != null)
                {
                    s_lazyCreateFromFileClassic = LightUpHelper.GetMethod(
                        s_lazyMemoryMappedFileType,
                        "CreateFromFile",
                        FileStreamReadLightUp.FileStreamType.Value,
                        typeof(string),
                        typeof(long),
                        s_lazyMemoryMappedFileAccessType,
                        s_lazyMemoryMappedFileSecurityType,
                        s_lazyHandleInheritabilityType,
                        typeof(bool));
                }

                if (s_lazyCreateFromFileClassic == null)
                {
                    return(false);
                }
            }

            s_lazyCreateViewAccessor = LightUpHelper.GetMethod(
                s_lazyMemoryMappedFileType,
                "CreateViewAccessor",
                typeof(long),
                typeof(long),
                s_lazyMemoryMappedFileAccessType);

            if (s_lazyCreateViewAccessor == null)
            {
                return(false);
            }

            s_lazySafeMemoryMappedViewHandle = s_lazyMemoryMappedViewAccessorType.GetTypeInfo().GetDeclaredProperty("SafeMemoryMappedViewHandle");
            if (s_lazySafeMemoryMappedViewHandle == null)
            {
                return(false);
            }

            // .NET Core, .NET 4.5.1+
            s_lazyPointerOffset = s_lazyMemoryMappedViewAccessorType.GetTypeInfo().GetDeclaredProperty("PointerOffset");

            // .NET < 4.5.1
            if (s_lazyPointerOffset == null)
            {
                s_lazyInternalViewField = s_lazyMemoryMappedViewAccessorType.GetTypeInfo().GetDeclaredField("m_view");
                if (s_lazyInternalViewField == null)
                {
                    return(false);
                }

                s_lazyInternalPointerOffset = s_lazyInternalViewField.FieldType.GetTypeInfo().GetDeclaredProperty("PointerOffset");
                if (s_lazyInternalPointerOffset == null)
                {
                    return(false);
                }
            }

            return(true);
        }
Exemplo n.º 2
0
 private static bool TryLoadType(string typeName, string modernAssembly, string classicAssembly, out Type type)
 {
     type = LightUpHelper.GetType(typeName, modernAssembly, classicAssembly);
     return(type != null);
 }