本文整理汇总了C#中System.GetService方法的典型用法代码示例。如果您正苦于以下问题:C# System.GetService方法的具体用法?C# System.GetService怎么用?C# System.GetService使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System
的用法示例。
在下文中一共展示了System.GetService方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: EditValue
public override object EditValue(ITypeDescriptorContext context, System.IServiceProvider provider, object value)
{
if (context != null && provider != null)
{
edSvc = (IWindowsFormsEditorService)provider.GetService(typeof(IWindowsFormsEditorService));
if (edSvc != null)
{
lb = new ListBox();
lb.Items.AddRange(new object[] {
"Sunday",
"Monday",
"Tuesday",
"Wednesday",
"Thursday",
"Friday",
"Saturday"});
lb.SelectedIndexChanged += new System.EventHandler(lb_SelectedIndexChanged);
edSvc.DropDownControl(lb);
}
return text;
}
return base.EditValue(context, provider, value);
}
示例2: EditValue
public override object EditValue(ITypeDescriptorContext context, System.IServiceProvider provider, object value)
{
List<string> objName = new List<string>();
ControlCollection ctrlList = null;
if (context.Instance is Control)
{
ctrlList = ((Control)context.Instance).Page.Controls;
}
else if (context.Instance is InfoOwnerCollectionItem && ((InfoOwnerCollectionItem)context.Instance).Owner is Control)
{
ctrlList = ((Control)((InfoOwnerCollectionItem)context.Instance).Owner).Page.Controls;
}
foreach (Control ctrl in ctrlList)
{
if (ctrl is WebDataSource)
{
objName.Add(ctrl.ID);
}
}
IWindowsFormsEditorService service = (IWindowsFormsEditorService)provider.GetService(typeof(IWindowsFormsEditorService));
if (service != null)
{
StringListSelector selector = new StringListSelector(service, objName.ToArray());
string strValue = (string)value;
if (selector.Execute(ref strValue)) value = strValue;
}
return value;
}
示例3: GetCurrentHierarchy
/// <summary>
/// Get the current Hierarchy
/// </summary>
/// <param name="provider"></param>
/// <returns></returns>
public static IVsHierarchy GetCurrentHierarchy(System.IServiceProvider provider)
{
DTE vs = (DTE)provider.GetService(typeof(DTE));
if (vs == null) throw new InvalidOperationException("DTE not found.");
return ToHierarchy(vs.SelectedItems.Item(1).ProjectItem.ContainingProject);
}
示例4: EditValue
public override object EditValue(
System.ComponentModel.ITypeDescriptorContext context,
System.IServiceProvider provider, object value)
{
if (provider != null)
{
IWindowsFormsEditorService editorService =
provider.GetService(
typeof(IWindowsFormsEditorService))
as IWindowsFormsEditorService;
if (editorService != null)
{
Progress ctrl = (Progress)context.Instance;
ProgressValueDropDown selectionControl =
new ProgressValueDropDown(
(int)value, ctrl.Maximum,
editorService);
editorService.DropDownControl(selectionControl);
value = selectionControl.Value;
}
}
return value;
}
示例5: EditValue
// Displays the UI for value selection.
// Para ver en un User control edSvc.DropDownControl(styleControl);
// Para ver en un formulario edSvc.ShowDialog(styleForm);
/// <summary>
///
/// </summary>
/// <param name="context"></param>
/// <param name="provider"></param>
/// <param name="value"></param>
/// <returns></returns>
public override object EditValue(System.ComponentModel.ITypeDescriptorContext context, System.IServiceProvider provider, object value)
{
// Return the value if the value is not of type Int32, Double and Single.
//if (value.GetType() != typeof(IFwkCellStyle))
// return value;
// Uses the IWindowsFormsEditorService to display a
// drop-down UI in the Properties window.
IWindowsFormsEditorService edSvc = (IWindowsFormsEditorService)provider.GetService(typeof(IWindowsFormsEditorService));
if (edSvc != null)
{
// Display an angle selection control and retrieve the value.
//StyleControl styleControl = new StyleControl((GridProperties)value);
//edSvc.DropDownControl(styleControl);
FwkGridStyleForm wStyleForm = new FwkGridStyleForm((GridProperties)value);
edSvc.ShowDialog(wStyleForm);
// Return the value in the appropraite data format.
//if (value.GetType() == typeof(IFwkCellStyle))
return wStyleForm.GridProperties;
}
return value;
}
示例6: GetActiveTextView
public static Microsoft.VisualStudio.Text.Editor.IWpfTextView GetActiveTextView(System.IServiceProvider serviceProvider)
{
var monitorSelection = (Microsoft.VisualStudio.Shell.Interop.IVsMonitorSelection)serviceProvider.GetService(typeof(Microsoft.VisualStudio.Shell.Interop.SVsShellMonitorSelection));
if (monitorSelection == null) {
return null;
}
object curDocument;
if (Microsoft.VisualStudio.ErrorHandler.Failed(monitorSelection.GetCurrentElementValue((uint)Microsoft.VisualStudio.VSConstants.VSSELELEMID.SEID_DocumentFrame, out curDocument))) {
return null;
}
Microsoft.VisualStudio.Shell.Interop.IVsWindowFrame frame = curDocument as Microsoft.VisualStudio.Shell.Interop.IVsWindowFrame;
if (frame == null) {
return null;
}
object docView = null;
if (Microsoft.VisualStudio.ErrorHandler.Failed(frame.GetProperty((int)Microsoft.VisualStudio.Shell.Interop.__VSFPROPID.VSFPROPID_DocView, out docView))) {
return null;
}
if (docView is Microsoft.VisualStudio.TextManager.Interop.IVsCodeWindow) {
Microsoft.VisualStudio.TextManager.Interop.IVsTextView textView;
if (Microsoft.VisualStudio.ErrorHandler.Failed(((Microsoft.VisualStudio.TextManager.Interop.IVsCodeWindow)docView).GetPrimaryView(out textView))) {
return null;
}
var model = (Microsoft.VisualStudio.ComponentModelHost.IComponentModel)serviceProvider.GetService(typeof(Microsoft.VisualStudio.ComponentModelHost.SComponentModel));
var adapterFactory = model.GetService<Microsoft.VisualStudio.Editor.IVsEditorAdaptersFactoryService>();
var wpfTextView = adapterFactory.GetWpfTextView(textView);
return wpfTextView;
}
return null;
}
示例7: EditValue
/// <summary>
/// Called when we want to edit the value of a property.
/// </summary>
/// <param name="context"></param>
/// <param name="provider"></param>
/// <param name="value"></param>
/// <returns></returns>
public override object EditValue(System.ComponentModel.ITypeDescriptorContext context, System.IServiceProvider provider, object value)
{
edSvc = (IWindowsFormsEditorService)provider.GetService(typeof(IWindowsFormsEditorService));
if (edSvc != null)
{
UI.Actions.MessageAction messageAction = context.Instance as UI.Actions.MessageAction;
if (messageAction != null)
{
ListBox listBox = new ListBox();
foreach (UI.Message message in messageAction.Scene.Messages)
{
listBox.Items.Add(message);
}
listBox.SelectedItem = messageAction.Scene.GetMessage((int)value);
listBox.SelectedIndexChanged += ((s, e) => { edSvc.CloseDropDown(); });
edSvc.DropDownControl(listBox);
return listBox.SelectedItem != null ? (listBox.SelectedItem as UI.Message).ID : -1;
}
}
return value;
}
示例8: EditValue
public override object EditValue(System.ComponentModel.ITypeDescriptorContext context, System.IServiceProvider provider, object value)
{
IWindowsFormsEditorService service = (IWindowsFormsEditorService)provider.GetService(typeof(IWindowsFormsEditorService));
if (service != null && context.Instance.GetType().GetInterface("IReportGetValues") != null)
{
IReportGetValues item = (IReportGetValues)context.Instance;
ListBox listbox = new ListBox();
listbox.Items.AddRange(item.GetValues(context.PropertyDescriptor.Name));
listbox.SelectedItem = value;
listbox.Click += delegate(object sender, EventArgs e)
{
service.CloseDropDown();
};
service.DropDownControl(listbox);
if (listbox.SelectedItem != null)
{
value = listbox.SelectedItem.ToString();
}
else
{
value = string.Empty;
}
}
return value;
}
示例9: EditValue
public override object EditValue(System.ComponentModel.ITypeDescriptorContext context, System.IServiceProvider provider, object value)
{
var service = (IWindowsFormsEditorService)provider.GetService(typeof(IWindowsFormsEditorService));
try
{
//throw new MissingMethodException(
ListBox listbox = new ListBox();
listbox.Items.AddRange(GetListOfValues(context).ToArray());
listbox.SelectedItem = value;
listbox.Click += delegate(object sender, EventArgs e)
{
service.CloseDropDown();
};
service.DropDownControl(listbox);
if (listbox.SelectedItem != null)
{
value = listbox.SelectedItem.ToString();
}
else
{
value = string.Empty;
}
}
catch(Exception e)
{
System.Windows.Forms.MessageBox.Show(e.Message, "Error"
, System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Error);
}
return value;
}
示例10: EditValue
public override object EditValue(System.ComponentModel.ITypeDescriptorContext context, System.IServiceProvider provider, object value)
{
IWindowsFormsEditorService editorService = null;
if (provider != null)
{
editorService = provider.GetService(typeof(IWindowsFormsEditorService)) as IWindowsFormsEditorService;
}
if (editorService != null)
{
var control = new ListBox();
control.Items.Add(ResourceExtenderBase.AnyText);
control.Items.AddRange(list);
control.Height = 200;
control.BorderStyle = BorderStyle.FixedSingle;
if (string.IsNullOrEmpty(value as string))
{
control.SelectedIndex = 0;
}
else
{
control.SelectedItem = value;
}
control.PreviewKeyDown += (s, x) => { if (x.KeyCode == Keys.Enter) editorService.CloseDropDown(); };
control.Leave += (s, x) => editorService.CloseDropDown();
control.Click += (s, x) => editorService.CloseDropDown();
editorService.DropDownControl(control);
if (control.SelectedIndex == 0)
return null;
return control.SelectedItem;
}
return base.EditValue(context, provider, value);
}
示例11: EditValue
/// <summary>
/// Called when we want to edit the value of the property. Brings up the a drop down list box of masks.
/// </summary>
/// <param name="context"></param>
/// <param name="provider"></param>
/// <param name="value"></param>
/// <returns></returns>
public override object EditValue(System.ComponentModel.ITypeDescriptorContext context, System.IServiceProvider provider, object value)
{
edSvc = (IWindowsFormsEditorService)provider.GetService(typeof(IWindowsFormsEditorService));
if (edSvc != null)
{
GUIControl controlContext = context.Instance as GUIControl;
ListBox listBox = new ListBox();
listBox.Items.Add("None");
AddControls(listBox, controlContext.ParentView.Controls);
listBox.SelectedItem = value;
listBox.SelectedIndexChanged += (s, e) => { edSvc.CloseDropDown(); };
edSvc.DropDownControl(listBox);
//no valid item selected; return previous value
if (listBox.SelectedIndex == -1 || listBox.SelectedItem == null)
return value;
//"None" selected
if (listBox.SelectedIndex == 0)
return -1;
return (listBox.SelectedItem as GUIMask).ID;
}
return value;
}
示例12: VsIdleTaskHost
public VsIdleTaskHost(System.IServiceProvider serviceProvider, Func<bool> task, TimeSpan updateDelay)
{
Guard.NotNull(() => serviceProvider, serviceProvider);
Guard.NotNull(() => task, task);
this.componentManager = (IOleComponentManager)serviceProvider.GetService(typeof(SOleComponentManager));
this.host = new HostComponent(task, updateDelay);
}
示例13: GetStandardValues
/// <summary>
/// Returns a collection of standard values for the data type this type converter is designed for when provided with a format context.
/// </summary>
/// <param name="context">An <see cref="T:System.ComponentModel.ITypeDescriptorContext"></see> that provides a format context that can be used to extract additional information about the environment from which this converter is invoked. This parameter or properties of this parameter can be null.</param>
/// <returns>
/// A <see cref="T:System.ComponentModel.TypeConverter.StandardValuesCollection"></see> that holds a standard set of valid values, or null if the data type does not support a standard set of values.
/// </returns>
public override StandardValuesCollection GetStandardValues(System.ComponentModel.ITypeDescriptorContext context)
{
DTE dte = (DTE)context.GetService(typeof(DTE));
ResponsibleProjectFinder finder = new ResponsibleProjectFinder(dte);
List<Project> projects = finder.FindProjectsWithResponsibility(responsibility);
return new StandardValuesCollection(projects);
}
示例14: EditValue
public override object EditValue(ITypeDescriptorContext context, System.IServiceProvider provider, object value)
{
IWindowsFormsEditorService svc = provider.GetService(typeof(IWindowsFormsEditorService)) as IWindowsFormsEditorService;
if (svc != null) {
using (TextMessageEditorForm form = new TextMessageEditorForm()) {
form.MessageText = (string) value;
if (svc.ShowDialog(form) == DialogResult.OK)
value = form.MessageText;
}
}
return value;
}
示例15: EditValue
public override object EditValue(ITypeDescriptorContext context, System.IServiceProvider provider, object value)
{
List<string> objName = new List<string>();
IAjaxDataSource ajaxSource = null;
ControlCollection ctrlList = null;
if (context.Instance is IAjaxDataSource)
{
ajaxSource = (IAjaxDataSource)context.Instance;
ctrlList = ((Control)context.Instance).Page.Controls;
}
else if (context.Instance is InfoOwnerCollectionItem && ((InfoOwnerCollectionItem)context.Instance).Owner is IAjaxDataSource)
{
ajaxSource = ((InfoOwnerCollectionItem)context.Instance).Owner as IAjaxDataSource;
ctrlList = (((InfoOwnerCollectionItem)context.Instance).Owner as Control).Page.Controls;
}
if (ajaxSource != null)
{
foreach (Control ctrl in ctrlList)
{
if (ctrl is WebDataSource && ctrl.ID == ajaxSource.DataSourceID)
{
WebDataSource wds = (WebDataSource)ctrl;
DataTable srcTab = null;
if (string.IsNullOrEmpty(wds.SelectAlias) && string.IsNullOrEmpty(wds.SelectCommand))
{
if (wds.DesignDataSet == null)
{
WebDataSet ds = GloFix.CreateDataSet(wds.WebDataSetID);
wds.DesignDataSet = ds.RealDataSet;
}
srcTab = wds.DesignDataSet.Tables[wds.DataMember].Clone();
}
else
{
srcTab = wds.CommandTable.Clone();
}
foreach (DataColumn column in srcTab.Columns)
{
objName.Add(column.ColumnName);
}
break;
}
}
}
IWindowsFormsEditorService service = (IWindowsFormsEditorService)provider.GetService(typeof(IWindowsFormsEditorService));
if (service != null)
{
StringListSelector selector = new StringListSelector(service, objName.ToArray());
string strValue = (string)value;
if (selector.Execute(ref strValue)) value = strValue;
}
return value;
}