Пример #1
0
        /// <summary>
        /// Retrieves the <see cref="Type"/> corresponding to the <paramref name="codeClass"/>.
        /// </summary>
        /// <exception cref="InvalidOperationException">An <see cref="ITypeDiscoveryService"/> cannot be
        /// retrieved for the project the class lives in.</exception>
        /// <exception cref="InvalidOperationException">The <paramref name="codeClass"/> has not been
        /// compiled into the project still.</exception>
        public static Type ToType(CodeClass codeClass)
        {
            Guard.ArgumentNotNull(codeClass, "codeClass");

            string           typeFullName = codeClass.FullName;
            Type             returnType   = null;
            IServiceProvider provider     = ToServiceProvider(codeClass.DTE);

            DynamicTypeService typeService = VsHelper.GetService <DynamicTypeService>(provider, true);

            IVsHierarchy hier = ToHierarchy(codeClass.ProjectItem.ContainingProject);

            ITypeResolutionService typeResolution = typeService.GetTypeResolutionService(hier);

            if (typeResolution == null)
            {
                throw new InvalidOperationException(String.Format(
                                                        CultureInfo.CurrentCulture,
                                                        Properties.Resources.ServiceMissing,
                                                        typeof(ITypeResolutionService)));
            }

            returnType = typeResolution.GetType(typeFullName);
            if (returnType == null)
            {
                throw new InvalidOperationException(String.Format(
                                                        CultureInfo.CurrentCulture,
                                                        Properties.Resources.ClassNotCompiledYet,
                                                        typeFullName,
                                                        codeClass.ProjectItem.get_FileNames(1)));
            }

            return(returnType);
        }
Пример #2
0
        private NemerleCodeBehindEventBinder GetBinder(EnvDTE.ProjectItem projectItem)
        {
            if (projectItem == null)
            {
                return(null);
            }

            if (projectItem.FileCodeModel == null)
            {
                return(null);
            }

            ITypeResolutionService typeResolutionService = null;

            if (this._serviceProvider != null)
            {
                DynamicTypeService typeService = this._serviceProvider.GetService(typeof(DynamicTypeService)) as DynamicTypeService;
                if (typeService != null)
                {
                    typeResolutionService = typeService.GetTypeResolutionService(this._hierarchy);
                }
            }

            return(new NemerleCodeBehindEventBinder(projectItem.FileCodeModel, typeResolutionService));
        }
Пример #3
0
        public NemerleContainedLanguage(IVsTextBufferCoordinator bufferCoordinator, NemerleIntellisenseProvider intellisenseProject, uint itemId, IVsHierarchy pHierarchy)
        {
            if (null == bufferCoordinator)
            {
                throw new ArgumentNullException("bufferCoordinator");
            }
            if (null == intellisenseProject)
            {
                throw new ArgumentNullException("intellisenseProject");
            }
            _hierarchy = pHierarchy;

            object projectItem = null;

            pHierarchy.GetProperty(itemId, (int)__VSHPROPID.VSHPROPID_ExtObject, out projectItem);

            _projectItem = projectItem as EnvDTE.ProjectItem;

            EnvDTE.Property prop = _projectItem.Properties.Item("FullPath");
            if (prop != null)
            {
                _filePath = prop.Value as string;
            }

            var project = _projectItem.ContainingProject as NemerleOAProject;

            if (project != null)
            {
                _projectInfo = ((NemerleProjectNode)project.Project).ProjectInfo;
            }

            _typeResolutionService = null;
            DynamicTypeService typeService = LanguageService.GetService(typeof(DynamicTypeService)) as DynamicTypeService;

            if (typeService != null)
            {
                _typeResolutionService = typeService.GetTypeResolutionService(this._hierarchy);
            }

            this.bufferCoordinator   = bufferCoordinator;
            this.intellisenseProject = intellisenseProject;
            this.itemId = itemId;

            // Make sure that the secondary buffer uses the IronPython language service.
            IVsTextLines buffer;

            ErrorHandler.ThrowOnFailure(bufferCoordinator.GetSecondaryBuffer(out buffer));

            Guid languageGuid;

            this.GetLanguageServiceID(out languageGuid);
            ErrorHandler.ThrowOnFailure(buffer.SetLanguageServiceID(ref languageGuid));

            _documentClosingEventHandler = new _dispDocumentEvents_DocumentClosingEventHandler(OnDocumentClosing);
        }
