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


C# IServiceProvider.GetType方法代码示例

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


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

示例1: GetPane

        /// <summary>
        /// Gets the output window pane corresponding to the package, using the package
        /// <c>GuidAttribute</c> attribute as the pane identifier. The pane title is
        /// determined by the package class <c>DisplayNameAttribute</c> or its namespace
        /// if no display name is provided.
        /// </summary>
        /// <param name="manager">The output window manager.</param>
        /// <param name="package">The owning package.</param>
        /// <returns></returns>
        public static TextWriter GetPane(this IOutputWindowManager manager, IServiceProvider package)
        {
            var title = package.GetType().GetCustomAttributes<DisplayNameAttribute>()
                .Select(d => d.DisplayName)
                .FirstOrDefault() ?? package.GetType().Namespace;

            return GetPane(manager, package, title);
        }
开发者ID:MobileEssentials,项目名称:clide,代码行数:17,代码来源:IOutputWindowManagerExtensions.cs

示例2: CuteProvider

        /// <summary>
        /// Initializes a new instance of the <see cref="CuteProvider"/> class.
        /// </summary>
        /// <param name="Provider">Provider that will be acting as a back-end for current one</param>
        public CuteProvider(IServiceProvider provider)
            : this()
        {
            if (provider.GetType() == typeof(CuteProvider))
            {
                Original = ((CuteProvider)provider).Original;
                Type = InstanceType.WrappedInput;
            }
            else
            {
                Original = provider;
                Type = InstanceType.BareInput;
            }

            Context = CuteContext.Copy((IPluginExecutionContext)this.Original.GetService(typeof(IPluginExecutionContext)));
        }
开发者ID:Innofactor,项目名称:CUTE,代码行数:20,代码来源:CuteProvider.cs

示例3: InitializeContainer

        private IServiceLocator InitializeContainer(IServiceProvider services)
        {
            using (tracer.StartActivity(Strings.DevEnvFactory.CreatingComposition))
            {
                // Allow dependencies of VS exported services.
                var composition = services.GetService<SComponentModel, IComponentModel>();

                // Keep track of assemblies we've already added, to avoid duplicate registrations.
                var addedAssemblies = new Dictionary<string, Assembly>();

                // Register built-in components from Clide assembly.
                var clideAssembly = Assembly.GetExecutingAssembly();
                addedAssemblies.Add(clideAssembly.Location.ToLowerInvariant(), clideAssembly);

                // Register hosting package assembly.
                var servicesAssembly = services.GetType().Assembly;
                addedAssemblies[servicesAssembly.Location.ToLowerInvariant()] = servicesAssembly;

                var installPath = GetInstallPath(services);

                var packageManifestFile = Path.Combine(installPath, "extension.vsixmanifest");
                if (File.Exists(packageManifestFile))
                {
                    tracer.Info(Strings.DevEnvFactory.ExtensionManifestFound(packageManifestFile));
                    var manifestDoc = XDocument.Load(packageManifestFile);

                    ThrowIfClideIsMefComponent(manifestDoc);
                    // NOTE: we don't warn anymore in this case, since a single package may have
                    // a mix of plain VS exports as well as clide components.
                    // Since we use CommonComposition, only the types with the ComponentAttribute
                    // will be made available in the Clide container, not the others, and no
                    // duplicates would be registered.
                    //WarnIfClideComponentIsAlsoMefComponent(packageManifestFile, manifestDoc);

                    foreach (string clideComponent in GetClideComponents(manifestDoc))
                    {
                        var assemblyFile = Path.Combine(installPath, clideComponent);
                        tracer.Info(Strings.DevEnvFactory.ClideComponentDeclared(clideComponent, assemblyFile));

                        if (clideComponent == ClideAssembly)
                        {
                            tracer.Warn(Strings.DevEnvFactory.ClideNotNecessaryAsComponent(clideComponent));
                            continue;
                        }

                        if (!File.Exists(assemblyFile))
                            throw new InvalidOperationException(Strings.DevEnvFactory.ClideComponentNotFound(packageManifestFile, clideComponent, assemblyFile));

                        var componentAssembly = Assembly.LoadFrom(assemblyFile);
                        if (!addedAssemblies.ContainsKey(componentAssembly.Location.ToLowerInvariant()))
                            addedAssemblies.Add(componentAssembly.Location.ToLowerInvariant(), componentAssembly);
                    }
                }
                else
                {
                    tracer.Info(Strings.DevEnvFactory.ExtensionManifestNotFound(packageManifestFile));
                }

                var catalog = new ComponentCatalog(addedAssemblies.Values.ToArray());
                var container = new CompositionContainer(catalog,
                    composition.DefaultExportProvider,
                    new ServicesExportProvider(services));

                // Make the service locator itself available as an export.
                var serviceLocator = new ServicesAccessor(services, new Lazy<IServiceLocator>(() => serviceLocators[services]));
                container.ComposeParts(serviceLocator);

                return new ExportsServiceLocator(container);
            }
        }
开发者ID:austinvernsonger,项目名称:clide,代码行数:70,代码来源:DevEnvFactory.cs

