Ejemplo n.º 1
0
 public static Lazy <Type> ReadLazyTypeForPart(this IDictionary <string, object> cache, Func <Assembly> assemblyLoader)
 {
     if (assemblyLoader == null)
     {
         return(LazyServices.MakeLazy(
                    () => cache.ReadMember <Type>(AttributedCacheServices.CacheKeys.PartType, (Type)null, (Func <Assembly>)null),
                    cache.ReadDictionary <object>(AttributedCacheServices.CacheKeys.PartType)
                    ));
     }
     else
     {
         return(LazyServices.MakeLazy(
                    () => cache.ReadMember <Type>(AttributedCacheServices.CacheKeys.PartType, (Type)null, assemblyLoader)));
     }
 }
Ejemplo n.º 2
0
        public void StrongTypeLazyWrapperFactory()
        {
            Func <Func <object>, object, object> factory = LazyServices.CreateStronglyTypedLazyFactory(typeof(string), null);
            bool executed = false;
            var  lazy     = (Lazy <string>)factory(
                () =>
            {
                executed = true;
                return("hi");
            },
                5);

            Assert.IsType(typeof(Lazy <string>), lazy);
            Assert.False(executed);
            Assert.Equal("hi", lazy.Value);
            Assert.True(executed);
        }
Ejemplo n.º 3
0
        public void StrongTypeLazyWrapperFactoryWithMetadata()
        {
            Func <Func <object>, object, object> factory = LazyServices.CreateStronglyTypedLazyFactory(typeof(string), typeof(int));
            bool executed = false;
            var  lazy     = (Lazy <string, int>)factory(
                () =>
            {
                executed = true;
                return("hi");
            },
                5);

            Assert.False(executed);
            Assert.Equal(5, lazy.Metadata);
            Assert.False(executed);
            Assert.Equal("hi", lazy.Value);
            Assert.True(executed);
        }
        public static ComposablePartDefinition ReadPartDefinition(IDictionary <string, object> cache, Func <ComposablePartDefinition, IEnumerable <ImportDefinition> > importsCreator, Func <ComposablePartDefinition, IEnumerable <ExportDefinition> > exportsCreator, Func <Assembly> assemblyLoader)
        {
            Assumes.NotNull(cache);

            Lazy <Type> partType = cache.ReadLazyTypeForPart(assemblyLoader);

            ComposablePartDefinition part = null;

            part = ReflectionModelServices.CreatePartDefinition(
                partType,
                cache.ReadValue <bool>(AttributedCacheServices.CacheKeys.IsDisposalRequired, false),
                LazyServices.MakeLazy(() => importsCreator(part)),
                LazyServices.MakeLazy(() => exportsCreator(part)),
                cache.ReadLazyMetadata(),
                null);

            return(part);
        }
Ejemplo n.º 5
0
 public static Lazy <IDictionary <string, object> > ReadLazyMetadata(this IDictionary <string, object> cache)
 {
     Assumes.NotNull(cache);
     return(LazyServices.MakeLazy(() => cache.ReadDictionary <object>(AttributedCacheServices.CacheKeys.Metadata)));
 }
Ejemplo n.º 6
0
 public static Lazy <ParameterInfo> ReadLazyParameter(this IDictionary <string, object> cache, Lazy <Type> defaultType)
 {
     Assumes.NotNull(cache);
     return(LazyServices.MakeLazy(() => cache.ReadParameter(defaultType)));
 }