Example #1
0
        public LiftedList <TChild> LoadIndirectChildren <TChild, TParentField>(
            TParentField parent,
            MetadataTable childTable,
            UnsafeSelector <TParentField> parentSelector,
            CreateObjectDelegate <TChild> factory
            ) where TChild : class
        {
            CheckDisposed();
            //It is valid for the child table to not be sorted, but I don't expect such a case to occur in practice.
            //I imagine that this could maybe happen with ENC, but we don't need to be able to decompile enc assemblies.
            //In either case, if we do end up needing to support assemblies with unsorted meta-data tables, then we should probably
            //add our best attempt at an efficent fallback in that case. For now we just throw.
            IsSorted(childTable).Assume("The generic param constraint table is not sorted.");

            var glb = GreatestLowerBound(
                childTable,
                parent,
                parentSelector
                );
            var lub = LeastUpperBound(
                childTable,
                parent,
                parentSelector
                );

            var ret = new LiftedList <TChild>(
                (glb - lub - 1).Value,
                index => GetRow(index.ToZB() + lub + 1, childTable),
                factory,
                () => IsDisposed
                );

            return(ret);
        }
Example #2
0
        /// <summary>
        ///
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="dr"></param>
        /// <param name="del"></param>
        /// <returns></returns>
        public static T CreateItem <T>(DataRow dr, CreateObjectDelegate <T> del)
        {
            T obj = default(T);

            if (dr != null)
            {
                if (del != null)
                {
                    obj = del.Invoke();
                }
                else
                {
                    obj = Activator.CreateInstance <T>();
                }
                if (obj != null)
                {
                    foreach (DataColumn column in dr.Table.Columns)
                    {
                        PropertyInfo prop = obj.GetType().GetProperty(column.ColumnName);
                        if (prop != null)
                        {
                            if (!object.ReferenceEquals(dr[column.ColumnName], DBNull.Value))
                            {
                                prop.SetValue(obj, dr[column.ColumnName], null);
                            }
                            else
                            {
                                prop.SetValue(obj, null, null);
                            }
                        }
                    }
                }
            }
            return(obj);
        }
Example #3
0
        public ConfigEntry(string sectionName, Type type, CreateObjectDelegate creater)
        {
            this.Name = sectionName;
            this.type = type;

            isSet = false;
            locker = new object();
            OnCreate = creater;
        }
Example #4
0
 public static LiftedValueTypeList <T> Create <T>(
     int itemCount,
     GetRowDelegate rowFectcher,
     CreateObjectDelegate <T> factory,
     Func <bool> disposedChecker
     ) where T : struct
 {
     return(new LiftedValueTypeList <T>(itemCount, rowFectcher, factory, disposedChecker));
 }
Example #5
0
        public ConfigEntry(string sectionName, Type type, CreateObjectDelegate creater)
        {
            this.Name = sectionName;
            this.type = type;

            isSet    = false;
            locker   = new object();
            OnCreate = creater;
        }
Example #6
0
        public ConfigEntry(string configName, CreateObjectDelegate creater, Type type)
        {
            this.ConfigName = configName;

            _isSet   = false;
            locker   = new object();
            Type     = type;
            OnCreate = creater;
        }
Example #7
0
 internal LiftedList(
     int itemCount,
     GetRowDelegate rowFectcher,
     CreateObjectDelegate <T> factory,
     Func <bool> disposedChecker
     ) : this(itemCount, rowFectcher, (pRow, index) => factory(pRow), disposedChecker)
 {
     factory.CheckNotNull("factory");
 }
Example #8
0
 public LiftedList <T> LoadDirectChildren <T>(
     MetadataTable childTable,
     GetTokenDelegate tokenSelector,
     CreateObjectDelegate <T> factory,
     MetadataTable parentTable,
     void *parentRow
     ) where T : class
 {
     factory.CheckNotNull("factory");
     return(LoadDirectChildren(childTable, tokenSelector, (pRow, index) => factory(pRow), parentTable, parentRow));
 }
