当前位置: 首页>>代码示例>>C#>>正文


C# IServiceProvider.GetService方法代码示例

本文整理汇总了C#中IServiceProvider.GetService方法的典型用法代码示例。如果您正苦于以下问题:C# IServiceProvider.GetService方法的具体用法?C# IServiceProvider.GetService怎么用?C# IServiceProvider.GetService使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在IServiceProvider的用法示例。


在下文中一共展示了IServiceProvider.GetService方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: BuildUrl

 public static string BuildUrl(IServiceProvider serviceProvider, Control owner, string initialUrl, string caption, string filter, UrlBuilderOptions options)
 {
     string baseUrl = string.Empty;
     string str2 = null;
     IDesignerHost host = (IDesignerHost) serviceProvider.GetService(typeof(IDesignerHost));
     if (host != null)
     {
         WebFormsRootDesigner designer = host.GetDesigner(host.RootComponent) as WebFormsRootDesigner;
         if (designer != null)
         {
             baseUrl = designer.DocumentUrl;
         }
     }
     if (baseUrl.Length == 0)
     {
         IWebFormsDocumentService service = (IWebFormsDocumentService) serviceProvider.GetService(typeof(IWebFormsDocumentService));
         if (service != null)
         {
             baseUrl = service.DocumentUrl;
         }
     }
     IWebFormsBuilderUIService service2 = (IWebFormsBuilderUIService) serviceProvider.GetService(typeof(IWebFormsBuilderUIService));
     if (service2 != null)
     {
         str2 = service2.BuildUrl(owner, initialUrl, baseUrl, caption, filter, options);
     }
     return str2;
 }
开发者ID:Reegenerator,项目名称:Sample-CustomizeDatasetCS,代码行数:28,代码来源:UrlBuilder.cs

示例2: EditValue

 public override object EditValue(ITypeDescriptorContext context, IServiceProvider provider, object value)
 {
     if (provider != null)
     {
         IWindowsFormsEditorService edSvc = (IWindowsFormsEditorService) provider.GetService(typeof(IWindowsFormsEditorService));
         if ((edSvc == null) || (context.Instance == null))
         {
             return value;
         }
         if (this.columnTypePicker == null)
         {
             this.columnTypePicker = new FilterColumnTypePicker();
         }
         FilterColumnCollectionDialog.ListBoxItem instance = (FilterColumnCollectionDialog.ListBoxItem)context.Instance;
         IDesignerHost service = (IDesignerHost) provider.GetService(typeof(IDesignerHost));
         ITypeDiscoveryService discoveryService = null;
         if (service != null)
         {
             discoveryService = (ITypeDiscoveryService) service.GetService(typeof(ITypeDiscoveryService));
         }
         this.columnTypePicker.Start(edSvc, discoveryService, instance.FilterColumn.GetType());
         edSvc.DropDownControl(this.columnTypePicker);
         if (this.columnTypePicker.SelectedType != null)
         {
             value = this.columnTypePicker.SelectedType;
         }
     }
     return value;
 }
开发者ID:BachelorEric,项目名称:ModelFirst,代码行数:29,代码来源:FilterColumnTypeEditor.cs

示例3: EditValue

        /// <summary>
        /// <para>Edits the specified object's value using the editor style indicated by <see cref="GetEditStyle"/>. This should be a <see cref="DpapiSettings"/> object.</para>
        /// </summary>
        /// <param name="context"><para>An <see cref="ITypeDescriptorContext"/> that can be used to gain additional context information.</para></param>
        /// <param name="provider"><para>An <see cref="IServiceProvider"/> that this editor can use to obtain services.</para></param>
        /// <param name="value"><para>The object to edit. This should be a <see cref="Password"/> object.</para></param>
        /// <returns><para>The new value of the <see cref="Password"/> object.</para></returns>
        /// <seealso cref="UITypeEditor.EditValue(ITypeDescriptorContext, IServiceProvider, object)"/>
        public override object EditValue(ITypeDescriptorContext context, IServiceProvider provider, object value)
        {
            Debug.Assert(provider != null, "No service provider; we cannot edit the value");
            if (provider != null)
            {
                IWindowsFormsEditorService edSvc = (IWindowsFormsEditorService)provider.GetService(typeof(IWindowsFormsEditorService));

                Debug.Assert(edSvc != null, "No editor service; we cannot edit the value");
                if (edSvc != null)
                {
                    IWindowsFormsEditorService service =(IWindowsFormsEditorService)provider.GetService(typeof(IWindowsFormsEditorService));
                    using (PasswordEditorUI dialog = new PasswordEditorUI())
                    {
                        if (DialogResult.OK == service.ShowDialog(dialog))
                        {
                            return new Password(dialog.Password);
                        }
                        else
                        {
                            return value;
                        }
                    }
                }
            }
            return value;
        }
