本文整理汇总了C#中LanguageElement类的典型用法代码示例。如果您正苦于以下问题:C# LanguageElement类的具体用法?C# LanguageElement怎么用?C# LanguageElement使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
LanguageElement类属于命名空间,在下文中一共展示了LanguageElement类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetClassBaseType
} // IsClass
/// <summary>
/// Get class base type
/// </summary>
private static TypeReferenceExpression GetClassBaseType(LanguageElement classElement)
{
LanguageElement current = classElement.FirstDetail;
while (current != null && !IsClass(current))
current = current.NextSibling;
return (TypeReferenceExpression)current;
} // GetClassBaseType
示例2: IsValidReferenceAndQualifier
private bool IsValidReferenceAndQualifier(LanguageElement activeRerence, out ITypeElement callerType, out Expression qualifier)
{
qualifier = null;
callerType = null;
if (!(activeRerence is IHasQualifier))
return false;
// should be undeclared....
IElement declaration = activeRerence.GetDeclaration(false);
if (declaration != null)
return false;
qualifier = (activeRerence as IHasQualifier).Qualifier;
if (qualifier is MethodReferenceExpression)
qualifier = (qualifier as MethodReferenceExpression).Qualifier;
if (qualifier == null)
return false;
callerType = qualifier.Resolve(ParserServices.SourceTreeResolver) as ITypeElement;
if (callerType == null)
return false;
return true;
}
示例3: Scan
public void Scan()
{
_ElementType = LanguageElementType.Unknown;
_ElementsFound = 0;
_TopNode = null;
CodeRush.Source.IterateNodesInSelection(NodeIterator);
}
示例4: IsMethodCall
private bool IsMethodCall(LanguageElement Item)
{
if (Item is MethodCall)
{
// Calls which discard any returned value.
return true;
}
if (Item is MethodCallExpression)
{
// Method calls which are themselves passed to other methods.
return true;
}
// C# requires parenthesis for it's method calls. This makes identifying method calls very easy.
// Other languages (VB.Net for example) do not share this requirement.
// References to Methods and Variables end up looking exactly the same to the parser.
// ElementReferenceExpressions may potentially refer to Methods.
if (!(Item is ElementReferenceExpression))
return false;
// This forces us to locate the declaration of the item the reference points at.
// Once there we can confirm if the Item in question is a Method.
if (!(Item.GetDeclaration() is IMethodElement))
return false;
// Finally we need to confirm that the method reference is in fact a call.
// We do this by eliminating the other purpose of a method reference: That of a Method pointer.
// No parent AddressOf operator. Therefore not a method pointer.
if (!(Item.Parent is AddressOfExpression))
return true;
return false;
}
示例5: GetAllPropertyReferences
private static FileSourceRangeCollection GetAllPropertyReferences(LanguageElement startElement)
{
FileSourceRangeCollection allReferences = new FileSourceRangeCollection();
Property property;
PrimitiveExpression primitiveExpression;
if (!GetPrimitiveExpressionAndProperty(startElement, out primitiveExpression, out property))
return allReferences;
// Add references found...
IElementCollection allPropertyReferences = property.FindAllReferences();
foreach (IElement element in allPropertyReferences)
allReferences.Add(new FileSourceRange(element.FirstFile as SourceFile, element.FirstNameRange));
// Add the contents of the string primitive...
SourceRange primitiveRange = primitiveExpression.NameRange;
int nameStart = primitiveExpression.Name.IndexOf(property.Name);
int nameEndMargin = primitiveExpression.Name.Length - property.Name.Length - nameStart;
primitiveRange.Start.Offset += nameStart;
primitiveRange.End.Offset -= nameEndMargin;
allReferences.Add(new FileSourceRange(primitiveExpression.FileNode, primitiveRange));
// Add the NameRange of the property declaration itself....
allReferences.Add(new FileSourceRange(property.FileNode, property.NameRange));
return allReferences;
}
示例6: PromoteIfReference
private LanguageElement PromoteIfReference(LanguageElement element)
{
if (element.ElementType == LanguageElementType.MethodReferenceExpression)
if (element.Parent.ElementType == LanguageElementType.MethodCallExpression)
return element.Parent;
return element;
}
示例7: GetNamespaceReference
private ElementReferenceExpression GetNamespaceReference(LanguageElement element)
{
MethodReferenceExpression methodReference = element as MethodReferenceExpression;
MethodCall methodCall = methodReference.Parent as MethodCall;
ElementReferenceExpression classReference = methodReference.Nodes[0] as ElementReferenceExpression;
ElementReferenceExpression namespaceReference = classReference.Nodes[0] as ElementReferenceExpression;
return namespaceReference;
}
示例8: events_LanguageElementActivated
private void events_LanguageElementActivated(LanguageElementActivatedEventArgs ea)
{
LanguageElement activeMember = CodeRush.Source.ActiveMember;
if (lastMember == activeMember)
return;
lastMember = activeMember;
ShowCode();
}
示例9: GetBestLocation
public SourcePoint GetBestLocation(LanguageElement element)
{
int smallestLineDeltaSoFar = int.MaxValue;
int smallestOffsetDeltaSoFar = int.MaxValue;
ElementLocation location = this;
SourcePoint result = SourcePoint.Empty;
LanguageElement parent = null;
while (location != null && element != null)
{
CaretVector vector = location._Vector;
int lineDeltaSize = Math.Abs(vector.LineDelta);
int offsetDeltaSize = Math.Abs(vector.OffsetDelta);
if (lineDeltaSize < smallestLineDeltaSoFar || (lineDeltaSize == smallestLineDeltaSoFar && offsetDeltaSize < smallestOffsetDeltaSoFar))
{
// Found a smaller vector...
SourcePoint newPosition = GetSourcePoint(element, vector);
if (newPosition != SourcePoint.Empty)
{
result = newPosition;
smallestLineDeltaSoFar = lineDeltaSize;
smallestOffsetDeltaSoFar = offsetDeltaSize;
if (lineDeltaSize == 0 && offsetDeltaSize == 0)
if (vector.ElementPosition != ElementPosition.LastDetailEnd || element.ElementType != LanguageElementType.Method && element.ElementType != LanguageElementType.Property)
return result;
}
}
location = location._Child;
parent = element;
element = GetChildElement(element, location);
if (location != null && element == null)
{
// We were expecting a child but found nothing...
if (location._ElementType == LanguageElementType.Parameter)
{
Method method = parent as Method;
if (method != null)
return method.ParamOpenRange.End;
else
{
Property property = parent as Property;
if (property != null)
return property.NameRange.End;
}
}
else
{
SourcePoint newDefaultPosition = GetDefaultPosition(parent);
if (newDefaultPosition != SourcePoint.Empty)
return newDefaultPosition;
}
}
}
return result;
}
示例10: GetTypeReference
/// <summary>
/// Gets the type reference pointed to by a qualifying namespace reference.
/// </summary>
private static TypeReferenceExpression GetTypeReference(LanguageElement namespaceReference)
{
LanguageElement parentTypeReference = namespaceReference.Parent;
while (parentTypeReference is TypeReferenceExpression && parentTypeReference.IsDetailNode && parentTypeReference.Parent != null && parentTypeReference.Parent is TypeReferenceExpression)
parentTypeReference = parentTypeReference.Parent;
if (parentTypeReference is TypeReferenceExpression /* && !parentTypeReference.IsDetailNode */) // We've found the class reference...
return (TypeReferenceExpression)parentTypeReference;
return null;
}
示例11: CurrentNamespace
private string CurrentNamespace(LanguageElement element)
{
var names = new List<string>();
while (element != null && element.ElementType == LanguageElementType.Namespace)
{
names.Add(element.Name);
element = element.Parent;
}
return string.Join(".", names.Reverse<string>().ToArray());
}
示例12: IsValidSelection
protected override bool IsValidSelection(LanguageElement element, TextViewSelection selection)
{
if ((element == null) || (selection == null))
return false;
if (selection.Exists)
return false;
var creationExpression = element.Parent as ObjectCreationExpression;
return creationExpression != null && element.GetDeclaration() == null;
}
示例13: GetAssignmentExpression
private static AssignmentExpression GetAssignmentExpression(LanguageElement element)
{
// Rory is right. ea.Element will not always be equal to CodeRush.Source.Active.
// Also, CodeProviders can be called programmatically, targeting other places.
// Rory recommends always exhausting the ea.Xxxxxxx methods and properties, before looking elsewhere.
AssignmentExpression assignmentExpression = element as AssignmentExpression;
if (assignmentExpression == null)
assignmentExpression = element.GetParent(LanguageElementType.AssignmentExpression) as AssignmentExpression;
return assignmentExpression;
}
示例14: IsApproveCall
private static bool IsApproveCall(LanguageElement element)
{
if (element.ElementType == LanguageElementType.MethodCall && element.Name.Contains("Approve"))
return true;
if (element.Parent != null)
return IsApproveCall(element.Parent);
return false;
}
示例15: AddAttribute
private void AddAttribute(LanguageElement element, string AttributeName)
{
var Builder = new ElementBuilder();
var Attribute = Builder.BuildAttribute(AttributeName);
var Section = Builder.BuildAttributeSection();
Section.AddAttribute(Attribute);
var Code = CodeRush.CodeMod.GenerateCode(Section, false);
SourcePoint InsertionPoint = new SourcePoint(element.Range.Start.Line, 1);
CodeRush.Documents.ActiveTextDocument.QueueInsert(InsertionPoint, Code);
}