private IAssembly ResolveAssembly(IAssemblyManager assemblyManager, IAssemblyCache assemblyCache)
        {
            IAssemblyReference assemblyReference = this.ParseAssemblyReference(this.assembly, assemblyManager);

            for (int i = 0; i < assemblyManager.Assemblies.Count; i++)
            {
                IAssembly assembly = assemblyManager.Assemblies[i];
                if (assembly.Equals(assemblyReference))
                {
                    return(assembly);
                }
            }

            if (assemblyCache != null)
            {
                string location = assemblyCache.QueryLocation(assemblyReference, null);
                if ((location != null) && (location.Length > 0))
                {
                    IAssembly assembly = assemblyManager.LoadFile(location);
                    return(assembly);
                }
            }

            return(null);
        }
Пример #2
0
        public bool InTargetAssembly(IType typeId)
        {
            IAssembly projectAssembly = this.ProjectAssembly;

            if (projectAssembly == null)
            {
                return(false);
            }
            return(projectAssembly.Equals(typeId.RuntimeAssembly));
        }
Пример #3
0
        private IEnumerable <IType> AllXamlRelevantTypesInAssembly(IAssembly assembly)
        {
            IProjectContext project         = this.ProjectContext;
            bool            supportInternal = assembly.Equals((object)project.ProjectAssembly);

            Type[] assemblyTypes = Type.EmptyTypes;
            try
            {
                assemblyTypes = AssemblyHelper.GetTypes(assembly);
            }
            catch (ReflectionTypeLoadException ex)
            {
                assemblyTypes = Type.EmptyTypes;
            }
            IAttachedPropertiesProvider attachedPropertiesProvider = this.AttachedPropertiesProvider;

            if (attachedPropertiesProvider == null)
            {
                throw new NotSupportedException();
            }
            Type[] allTypesWithAttachedProperties = (Type[])null;
            using (IAttachedPropertiesAccessToken token = attachedPropertiesProvider.AttachedProperties.Access())
            {
                CodeAidProvider.EnsurePreloadKnownAttachedProperties(token, project);
                allTypesWithAttachedProperties = Enumerable.ToArray <Type>(Enumerable.Select <IGrouping <Type, IAttachedPropertyMetadata>, Type>(Enumerable.GroupBy <IAttachedPropertyMetadata, Type>((IEnumerable <IAttachedPropertyMetadata>)token.AttachedPropertiesForAssembly(assembly.Name), (Func <IAttachedPropertyMetadata, Type>)(property => property.OwnerType)), (Func <IGrouping <Type, IAttachedPropertyMetadata>, Type>)(type => type.Key)));
            }
            foreach (Type type3 in assemblyTypes)
            {
                IType yieldedTypeId = (IType)null;
                try
                {
                    if (!type3.IsGenericType)
                    {
                        if (type3.IsVisible)
                        {
                            if (!type3.IsNested)
                            {
                                if (!typeof(Attribute).IsAssignableFrom(type3))
                                {
                                    if (!typeof(Exception).IsAssignableFrom(type3))
                                    {
                                        if (type3.IsPublic)
                                        {
                                            if (TypeUtilities.HasDefaultConstructor(type3, supportInternal) && TypeUtilities.CanCreateTypeInXaml((ITypeResolver)project, type3))
                                            {
                                                IType type1 = project.GetType(type3);
                                                if (JoltHelper.TypeSupported((ITypeResolver)project, (ITypeId)type1))
                                                {
                                                    yieldedTypeId = type1;
                                                }
                                            }
                                            else if (allTypesWithAttachedProperties != null)
                                            {
                                                if (OrderedListExtensions.GenericBinarySearch <Type, Type>(allTypesWithAttachedProperties, type3, (Func <Type, Type, int>)((type1, type2) => type1.Name.CompareTo(type2.Name))) >= 0)
                                                {
                                                    yieldedTypeId = project.GetType(type3);
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
                catch (FileNotFoundException ex)
                {
                }
                if (yieldedTypeId != null)
                {
                    yield return(yieldedTypeId);
                }
            }
        }
        private void ResolveDefaultStyle(SceneElement targetElement, object defaultStyleKey, bool allowDefaultStyle, out DocumentNode currentStyle, out bool isThemeStyle, out IList <DocumentCompositeNode> auxillaryResources)
        {
            IProjectContext      projectContext1      = this.SceneViewModel.ProjectContext;
            ThemeContentProvider themeContentProvider = this.DesignerContext.ThemeContentProvider;

            currentStyle       = (DocumentNode)null;
            isThemeStyle       = false;
            auxillaryResources = (IList <DocumentCompositeNode>)null;
            if (defaultStyleKey == null)
            {
                return;
            }
            IAssembly runtimeAssembly = targetElement.Type.RuntimeAssembly;
            IAssembly targetAssembly  = PlatformTypeHelper.GetTargetAssembly(targetElement.Type);
            Type      type1           = defaultStyleKey as Type;

            if (type1 != (Type)null)
            {
                ITypeId typeId = (ITypeId)projectContext1.GetType(type1);
                if (typeId != null)
                {
                    IType type2 = projectContext1.ResolveType(typeId);
                    runtimeAssembly = type2.RuntimeAssembly;
                    targetAssembly  = PlatformTypeHelper.GetTargetAssembly(type2);
                }
            }
            IAssembly designAssembly = projectContext1.GetDesignAssembly(runtimeAssembly);

            if (designAssembly != null)
            {
                currentStyle = themeContentProvider.GetThemeResourceFromAssembly(projectContext1, designAssembly, designAssembly, defaultStyleKey, out auxillaryResources);
                if (currentStyle != null)
                {
                    return;
                }
            }
            if (!PlatformTypes.IsPlatformType((ITypeId)this.Type))
            {
                foreach (IProject project in this.DesignerContext.ProjectManager.CurrentSolution.Projects)
                {
                    IProjectContext projectContext2 = (IProjectContext)ProjectXamlContext.GetProjectContext(project);
                    if (projectContext2 != null && runtimeAssembly.Equals((object)projectContext2.ProjectAssembly))
                    {
                        currentStyle = themeContentProvider.GetThemeResourceFromProject(project, defaultStyleKey, out auxillaryResources);
                        if (currentStyle != null)
                        {
                            return;
                        }
                    }
                }
            }
            else if (!allowDefaultStyle || projectContext1.PlatformMetadata.TargetFramework.Identifier == ".NETFramework" && projectContext1.PlatformMetadata.TargetFramework.Version < projectContext1.PlatformMetadata.RuntimeFramework.Version)
            {
                currentStyle = themeContentProvider.GetThemeResourceFromPlatform(projectContext1.Platform, defaultStyleKey, out auxillaryResources);
                if (currentStyle != null)
                {
                    isThemeStyle = true;
                    return;
                }
            }
            if (!projectContext1.IsCapabilitySet(PlatformCapability.IsWpf))
            {
                currentStyle = themeContentProvider.GetThemeResourceFromAssembly(projectContext1, runtimeAssembly, targetAssembly, defaultStyleKey, out auxillaryResources);
                isThemeStyle = currentStyle != null;
            }
            else
            {
                object resource = this.SceneViewModel.FindResource(defaultStyleKey);
                if (resource == null)
                {
                    return;
                }
                if (projectContext1 != null && projectContext1.IsCapabilitySet(PlatformCapability.VsmInToolkit) && (projectContext1.IsCapabilitySet(PlatformCapability.SupportsVisualStateManager) && projectContext1.PlatformMetadata.IsNullType((ITypeId)projectContext1.ResolveType(ProjectNeutralTypes.VisualStateManager))))
                {
                    IAssembly usingAssemblyName = projectContext1.Platform.Metadata.GetPlatformAssemblyUsingAssemblyName(targetElement.Type.RuntimeAssembly);
                    if (usingAssemblyName == null || !AssemblyHelper.IsPlatformAssembly(usingAssemblyName))
                    {
                        IDocumentContext documentContext = (IDocumentContext) new DocumentContext((IProjectContext) new ToolkitProjectContext(projectContext1), ((DocumentContext)this.SceneViewModel.Document.DocumentContext).DocumentLocator);
                        DocumentNode     node            = documentContext.CreateNode(resource.GetType(), resource);
                        if (ProjectAttributeHelper.GetDefaultStateRecords(this.Type, (ITypeResolver)(documentContext.TypeResolver as ProjectContext)).Count > 0 || (DocumentCompositeNode)node.FindFirst(new Predicate <DocumentNode>(this.SelectVisualStateGroupPredicate)) != null)
                        {
                            ToolkitHelper.AddToolkitReferenceIfNeeded((ITypeResolver)projectContext1, this.DesignerContext.ViewUpdateManager);
                        }
                    }
                }
                SceneNode sceneNode = this.SceneViewModel.CreateSceneNode(resource);
                if (!PlatformTypes.Style.IsAssignableFrom((ITypeId)sceneNode.Type))
                {
                    return;
                }
                currentStyle = sceneNode.DocumentNode;
            }
        }