开发者ID:bnantz,项目名称:NCS-V1-1,代码行数:34,代码来源:PasswordEditor.cs

示例4: DocumentProvider

        /// <summary>
        /// Creates a document provider.
        /// </summary>
        /// <param name="projectContainer">Project container for the documents.</param>
        /// <param name="serviceProvider">Service provider</param>
        /// <param name="documentTrackingService">An optional <see cref="VisualStudioDocumentTrackingService"/> to track active and visible documents.</param>
        public DocumentProvider(
            IVisualStudioHostProjectContainer projectContainer,
            IServiceProvider serviceProvider,
            VisualStudioDocumentTrackingService documentTrackingService)
        {
            var componentModel = (IComponentModel)serviceProvider.GetService(typeof(SComponentModel));

            _projectContainer = projectContainer;
            this._documentTrackingServiceOpt = documentTrackingService;
            this._runningDocumentTable = (IVsRunningDocumentTable4)serviceProvider.GetService(typeof(SVsRunningDocumentTable));
            this._editorAdaptersFactoryService = componentModel.GetService<IVsEditorAdaptersFactoryService>();
            this._contentTypeRegistryService = componentModel.GetService<IContentTypeRegistryService>();
            _textUndoHistoryRegistry = componentModel.GetService<ITextUndoHistoryRegistry>();
            _textManager = (IVsTextManager)serviceProvider.GetService(typeof(SVsTextManager));

            _fileChangeService = (IVsFileChangeEx)serviceProvider.GetService(typeof(SVsFileChangeEx));

            var shell = (IVsShell)serviceProvider.GetService(typeof(SVsShell));
            if (shell == null)
            {
                // This can happen only in tests, bail out.
                return;
            }

            var runningDocumentTableForEvents = (IVsRunningDocumentTable)_runningDocumentTable;
            Marshal.ThrowExceptionForHR(runningDocumentTableForEvents.AdviseRunningDocTableEvents(new RunningDocTableEventsSink(this), out _runningDocumentTableEventCookie));
        }
开发者ID:XieShuquan,项目名称:roslyn,代码行数:33,代码来源:DocumentProvider.cs

示例5: VisualEffect

        protected VisualEffect(IServiceProvider services, string effectAsset,
            int effectLayerCount, IEnumerable<RenderTargetLayerType> requiredRenderTargets)
        {
            if (services == null)
                throw new ArgumentNullException("services");
            if (effectAsset == null)
                throw new ArgumentNullException("effectAsset");
            if (requiredRenderTargets == null)
                throw new ArgumentNullException("requiredRenderTargets");
            if (effectLayerCount < 0)
                throw new ArgumentOutOfRangeException("affectedLayers", "Parameter should have non-negative value.");

            renderer = (Renderer)services.GetService(typeof(Renderer));
            resourceManager = (ResourceManager)services.GetService(typeof(ResourceManager));

            this.requiredRenderTargets = requiredRenderTargets;
            this.effectLayerCount = effectLayerCount > 0 ? effectLayerCount : renderer.KBufferManager.Configuration.LayerCount;

            effect = resourceManager.Load<Effect>(effectAsset);
            effectTechnique = effect.GetTechniqueByName(VisualEffectTechniqueName);
            if (!effectTechnique.IsValid)
                throw new ArgumentException(
                    string.Format("Given effect asset '{0}' does not contain technique {1}.", effectAsset, VisualEffectTechniqueName),
                    "effectAsset");
        }
开发者ID:TheProjecter,项目名称:romantiquex,代码行数:25,代码来源:VisualEffect.cs