Example #9
0
        private long TimeTestCreation(CreateObjectDelegate @delegate, TestObjectMarshall testObject, AppDomain appDomain, string exeAssembly)
        {
            _stopwatch.Reset();
            _stopwatch.Start();

            for (int i = 0; i < _repeatNumber; i++)
            {
                _mbrt = @delegate.Invoke(testObject, appDomain, exeAssembly);
            }

            _stopwatch.Stop();
            return(_stopwatch.ElapsedMilliseconds);
        }
Example #10
0
        public FileDecompresser(string lib7zPath, Stream zipStream)
        {
            this.safeHandle7zlib = Kernel32Dll.LoadLibrary(lib7zPath);
            if (this.safeHandle7zlib.IsInvalid)
            {
                throw new ArgumentException("不能正常调用指定的7z类库文件");
            }
            IntPtr createObjectPointer        = Kernel32Dll.GetProcAddress(this.safeHandle7zlib, "CreateObject");
            CreateObjectDelegate createObject = (CreateObjectDelegate)Marshal.GetDelegateForFunctionPointer(createObjectPointer, typeof(CreateObjectDelegate));
            List <ArchiveFormat> lstAF        = new List <ArchiveFormat>();

            this.archive7z = this.LoadArchiveFile(createObject, zipStream, lstAF);
        }
Example #11
0
 public ObjectPool(int maxObjects,
                   CreateObjectDelegate creator,
                   AllocObjectDelegate allocator,
                   DisposeObjectDelegate disposer)
 {
     if (creator == null)
     {
         throw new ArgumentNullException("CreateObjectDelegate creator");
     }
     _creator   = creator;
     _allocator = allocator;
     _disposer  = disposer;
     _pool      = new PoolEntry[maxObjects];
 }
Example #12
0
        /// <summary>
        ///
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="dt"></param>
        /// <param name="del"></param>
        /// <returns></returns>
        public static List <T> ConvertTo <T>(DataTable dt, CreateObjectDelegate <T> del)
        {
            if (dt == null)
            {
                return(null);
            }
            List <DataRow> rows = new List <DataRow>();

            foreach (DataRow row in dt.Rows)
            {
                rows.Add(row);
            }
            return(ConvertTo <T>(rows, del));
        }
Example #13
0
 //TODO: Factor GetMembers into a general helper in PEFile, so that it can also be used by
 //MethodDefinition.
 LiftedList <T> LoadDirectChildren <T>(
     MetadataTable childTable,
     GetTokenDelegate tokenSelector,
     CreateObjectDelegate <T> createObject
     ) where T : class
 {
     return(Module.PEFile.LoadDirectChildren(
                childTable,
                tokenSelector,
                createObject,
                MetadataTable.TypeDef,
                m_pRow
                ));
 }
Example #14
0
        private IInArchive LoadArchiveFile(CreateObjectDelegate createObject, Stream fs, List <ArchiveFormat> lstAF)
        {
            int signatureMaxLength = FormatSetting.FileSignatures.Values.OrderByDescending(v => v.Length).First().Length;

            byte[] signatureBuffer = new byte[signatureMaxLength];
            fs.Position = 0;
            int bytesRead        = fs.Read(signatureBuffer, 0, signatureMaxLength);
            var matchedSignature = FormatSetting.FileSignatures.Where(kv => signatureBuffer.Take(kv.Value.Length).SequenceEqual(kv.Value))
                                   .FirstOrDefault();

            if (matchedSignature.Key != ArchiveFormat.Undefined)
            {
                lstAF.Add(matchedSignature.Key);
            }
            var lstAFTemp = FormatSetting.FormatGuidMapping.Select(x => x.Key).Except(lstAF).ToList();

            lstAF.AddRange(lstAFTemp);
            ulong checkPos = 32 * 1024;

            this.Format = ArchiveFormat.Undefined;
            Guid interfaceId = typeof(IInArchive).GUID;

            foreach (var af in lstAF)
            {
                Guid   classId = FormatSetting.FormatGuidMapping[af];
                object tmp     = null;
                createObject.Invoke(ref classId, ref interfaceId, out tmp);
                IInArchive archive7z = tmp as IInArchive;
                fs.Position = 0;
                try
                {
                    int code = archive7z.Open(new QizFileStream(fs), ref checkPos, null);
                    if (code == 0)
                    {
                        this.Format = af;
                        return(archive7z);
                    }
                    Marshal.ReleaseComObject(archive7z);
                }
                catch (Exception)
                {
                    if (archive7z != null)
                    {
                        Marshal.ReleaseComObject(archive7z);
                    }
                }
            }
            return(null);
        }
