public void Assignment()
        {
            Context context = new Context();
            SimpleCacheWithContext <int, Context> cache = SimpleCache.CreateWithContext(context, (c) =>
            {
                c.Count++;
                return(42);
            });
            var cache2 = cache;

            Assert.Equal(0, context.Count);
            Assert.False(cache.Cached);
            Assert.Equal(42, cache.Value);
            Assert.Equal(1, context.Count);
            Assert.True(cache.Cached);
            Assert.False(cache2.Cached);
            Assert.Equal(42, cache2.Value);
            Assert.Equal(2, context.Count);
            Assert.True(cache2.Cached);
            var cache3 = cache;

            Assert.True(cache3.Cached);
            Assert.Equal(42, cache3.Value);
            Assert.Equal(2, context.Count);
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="PdbType"/> class.
 /// </summary>
 /// <param name="pdb">The PDB file reader.</param>
 /// <param name="typeIndex">Type index.</param>
 /// <param name="tagRecord">The tag record.</param>
 /// <param name="modifierOptions">The modifier options.</param>
 /// <param name="size">The type size in bytes.</param>
 internal PdbUserDefinedType(PdbFileReader pdb, TypeIndex typeIndex, TagRecord tagRecord, ModifierOptions modifierOptions, ulong size)
     : base(pdb, typeIndex, modifierOptions, tagRecord.Name.String, size)
 {
     TagRecord               = tagRecord;
     fieldsCache             = SimpleCache.CreateWithContext(this, CallEnumerateFields);
     staticFieldsCache       = SimpleCache.CreateWithContext(this, CallEnumerateStaticFields);
     baseClassesCache        = SimpleCache.CreateWithContext(this, CallEnumerateBaseClasses);
     virtualBaseClassesCache = SimpleCache.CreateWithContext(this, CallEnumerateVirtualBaseClasses);
 }
        public void Disposable()
        {
            Context context       = new Context();
            int     disposedCount = 0;

            using (SimpleCacheWithContext <DisposableAction, Context> cache = SimpleCache.CreateWithContext(context, (c) => new DisposableAction(() => disposedCount++)))
            {
                var v0 = cache.Value;

                cache.InvalidateCache();
                Assert.Equal(1, disposedCount);

                var v1 = cache.Value;
            }
            Assert.Equal(2, disposedCount);
        }
        public void SingleEvaluation()
        {
            Context context = new Context();
            SimpleCacheWithContext <int, Context> cache = SimpleCache.CreateWithContext(context, (c) =>
            {
                c.Count++;
                return(42);
            });

            Assert.Equal(0, context.Count);
            Assert.False(cache.Cached);
            Assert.Equal(42, cache.Value);
            Assert.Equal(1, context.Count);
            Assert.True(cache.Cached);
            Assert.Equal(42, cache.Value);
            Assert.Equal(1, context.Count);
            Assert.Single(cache, 42);
        }
        public void EvaluationAfterInvalidate()
        {
            Context context = new Context();
            SimpleCacheWithContext <int, Context> cache = SimpleCache.CreateWithContext(context, (c) =>
            {
                c.Count++;
                return(42);
            });

            Assert.Equal(0, context.Count);
            Assert.Equal(42, cache.Value);
            Assert.Equal(1, context.Count);
            Assert.Equal(42, cache.Value);
            Assert.Equal(1, context.Count);
            cache.InvalidateCache();
            Assert.Equal(1, context.Count);
            Assert.Equal(42, cache.Value);
            Assert.Equal(2, context.Count);
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="DbiModuleDescriptor"/> class.
        /// </summary>
        /// <param name="reader">Stream binary reader.</param>
        /// <param name="moduleList">Owning module list.</param>
        public DbiModuleDescriptor(IBinaryReader reader, DbiModuleList moduleList)
        {
            ModuleList     = moduleList;
            filesCache     = SimpleCache.CreateWithContext(this, CallEnumerateFiles);
            Header         = ModuleInfoHeader.Read(reader);
            ModuleName     = reader.ReadCString();
            ObjectFileName = reader.ReadCString();

            // Descriptors should be aligned at 4 bytes
            if (reader.Position % 4 != 0)
            {
                reader.Position += 4 - reader.Position % 4;
            }

            // Higher level API initialization
            moduleStreamCache          = SimpleCache.CreateWithContext(this, CallEnumerateModuleStream);
            localSymbolStreamCache     = SimpleCache.CreateWithContext(this, CallEnumerateLocalSymbolStream);
            debugSubsectionStreamCache = SimpleCache.CreateWithContext(this, CallEnumerateDebugSubsectionStream);
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="PdbType"/> class.
 /// </summary>
 /// <param name="pdb">The PDB file reader.</param>
 /// <param name="typeIndex">Type index.</param>
 /// <param name="enumRecord">The enum record.</param>
 /// <param name="modifierOptions">The modifier options.</param>
 internal PdbEnumType(PdbFileReader pdb, TypeIndex typeIndex, EnumRecord enumRecord, ModifierOptions modifierOptions)
     : base(pdb, typeIndex, enumRecord, modifierOptions, pdb[enumRecord.UnderlyingType].Size)
 {
     EnumRecord  = enumRecord;
     valuesCache = SimpleCache.CreateWithContext(this, CallEnumerateValues);
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="SymbolRecord"/> class.
 /// </summary>
 public SymbolRecord()
 {
     parentCache   = SimpleCache.CreateWithContext(this, getParentDelegate);
     childrenCache = SimpleCache.CreateWithContext(this, getChildrenDelegate);
 }
Exemple #9
0
 public DifferentCaches()
 {
     simpleCache            = SimpleCache.Create(() => 42);
     simpleCacheStruct      = SimpleCache.CreateStruct(() => 42);
     simpleCacheWithContext = SimpleCache.CreateWithContext(this, simpleCacheWithContextStaticDelegate);
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="PdbFunctionType"/> class.
 /// </summary>
 /// <param name="pdb">The PDB file reader.</param>
 /// <param name="typeIndex">Type index.</param>
 /// <param name="procedureRecord">The procedure record.</param>
 /// <param name="modifierOptions">The modifier options.</param>
 internal PdbFunctionType(PdbFileReader pdb, TypeIndex typeIndex, ProcedureRecord procedureRecord, ModifierOptions modifierOptions)
     : base(pdb, typeIndex, modifierOptions, string.Empty, 0)
 {
     ProcedureRecord = procedureRecord;
     argumentsCache  = SimpleCache.CreateWithContext(this, CallEnumerateArguments);
 }