示例6: DependentBasicGameComponent

        /// <summary>
        /// Initializes a new DependentBasicGameComponent.
        /// </summary>
        /// <param name="services">The service provider containing the required and optional services.</param>
        protected DependentBasicGameComponent(IServiceProvider services)
        {
            PropertyInfo[] properties = GetType().GetProperties();

            foreach (PropertyInfo property in properties)
            {
                object[] attributes = property.GetCustomAttributes(true);
                foreach (object attr in attributes)
                {
                    RequiredServiceAttribute reqService = attr as RequiredServiceAttribute;
                    OptionalServiceAttribute optService = attr as OptionalServiceAttribute;

                    if (reqService != null)
                    {
                        Type serviceType = reqService.ServiceType ?? property.PropertyType;
                        object service = services.GetService(serviceType);
                        if (service == null)
                            throw new Exception(string.Format(serviceNotFoundExceptionFormat, serviceType));

                        property.SetValue(this, service, null);
                    }
                    else if (optService != null)
                    {
                        Type serviceType = optService.ServiceType ?? property.PropertyType;
                        object service = services.GetService(serviceType);

                        if (service != null)
                            property.SetValue(this, service, null);
                    }
                }
            }
        }
开发者ID:northdocks,项目名称:ggj-2010-honeymoon,代码行数:36,代码来源:DependentGameComponent.cs

示例7: Execute

        public void Execute(IServiceProvider serviceProvider)
        {
            IPluginExecutionContext context = (IPluginExecutionContext)serviceProvider.GetService(typeof(IPluginExecutionContext));

            if (context.MessageName.ToLower() != "create") return;

            if (!context.InputParameters.Contains("Target") && !(context.InputParameters["Target"] is Entity)) return;

            Entity entity = (Entity)context.InputParameters["Target"];

            if (entity.LogicalName != "contact") return;

            if (!entity.Contains("ivg_Districtid")) return;

            #region Process
            IOrganizationServiceFactory serviceFactory = (IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory));
            IOrganizationService service = serviceFactory.CreateOrganizationService(context.UserId);

            try
            {

                //throw new InvalidPluginExecutionException("");
            }

            catch (Exception ex)
            {
                throw new Exception(ex.StackTrace);
            }
            #endregion
        }
开发者ID:hoanhtnb,项目名称:CRM2015-HPIH,代码行数:30,代码来源:PreValidate.cs

示例8: VisualStudioProjectTracker

        public VisualStudioProjectTracker(IServiceProvider serviceProvider)
        {
            _projectMap = new Dictionary<ProjectId, AbstractProject>();
            _projectPathToIdMap = new Dictionary<string, ProjectId>(StringComparer.OrdinalIgnoreCase);

            _serviceProvider = serviceProvider;
            _workspaceHosts = new List<WorkspaceHostState>(capacity: 1);

            _vsSolution = (IVsSolution)serviceProvider.GetService(typeof(SVsSolution));
            _runningDocumentTable = (IVsRunningDocumentTable4)serviceProvider.GetService(typeof(SVsRunningDocumentTable));

            uint solutionEventsCookie;
            _vsSolution.AdviseSolutionEvents(this, out solutionEventsCookie);
            _solutionEventsCookie = solutionEventsCookie;

            // It's possible that we're loading after the solution has already fully loaded, so see if we missed the event
            var shellMonitorSelection = (IVsMonitorSelection)serviceProvider.GetService(typeof(SVsShellMonitorSelection));

            uint fullyLoadedContextCookie;
            if (ErrorHandler.Succeeded(shellMonitorSelection.GetCmdUIContextCookie(VSConstants.UICONTEXT.SolutionExistsAndFullyLoaded_guid, out fullyLoadedContextCookie)))
            {
                int fActive;
                if (ErrorHandler.Succeeded(shellMonitorSelection.IsCmdUIContextActive(fullyLoadedContextCookie, out fActive)) && fActive != 0)
                {
                    _solutionLoadComplete = true;
                }
            }
        }
开发者ID:nemec,项目名称:roslyn,代码行数:28,代码来源:VisualStudioProjectTracker.cs

