本文整理汇总了C#中IDataContext.GetData方法的典型用法代码示例。如果您正苦于以下问题:C# IDataContext.GetData方法的具体用法?C# IDataContext.GetData怎么用?C# IDataContext.GetData使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IDataContext
的用法示例。
在下文中一共展示了IDataContext.GetData方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Resolve
public void Resolve(IDataContext context, Action<IQuickDocPresenter, PsiLanguageType> resolved)
{
var elements = context.GetData(PsiDataConstants.DECLARED_ELEMENTS);
Assertion.AssertNotNull(elements, "elements != null");
var document = context.GetData(DocumentModelDataConstants.DOCUMENT);
IProjectFile projectFile = null;
if (document != null)
projectFile = myDocumentManager.TryGetProjectFile(document);
var defaultLanguage = PresentationUtil.GetPresentationLanguageByContainer(projectFile, mySolution);
foreach (var element in elements.OfType<IClrDeclaredElement>())
{
var eventFunction = GetEventFunction(element);
if (eventFunction != null)
{
var presenter = new UnityEventFunctionQuickDocPresenter(eventFunction, element, myQuickDocTypeMemberProvider,
myTheming, myHelpSystem);
resolved(presenter, defaultLanguage);
return;
}
var eventFunctionForParameter = GetEventFunctionFromParameter(element as IParameter);
if (eventFunctionForParameter != null)
{
var presenter = new UnityEventFunctionQuickDocPresenter(eventFunctionForParameter, element.ShortName, element,
myQuickDocTypeMemberProvider, myTheming, myHelpSystem);
resolved(presenter, defaultLanguage);
return;
}
}
}
示例2: IsAvailable
public bool IsAvailable(IDataContext dataContext)
{
ISolution solution = dataContext.GetData(JetBrains.ProjectModel.DataContext.DataConstants.SOLUTION);
if (solution == null)
return false;
#if SDK70
IDocument document = dataContext.GetData(JetBrains.DocumentModel.DataConstants.DOCUMENT);
#else
IDocument document = dataContext.GetData(JetBrains.IDE.DataConstants.DOCUMENT);
#endif
if (document == null)
return false;
#if SDK70
DocumentOffset documentOffset = dataContext.GetData(JetBrains.DocumentModel.DataConstants.DOCUMENT_OFFSET);
#else
DocumentOffset documentOffset = dataContext.GetData(JetBrains.IDE.DataConstants.DOCUMENT_OFFSET);
#endif
if (documentOffset == null)
return false;
IPsiSourceFile psiSourceFile = document.GetPsiSourceFile(solution);
if (psiSourceFile != null)
{
// todo make this resolvable also via the AllTypes... line
var invokedNode = dataContext.GetSelectedTreeNode<IExpression>();
return solution.GetComponent<SolutionAnalyzer>()
.Analyze()
.Any(r => r.Registration.RegistrationElement.Children().Contains(invokedNode));
}
return false;
}
示例3: GetRegisteredComponentsRequest
public RegisteredComponentsSearchRequest GetRegisteredComponentsRequest(IDataContext dataContext)
{
ISolution solution = dataContext.GetData(JetBrains.ProjectModel.DataContext.DataConstants.SOLUTION);
if (solution == null)
{
throw new InvalidOperationException("Unable to get the solution");
}
var invokedNode = dataContext.GetSelectedTreeNode<IExpression>();
IDocument document = dataContext.GetData(JetBrains.IDE.DataConstants.DOCUMENT);
if (document == null)
return null;
IPsiSourceFile psiSourceFile = document.GetPsiSourceFile(solution);
if (psiSourceFile == null)
{
return null;
}
var registration = solution.GetComponent<IPatternManager>().GetRegistrationsForFile(psiSourceFile)
.FirstOrDefault(r => r.Registration.RegistrationElement.Children().Contains(invokedNode));
if (registration == null)
{
return null;
}
return new RegisteredComponentsSearchRequest(solution, locks, registration.Registration);
}
示例4: Execute
public void Execute(IDataContext context, DelegateExecute nextExecute)
{
var solution = context.GetData(ProjectModel.DataContext.DataConstants.SOLUTION);
var textControl = context.GetData(TextControl.DataContext.DataConstants.TEXT_CONTROL);
if (textControl != null && solution != null && myLookupWindowManager.CurrentLookup == null)
{
const string commandName = "Expand postfix template";
var updateCookie = myChangeUnitFactory.CreateChangeUnit(textControl, commandName);
try
{
using (myCommandProcessor.UsingCommand(commandName))
{
var template = GetTemplateFromTextControl(textControl, solution);
if (template != null)
{
var nameRange = new TextRange(textControl.Caret.PositionValue.ToDocOffset()); // looks wrong?
// invoke item completion manually
template.Accept(textControl, nameRange,
LookupItemInsertType.Replace, Suffix.Empty, solution, false);
return;
}
updateCookie.Dispose();
}
}
catch
{
updateCookie.Dispose();
throw;
}
}
nextExecute();
}
示例5: CanNavigate
public bool CanNavigate(IDataContext context)
{
var project = context.GetData(ProjectModelDataConstants.PROJECT);
if (project == null || !project.IsUnityProject()) return false;
var declaredElements = context.GetData(PsiDataConstants.DECLARED_ELEMENTS);
return declaredElements != null && declaredElements.Any(e => IsEventFunction(e) || IsParameterForEventFunction(e as IParameter));
}
示例6: GetElementAtCaret
/// <summary>
/// Gets the element at caret.
/// </summary>
/// <param name="context">The context.</param>
/// <returns>The element at caret.</returns>
protected static IElement GetElementAtCaret(IDataContext context)
{
ISolution solution = context.GetData(DataConstants.SOLUTION);
if (solution == null) {
return null;
}
ITextControl textControl = context.GetData(DataConstants.TEXT_CONTROL);
if (textControl == null) {
return null;
}
return TextControlToPsi.GetElementFromCaretPosition<IElement>(solution, textControl);
}
示例7: GetCandidates
public IList<IDeclaredElement> GetCandidates(IDataContext context)
{
var reference = context.GetData(DataConstants.REFERENCE);
var rer = reference as INitraAst;
if (rer != null)
return new IDeclaredElement[] { reference.Resolve().Result.DeclaredElement };
var declaredElements = context.GetData(DataConstants.DECLARED_ELEMENTS);
if (declaredElements != null)
return declaredElements.ToArray();
return EmptyList<IDeclaredElement>.InstanceList;
}
示例8: GetTypeElement
/// <summary>
/// Gets type element from context
/// </summary>
/// <param name="context">Action context</param>
/// <param name="instance">If true, only instance memebers are relevant, e.g. context points to instance of type</param>
/// <returns>ITypeElement instance or null</returns>
public static ITypeElement GetTypeElement(IDataContext context, out bool instance)
{
// Obtain declared element from context
// This may be from source code (from caret), or from various tree views displaying elements
var declaredElements = context.GetData(DataConstants.DECLARED_ELEMENTS);
if (declaredElements == null || declaredElements.IsEmpty())
{
instance = false;
return null;
}
IDeclaredElement declaredElement = declaredElements.First();
// If we have type, just return it
var typeElement = declaredElement as ITypeElement;
if (typeElement != null)
{
instance = false;
return typeElement;
}
// If it is constructor, return containing type
var constructor = declaredElement as IConstructor;
if (constructor != null)
{
instance = false;
return constructor.GetContainingType();
}
// Element has type attached to it, e.g. method return type, property or field type
var typeOwner = declaredElement as ITypeOwner;
if (typeOwner != null)
{
// It is instance of type, which is returned, so provide caller with this information
instance = true;
return GetTypeElement(typeOwner.Type);
}
// Try to guess type of expression
ITextControl textControl = context.GetData(TextControl.DataContext.DataConstants.TEXT_CONTROL);
ISolution solution = context.GetData(ProjectModel.DataContext.DataConstants.SOLUTION);
if (textControl != null && solution != null)
{
// TODO: Implement expression processing
}
instance = false;
return null;
}
示例9: CreateWorkflow
public IEnumerable<IRefactoringWorkflow> CreateWorkflow(IDataContext dataContext)
{
yield return new SharedToExtensionWorkflow(
dataContext.GetData(DataConstants.SOLUTION),
SharedToExtensionWorkflow.WorkflowDirection.SharedToExtension,
SharedToExtensionAction.ActionId);
}
示例10: Execute
public void Execute(IDataContext context, DelegateExecute nextExecute)
{
// Get solution from context in which action is executed
ISolution solution = context.GetData(ProjectModel.DataContext.DataConstants.SOLUTION);
if (solution == null)
return;
var documentManager = solution.GetComponent<DocumentManager>();
var shellLocks = solution.GetComponent<IShellLocks>();
var settingStore = solution.GetComponent<ISettingsStore>();
var mainWindow = solution.GetComponent<IMainWindow>();
// Ask user about search string
FindTextSearchRequest searchRequest;
using (var dialog = new EnterSearchStringDialog(settingStore.BindToContextTransient(ContextRange.Smart((lt, contexts) => context))))
{
if (dialog.ShowDialog(mainWindow) != DialogResult.OK)
return;
// Create request, descriptor, perform search and show results
searchRequest = new FindTextSearchRequest(solution, dialog.SearchString, dialog.CaseSensitive, dialog.SearchFlags, documentManager);
}
using (shellLocks.UsingReadLock())
{
var descriptor = new FindTextDescriptor(searchRequest);
descriptor.Search();
FindResultsBrowser.ShowResults(descriptor);
}
}
示例11: Initialize
public override bool Initialize(IDataContext context)
{
IDocument data = context.GetData(JetBrains.DocumentModel.DataConstants.DOCUMENT);
if (data == null) return false;
Marker = JetBrains.DocumentManagers.RangeMarkerExtentions.CreateRangeMarker(new DocumentRange(data, new TextRange(ITextControlCaretEx.Offset(this.TextControl.Caret))), DocumentManager.GetInstance(Solution));
return IsAvailable(context);
}
示例12: Update
public bool Update(IDataContext dataContext, ActionPresentation presentation, DelegateUpdate nextUpdate)
{
var solution = dataContext.GetData(JetBrains.ProjectModel.DataContext.DataConstants.SOLUTION);
if (solution == null)
return nextUpdate();
var textControl = dataContext.GetData(JetBrains.TextControl.DataContext.DataConstants.TEXT_CONTROL);
if (textControl == null)
return nextUpdate();
var doc = dataContext.GetData(JetBrains.DocumentModel.DataConstants.DOCUMENT);
if (doc == null)
return nextUpdate();
return true;
}
示例13: IsAvailable
// Hides the menu item if it's not a Unity project
public override bool IsAvailable(IDataContext dataContext)
{
var project = dataContext.GetData(ProjectModelDataConstants.PROJECT);
if (project == null || !project.IsUnityProject())
return false;
return base.IsAvailable(dataContext);
}
示例14: Execute
public void Execute(IDataContext context, DelegateExecute nextExecute)
{
var textControl = context.GetData(DataConstants.TEXT_CONTROL);
GC.KeepAlive(textControl);
DateTime lastInvocation, utcNow = DateTime.UtcNow;
lock (syncLock)
{
lastInvocation = this.lastLocateInvocation;
this.lastLocateInvocation = utcNow;
}
const int doubleKeyPressDelay = 500;
if (utcNow.Subtract(lastInvocation).TotalMilliseconds < doubleKeyPressDelay)
{
var locateFileAction = actionManager.TryGetAction(LocateFileAction.Id) as IExecutableAction;
if (locateFileAction != null)
{
locateFileAction.Execute(context);
return;
}
}
if (lastUnderlyingActionUpdate)
{
nextExecute();
}
}
示例15: GetOriginTypeElement
private static ITypeElement GetOriginTypeElement(IDataContext dataContext, DeclaredElementTypeUsageInfo initialTarget)
{
var data = dataContext.GetData(DataConstants.REFERENCES);
if (data == null) {
return null;
}
foreach (var current in data.OfType<IQualifiableReference>()) {
if (!Equals(current.Resolve().DeclaredElement, initialTarget)) {
continue;
}
var qualifierWithTypeElement = current.GetQualifier() as IQualifierWithTypeElement;
if (qualifierWithTypeElement == null) {
continue;
}
var qualifierTypeElement = qualifierWithTypeElement.GetQualifierTypeElement();
if (qualifierTypeElement != null) {
return qualifierTypeElement;
}
}
return null;
}