Пример #4
0
        string GetModuleType(Project project, CodeClass codeClass)
        {
            IVsSolution        solution     = (IVsSolution)GetService(typeof(IVsSolution));
            DynamicTypeService typeResolver = (DynamicTypeService)GetService(typeof(DynamicTypeService));

            IVsHierarchy hierarchy = null;

            solution.GetProjectOfUniqueName(project.UniqueName, out hierarchy);

            var typeResolutionService = typeResolver.GetTypeResolutionService(hierarchy);

            return(typeResolutionService.GetType(codeClass.FullName).AssemblyQualifiedName);
        }
        public Type GetTypeFromString(string type)
        {
            IServiceProvider serviceProvider = new ServiceProvider(_dte2 as Microsoft.VisualStudio.OLE.Interop.IServiceProvider);

            DynamicTypeService typeService = serviceProvider.GetService(typeof(DynamicTypeService)) as DynamicTypeService;

            IVsSolution sln = serviceProvider.GetService(typeof(IVsSolution)) as IVsSolution;

            IVsHierarchy hier;

            sln.GetProjectOfUniqueName(_dte2.ActiveDocument.ProjectItem.ContainingProject.UniqueName, out hier);

            return(typeService.GetTypeResolutionService(hier).GetType(type, true));
        }
        private Type ResolveType(Project prj, CodeType codeType)
        {
            try
            {
                DynamicTypeService typeService = this.serviceProvider.GetService(typeof(DynamicTypeService)) as DynamicTypeService;
                IVsSolution        solution    = this.serviceProvider.GetService(typeof(IVsSolution)) as IVsSolution;

                IVsHierarchy hierarchy;
                solution.GetProjectOfUniqueName(prj.UniqueName, out hierarchy);

                ITypeResolutionService resolutionService = typeService.GetTypeResolutionService(hierarchy);
                return(resolutionService.GetType(codeType.FullName));
            }
            catch
            {
                return(null);
            }
        }
        private void ValidateTypeName(string typeName)
        {
            DynamicTypeService typeService = (DynamicTypeService)site.GetService(typeof(DynamicTypeService));

            Debug.Assert(typeService != null, "No dynamic type service registered.");

            IVsHierarchy hier = DteHelper.GetCurrentSelection(site);

            Debug.Assert(hier != null, "No active hierarchy is selected.");

            ITypeResolutionService resolution = typeService.GetTypeResolutionService(hier);
            Type type = resolution.GetType(TypeHelper.ParseGenericType(typeName));

            if (type == null)
            {
                throw new TypeLoadException(string.Format(CultureInfo.CurrentUICulture, Resources.TypeNameValidatorTypeNotFound, typeName));
            }
        }
Пример #8
0
        public Type GetTypeFromString(string type)
        {
            IServiceProvider   serviceProvider = new ServiceProvider(_dte2 as Microsoft.VisualStudio.OLE.Interop.IServiceProvider);
            DynamicTypeService typeService     = serviceProvider.GetService(typeof(DynamicTypeService)) as DynamicTypeService;
            IVsSolution        solution        = serviceProvider.GetService(typeof(IVsSolution)) as IVsSolution;

            if (solution == null)
            {
                return(null);
            }

            IVsHierarchy hierarchy;

            solution.GetProjectOfUniqueName(_dte2.ActiveDocument.ProjectItem.ContainingProject.UniqueName, out hierarchy);

            Type returnType = typeService?.GetTypeResolutionService(hierarchy)?.GetType(type, false);

            return(returnType);
        }
Пример #9
0
        /// <summary>
        /// Converts the specified value object to a <see cref="T:System.String"></see> object.
        /// </summary>
        /// <param name="context">An <see cref="T:System.ComponentModel.ITypeDescriptorContext"></see> that provides a format context.</param>
        /// <param name="culture">The <see cref="T:System.Globalization.CultureInfo"></see> to use.</param>
        /// <param name="value">The <see cref="T:System.Object"></see> to convert.</param>
        /// <returns>
        /// An <see cref="T:System.Object"></see> that represents the converted value.
        /// </returns>
        /// <exception cref="T:System.NotSupportedException">The conversion could not be performed. </exception>
        public override object ConvertFrom(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value)
        {
            if (value is string)
            {
                DynamicTypeService typeService = (DynamicTypeService)context.GetService(typeof(DynamicTypeService));
                Debug.Assert(typeService != null, "No dynamic type service registered.");

                IVsHierarchy hier = DteHelper.GetCurrentSelection(context);
                Debug.Assert(hier != null, "No active hierarchy is selected.");

                ITypeResolutionService resolution = typeService.GetTypeResolutionService(hier);
                Type type = resolution.GetType(value.ToString());
                return(type);
            }
            else
            {
                return(base.ConvertFrom(context, culture, value));
            }
        }
Пример #10
0
        private ITypeResolutionService GetResolutionService(Project currentProject)
        {
            DynamicTypeService typeService = ServiceProvider.GetService(typeof(DynamicTypeService)) as DynamicTypeService;

            if (typeService == null)
            {
                throw new InvalidOperationException("No dynamic type service registered.");
            }

            IVsSolution vsSolution = (IVsSolution)ServiceProvider.GetService(typeof(IVsSolution));

            vsSolution.GetProjectOfUniqueName(currentProject.UniqueName, out IVsHierarchy vsHierarchy);
            if (vsHierarchy == null)
            {
                throw new InvalidOperationException("No active hierarchy is selected.");
            }

            return(typeService.GetTypeResolutionService(vsHierarchy));
        }