Example #15
0
        /// <summary>
        ///
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="rows"></param>
        /// <param name="del"></param>
        /// <returns></returns>
        public static List <T> ConvertTo <T>(List <DataRow> rows,
                                             CreateObjectDelegate <T> del)
        {
            List <T> list = null;

            if (rows != null)
            {
                list = new List <T>();
                foreach (DataRow row in rows)
                {
                    T item = CreateItem <T>(row, del);
                    list.Add(item);
                }
            }
            return(list);
        }
Example #16
0
        private T CreateInterface <T>(Guid classId) where T : class
        {
            if (this.LibHandle == null)
            {
                throw new ObjectDisposedException("SevenZipFormat");
            }
            CreateObjectDelegate delegateForFunctionPointer = (CreateObjectDelegate)Marshal.GetDelegateForFunctionPointer(GetProcAddress(this.LibHandle, "CreateObject"), typeof(CreateObjectDelegate));

            if (delegateForFunctionPointer != null)
            {
                object obj2;
                Guid   gUID = typeof(T).GUID;
                delegateForFunctionPointer(ref classId, ref gUID, out obj2);
                return(obj2 as T);
            }
            return(default(T));
        }
        public IInArchive CreateInArchive(Guid classId)
        {
            if (this.sevenZipSafeHandle == null)
            {
                throw new ObjectDisposedException("SevenZipHandle");
            }

            IntPtr procAddress = Kernel32Dll.GetProcAddress(this.sevenZipSafeHandle, "CreateObject");
            CreateObjectDelegate createObject = (CreateObjectDelegate)Marshal.GetDelegateForFunctionPointer(procAddress, typeof(CreateObjectDelegate));

            object result;
            Guid   interfaceId = typeof(IInArchive).GUID;

            createObject(ref classId, ref interfaceId, out result);

            return(result as IInArchive);
        }
Example #18
0
        //build constructor
        public Pool(string namePool, int size, CreateObjectDelegate buildMethod)
        {
            this.namePool = "(Pool)" + namePool;
            PoolManager.Instance.CreateObjectPool(this.namePool);

            this.stack         = new Stack <T>();
            this.m_buildMethod = buildMethod;


            for (int i = 0; i < size; i++)
            {
                T objectPoolObj = this.m_buildMethod();
                this.Store(objectPoolObj);
            }


            PoolManager.Instance.AddPool(this.namePool, this);
        }
Example #19
0
        public FileDecompresser(string lib7zPath, string zipFilePath)
        {
            this.safeHandle7zlib = Kernel32Dll.LoadLibrary(lib7zPath);
            if (this.safeHandle7zlib.IsInvalid)
            {
                throw new ArgumentException("不能正常调用指定的7z类库文件");
            }
            IntPtr createObjectPointer        = Kernel32Dll.GetProcAddress(this.safeHandle7zlib, "CreateObject");
            CreateObjectDelegate createObject = (CreateObjectDelegate)Marshal.GetDelegateForFunctionPointer(createObjectPointer, typeof(CreateObjectDelegate));
            List <ArchiveFormat> lstAF        = new List <ArchiveFormat>();
            var fileExt = System.IO.Path.GetExtension(zipFilePath).ToLower();

            if (FormatSetting.ExtensionFormatMapping.ContainsKey(fileExt))
            {
                lstAF.Add(FormatSetting.ExtensionFormatMapping[fileExt]);
            }
            this.archive7z = this.LoadArchiveFile(createObject, System.IO.File.Open(zipFilePath, FileMode.Open, FileAccess.Read), lstAF);
        }