示例9: ConfigureOAuth

        /// <summary>
        /// 初始化OAuth
        /// </summary>
        /// <param name="app"></param>
        /// <param name="provider"></param>
        /// <returns></returns>
        public static IAppBuilder ConfigureOAuth(this IAppBuilder app, IServiceProvider provider)
        {
            IOAuthAuthorizationServerProvider oauthServerProvider = provider.GetService<IOAuthAuthorizationServerProvider>();
            if (oauthServerProvider == null)
            {
                throw new InvalidOperationException(Resources.OAuthServerProviderIsNull);
            }
            IAuthorizationCodeProvider authorizationCodeProvider = provider.GetService<IAuthorizationCodeProvider>();
            if (authorizationCodeProvider == null)
            {
                throw new InvalidOperationException(Resources.AuthorizationCodeProviderIsNull);
            }
            IRefreshTokenProvider refreshTokenProvider = provider.GetService<IRefreshTokenProvider>();
            if (refreshTokenProvider == null)
            {
                throw new InvalidOperationException(Resources.RefreshTokenProviderIsNull);
            }
            OAuthAuthorizationServerOptions options = new OAuthAuthorizationServerOptions()
            {
                TokenEndpointPath = new PathString("/token"),
                AuthorizeEndpointPath =  new PathString("/authorize"),
                ApplicationCanDisplayErrors = true,
                AuthenticationMode = AuthenticationMode.Active,
#if DEBUG
                AllowInsecureHttp = true,
#endif
                Provider = oauthServerProvider,
                AuthorizationCodeProvider = authorizationCodeProvider,
                RefreshTokenProvider = refreshTokenProvider
            };
            app.UseOAuthAuthorizationServer(options);
            app.UseOAuthBearerAuthentication(new OAuthBearerAuthenticationOptions());
            return app;
        }
开发者ID:donnieyoung,项目名称:osharp,代码行数:40,代码来源:AppBuilderExtensions.cs

示例10: XmlKeyManager

        /// <summary>
        /// Creates an <see cref="XmlKeyManager"/>.
        /// </summary>
        /// <param name="repository">The repository where keys are stored.</param>
        /// <param name="configuration">Configuration for newly-created keys.</param>
        /// <param name="services">A provider of optional services.</param>
        public XmlKeyManager(
            IXmlRepository repository,
            IAuthenticatedEncryptorConfiguration configuration,
            IServiceProvider services)
        {
            if (repository == null)
            {
                throw new ArgumentNullException(nameof(repository));
            }

            if (configuration == null)
            {
                throw new ArgumentNullException(nameof(configuration));
            }

            KeyEncryptor = services.GetService<IXmlEncryptor>(); // optional
            KeyRepository = repository;

            _activator = services.GetActivator(); // returns non-null
            _authenticatedEncryptorConfiguration = configuration;
            _internalKeyManager = services.GetService<IInternalXmlKeyManager>() ?? this;
            _keyEscrowSink = services.GetKeyEscrowSink(); // not required
            _logger = services.GetLogger<XmlKeyManager>(); // not required
            TriggerAndResetCacheExpirationToken(suppressLogging: true);
        }
开发者ID:supermason,项目名称:DataProtection,代码行数:31,代码来源:XmlKeyManager.cs

示例11: DocumentProvider

        public DocumentProvider(
            IVisualStudioHostProjectContainer projectContainer,
            IServiceProvider serviceProvider,
            bool signUpForFileChangeNotification)
        {
            var componentModel = (IComponentModel)serviceProvider.GetService(typeof(SComponentModel));

            _projectContainer = projectContainer;
            this.RunningDocumentTable = (IVsRunningDocumentTable4)serviceProvider.GetService(typeof(SVsRunningDocumentTable));
            this.EditorAdaptersFactoryService = componentModel.GetService<IVsEditorAdaptersFactoryService>();
            this.ContentTypeRegistryService = componentModel.GetService<IContentTypeRegistryService>();
            _textUndoHistoryRegistry = componentModel.GetService<ITextUndoHistoryRegistry>();
            _textManager = (IVsTextManager)serviceProvider.GetService(typeof(SVsTextManager));

            // In the CodeSense scenario we will receive file change notifications from the native
            // Language Services, so we don't want to sign up for them ourselves.
            if (signUpForFileChangeNotification)
            {
                _fileChangeService = (IVsFileChangeEx)serviceProvider.GetService(typeof(SVsFileChangeEx));
            }

            var shell = (IVsShell)serviceProvider.GetService(typeof(SVsShell));
            if (shell == null)
            {
                // This can happen only in tests, bail out.
                return;
            }

            int installed;
            Marshal.ThrowExceptionForHR(shell.IsPackageInstalled(Guids.RoslynPackageId, out installed));
            IsRoslynPackageInstalled = installed != 0;

            var runningDocumentTableForEvents = (IVsRunningDocumentTable)RunningDocumentTable;
            Marshal.ThrowExceptionForHR(runningDocumentTableForEvents.AdviseRunningDocTableEvents(new RunningDocTableEventsSink(this), out _runningDocumentTableEventCookie));
        }
