public void CacheMappingsHoldTypes() { ModuleScope scope = new ModuleScope(true); DefaultProxyBuilder builder = new DefaultProxyBuilder(scope); Type cp = builder.CreateClassProxyType(typeof(object), Type.EmptyTypes, ProxyGenerationOptions.Default); string savedPath = scope.SaveAssembly(); CrossAppDomainCaller.RunInOtherAppDomain(delegate(object[] args) { Assembly assembly = Assembly.LoadFrom((string)args[0]); CacheMappingsAttribute attribute = (CacheMappingsAttribute) assembly.GetCustomAttributes(typeof(CacheMappingsAttribute), false)[0]; Dictionary <CacheKey, string> entries = attribute.GetDeserializedMappings(); Assert.AreEqual(1, entries.Count); CacheKey key = new CacheKey(typeof(object), new Type[0], ProxyGenerationOptions.Default); Assert.IsTrue(entries.ContainsKey(key)); Assert.AreEqual(args[1], entries[key]); }, savedPath, cp.FullName); File.Delete(savedPath); }
private void AddCacheMappings(AssemblyBuilder builder) { Dictionary <CacheKey, string> mappings; using (Lock.ForReading()) { mappings = new Dictionary <CacheKey, string>(); foreach (var cacheEntry in typeCache) { mappings.Add(cacheEntry.Key, cacheEntry.Value.FullName); } } CacheMappingsAttribute.ApplyTo(builder, mappings); }
//#if FEATURE_SERIALIZATION private void AddCacheMappings(AssemblyBuilder builder) { Dictionary <CacheKey, string> mappings; using (Lock.ForReading()) { mappings = new Dictionary <CacheKey, string>(); foreach (var cacheEntry in typeCache) { // NOTE: using == returns invalid results. // we need to use Equals here for it to work properly if (builder.Equals(cacheEntry.Value.Assembly)) { mappings.Add(cacheEntry.Key, cacheEntry.Value.FullName); } } } CacheMappingsAttribute.ApplyTo(builder, mappings); }