Example #20
0
        public IInArchive CreateInArchive(Guid classId)
        {
            object obj = null;

            if (this.LibHandle == null)
            {
                throw new ObjectDisposedException("SevenZipFormat");
            }
            CreateObjectDelegate delegateForFunctionPointer = (CreateObjectDelegate)Marshal.GetDelegateForFunctionPointer(SevenZipFormat.GetProcAddress(this.LibHandle, "CreateObject"), typeof(CreateObjectDelegate));

            if (delegateForFunctionPointer == null)
            {
                return(null);
            }
            Guid gUID = typeof(IInArchive).GUID;

            delegateForFunctionPointer(ref classId, ref gUID, out obj);
            return(obj as IInArchive);
        }
    /// <summary>
    /// 初始化
    /// </summary>
    public virtual void Initialize(int min, int max, CreateObjectDelegate createObjectFunc)
    {
        if (m_listObject != null)
        {
            DestroyAll();
        }

        m_listObject = new List<GameObject>();
        m_listState = new List<bool>();

        m_minObjCount = min;
        m_maxObjCount = max;
        m_createObjectFunc = createObjectFunc;

        // 初始时需要创建
        for (int i = 0; i < m_minObjCount; i++)
        {
            CreateOneObject();
        }
    }
Example #22
0
    /// <summary>
    /// 初始化
    /// </summary>
    public virtual void Initialize(int min, int max, CreateObjectDelegate createObjectFunc)
    {
        if (m_listObject != null)
        {
            DestroyAll();
        }

        m_listObject = new List <GameObject>();
        m_listState  = new List <bool>();

        m_minObjCount      = min;
        m_maxObjCount      = max;
        m_createObjectFunc = createObjectFunc;

        // 初始时需要创建
        for (int i = 0; i < m_minObjCount; i++)
        {
            CreateOneObject();
        }
    }
Example #23
0
        private T CreateInterface <T>(Guid classId) where T : class
        {
            if (LibHandle == null)
            {
                throw new ObjectDisposedException("SevenZipFormat");
            }

            CreateObjectDelegate CreateObject =
                (CreateObjectDelegate)Marshal.GetDelegateForFunctionPointer(
                    GetProcAddress(LibHandle, "CreateObject"), typeof(CreateObjectDelegate));

            if (CreateObject != null)
            {
                object Result;
                Guid   InterfaceId = typeof(T).GUID;
                CreateObject(ref classId, ref InterfaceId, out Result);
                return(Result as T);
            }

            return(null);
        }
Example #24
0
        IReadOnlyList <T> LoadDirectChildrenFromMap <T>(
            MetadataTable mapTable,
            MetadataTable childTable,
            UnsafeSelector <OneBasedIndex> parentSelector,
            GetTokenDelegate tokenSelector,
            CreateObjectDelegate <T> factory
            ) where T : class
        {
            //It is valid for the map table to not be sorted. However, I don't expect this to happen in
            //practice, so for now we throw an exception in that case. If we do end up needing to support
            //assemblies with unsorted meta-data tables then we will need to add some sort of fallback
            //here.
            mapTable.IsSorted(Module.PEFile).Assume("The table is not sorted");

            var mapIndex = mapTable.Find(
                (OneBasedIndex)MetadataTable.TypeDef.RowIndex(m_pRow, Module.PEFile),
                parentSelector,
                Module.PEFile
                );

            IReadOnlyList <T> ret;

            if (mapIndex < 0)
            {
                ret = new List <T>(0).AsReadOnly();
            }
            else
            {
                ret = Module.PEFile.LoadDirectChildren(
                    childTable,
                    tokenSelector,
                    factory,
                    mapTable,
                    mapTable.GetRow(mapIndex, Module.PEFile)
                    );
            }
            return(ret);
        }
Example #25
0
 public BaseDeserializer(Dispatcher dispatcher)
 {
     _objectCreator = new CreateObjectDelegate(DispCreateNewObject);
     _dispatcher = dispatcher;
 }
Example #26
0
        private long TimeTestCreation(CreateObjectDelegate @delegate ,TestObjectMarshall  testObject, AppDomain appDomain, string exeAssembly)
        {
            _stopwatch.Reset();
            _stopwatch.Start();

            for (int i = 0; i < _repeatNumber; i++ )
            {
                _mbrt = @delegate.Invoke(testObject, appDomain, exeAssembly);
            }

            _stopwatch.Stop();
            return _stopwatch.ElapsedMilliseconds;
        }
Example #27
0
 public BaseDeserializer(Dispatcher dispatcher)
 {
     _objectCreator = new CreateObjectDelegate(DispCreateNewObject);
     _dispatcher    = dispatcher;
 }