开发者ID:Rickinio,项目名称:roslyn,代码行数:35,代码来源:DocumentProvider.cs

示例12: InitializeNerdDinner

        public static async Task InitializeNerdDinner(IServiceProvider provider)
        {
            NerdDinnerDbContext dbContext = provider.GetService<NerdDinnerDbContext>();
            UserManager<ApplicationUser> userManager = provider.GetService<UserManager<ApplicationUser>>();

            INerdDinnerRepository repository = new NerdDinnerRepository(dbContext);

            var users = GetUsers();
            var dinners = GetDinners();

            foreach(RegisterViewModel user in users)
            {
                var applicationUser = new ApplicationUser
                {
                    UserName = user.Email
                };

                await userManager.CreateAsync(applicationUser, user.Password);
            }

            foreach (Dinner dinner in dinners)
            {
                await repository.CreateDinnerAsync(dinner);
            }
        }
开发者ID:johndelfGM,项目名称:NerdDinner,代码行数:25,代码来源:SampleData.cs

示例13: EditValue

        public override object EditValue(ITypeDescriptorContext context, IServiceProvider provider, object value)
        {
            if (null == context) return value;
            if (null == provider) return value;

            IWindowsFormsEditorService edSvc = (IWindowsFormsEditorService)provider.GetService(typeof(IWindowsFormsEditorService));

            Debug.Assert(edSvc != null, "No editor service; we cannot edit the value");
            if (edSvc != null)
            {
                IWindowsFormsEditorService service = (IWindowsFormsEditorService)provider.GetService(typeof(IWindowsFormsEditorService));
                string expression = (string)value;
                var bindableProperty = EditorUtility.GetBindableProperty(context);
                var expressionProperty = bindableProperty.Property;

                if (expressionProperty != null)
                {
                    formUI.Expression = expression;
                    formUI.RuleName = ((ILogicalPropertyContainerElement)expressionProperty).ContainingElementDisplayName;

                    DialogResult result = service.ShowDialog(formUI);
                    if (result == DialogResult.OK)
                    {
                        expression = formUI.Expression;
                    }
                    return expression;
                }
            }
            
            return value;
        }
开发者ID:HondaBey,项目名称:EnterpriseLibrary6,代码行数:31,代码来源:ExpressionEditor.cs

示例14: PlayerShip

 public PlayerShip(IServiceProvider serviceProvider)
     : base(serviceProvider)
 {
     var content = (ContentManager)serviceProvider.GetService(typeof(ContentManager));
     _ship = content.Load<Texture2D>("HammerFrames");
     _spriteBatch = (SpriteBatch) serviceProvider.GetService(typeof (SpriteBatch));
 }
开发者ID:kingcoyote,项目名称:fusionc,代码行数:7,代码来源:PlayerShip.cs

示例15: EditValue

        /// <summary>
        /// Edits the value of the specified object.
        /// </summary>
        /// <param name="context">An <see cref="ITypeDescriptorContext"/> that can be used to gain
        /// additional context information.</param>
        /// <param name="provider">An <see cref="IServiceProvider"/> that this editor can use to obtain services.</param>
        /// <param name="value">The object to edit.</param>
        /// <returns>The new value of the object. If the value of the object has not changed, this should return the same object it was passed.</returns>
        public override object EditValue(ITypeDescriptorContext context, IServiceProvider provider, object value)
        {
            var baseTypeAttribute = GetBaseTypeAttribute(context);
            var constraint =
                    new TypeBuildNodeConstraint(
                        baseTypeAttribute.BaseType,
                        baseTypeAttribute.ConfigurationType,
                        baseTypeAttribute.TypeSelectorIncludes);

            var model = new TypeBrowserViewModel(constraint, provider);
            var window =
                new TypeBrowser(model, (IAssemblyDiscoveryService)provider.GetService(typeof(IAssemblyDiscoveryService)));

            var service = (IUIServiceWpf)provider.GetService(typeof(IUIServiceWpf));
            if (service != null)
            {
                service.ShowDialog(window);
            }
            else
            {
                window.ShowDialog();
            }

            if (window.DialogResult.HasValue && window.DialogResult.Value)
            {
                return window.SelectedType != null ? window.SelectedType.AssemblyQualifiedName : null;
            }

            return value;
        }
开发者ID:jmeckley,项目名称:Enterprise-Library-5.0,代码行数:38,代码来源:TypeSelectionEditor.cs


注:本文中的IServiceProvider.GetService方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。