示例4: GetInstallPath

 private string GetInstallPath(IServiceProvider services)
 {
     return Path.GetDirectoryName(services.GetType().Assembly.ManifestModule.FullyQualifiedName);
 }
开发者ID:austinvernsonger,项目名称:clide,代码行数:4,代码来源:DevEnvFactory.cs

示例5: SetServiceLocator

 public static void SetServiceLocator(IServiceProvider serviceLocator)
 {
     Logger.LogEvent(string.Format("Setting instance of {0} as a service locator", serviceLocator.GetType().Name), null, ImportanceLevels.gUnimportant);
     _current = serviceLocator;
     Logger.LogEvent(string.Format("Instance of {0} set as a service locator", serviceLocator.GetType().Name), null, ImportanceLevels.gUnimportant);
 }
开发者ID:ZivSystems,项目名称:WcfFramework,代码行数:6,代码来源:ServiceLocator.cs

示例6: EditValue

        public override object EditValue(ITypeDescriptorContext context, IServiceProvider provider, object value)
        {

            if (provider == null || provider.GetType().FullName != "System.Windows.Forms.PropertyGridInternal.PropertyDescriptorGridEntry")
                return null;

            // First off, does this point to an enum?
            //bool isEnum = 
            // What type are we creating
            //Type creatingType = provider.GetType().GetProperty("PropertyType").GetValue(provider, null) as Type;
            Type creatingType = context.PropertyDescriptor.PropertyType;
            object[] propertyAttributes = context.Instance.GetType().GetProperty(context.PropertyDescriptor.Name).GetCustomAttributes(typeof(PropertyAttribute), true);

            // Get the ListBox control
            object lb = CreateControl(creatingType, propertyAttributes, value);

            // Create a service
            Type serviceType = lb.GetType().Assembly.GetType("System.Windows.Forms.Design.IWindowsFormsEditorService");
            object service = provider.GetService(serviceType);
            

            // Drop down the control
            serviceType.GetMethod("DropDownControl").Invoke(service, new object[] { lb });

            if (lb.GetType().GetProperty("SelectedItem") != null && lb.GetType().GetProperty("SelectedItem").GetValue(lb, null) == null)
                value = null;
            else if (lb.GetType().GetProperty("SelectedItem") != null && lb.GetType().GetProperty("SelectedItem").GetValue(lb, null).ToString() == "Create new Instance")
                value = creatingType.Assembly.CreateInstance(creatingType.FullName);
            else if (lb.GetType().GetProperty("SelectedItem") != null) // We don't know what type they want.. yet
            {
                object selectedItem = lb.GetType().GetProperty("SelectedItem").GetValue(lb, null);
                if (selectedItem is string)
                    value = null;
                else
                    value = (selectedItem as CreateTypeReference).Type.Assembly.CreateInstance((selectedItem as CreateTypeReference).Type.FullName);
            }
            else if (lb.GetType().GetProperty("Text") != null && lb.GetType().GetProperty("Text").GetValue(lb, null).ToString().Length > 0) // Textual
            {
                object tmp = lb.GetType().GetProperty("Text").GetValue(lb, null);
                // Look for the ctor
                foreach (MethodInfo mi in creatingType.GetMethods(BindingFlags.Public | BindingFlags.Static))
                    if (mi.Name == "op_Implicit" && mi.GetParameters()[0].ParameterType == typeof(System.String)) // Use a text box!
                    {
                        value = mi.Invoke(null, new object[] { tmp });
                        break;
                    }
            }

            serviceType.GetMethod("CloseDropDown").Invoke(service, null);

            return value;
        }
开发者ID:oneminot,项目名称:everest,代码行数:52,代码来源:NewInstanceTypeEditor.cs

示例7: EditValue

        /// <summary>
        /// Displays a list of available values for the specified component than sets the value.
        /// </summary>
        /// <param name="context">An ITypeDescriptorContext that can be used to gain additional context information.</param>
        /// <param name="provider">A service provider object through which editing services may be obtained.</param>
        /// <param name="value">An instance of the value being edited.</param>
        /// <returns>The new value of the object. If the value of the object hasn't changed, this method should return the same object it was passed.</returns>
        public override object EditValue(ITypeDescriptorContext context, IServiceProvider provider, object value)
        {
            if (provider != null)
            {
                // This service is in charge of popping our ListBox.
                var service1 = ((IWindowsFormsEditorService)provider.GetService(typeof(IWindowsFormsEditorService)));

                if (service1 != null)
                {
                    // This is an internal Microsoft class representing the PropertyGrid entry for our component.
                    if (provider.GetType().FullName == "System.Windows.Forms.PropertyGridInternal.PropertyDescriptorGridEntry")
                    {
                        var list = new PropertiesList(context);
                        // Drop the list control.
                        service1.DropDownControl(list);

                        if (list.SelectedIndices.Count == 1)
                        {
                            value = list.SelectedItem.ToString();
                        }
                        // Close the list control after selection.
                        service1.CloseDropDown();
                    }
                }
            }

            return value;
        }
开发者ID:johnmensen,项目名称:TradeSharp,代码行数:35,代码来源:LookupTypeEditor.cs


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