本文整理汇总了C#中ICodeElement类的典型用法代码示例。如果您正苦于以下问题:C# ICodeElement类的具体用法?C# ICodeElement怎么用?C# ICodeElement使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ICodeElement类属于命名空间,在下文中一共展示了ICodeElement类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Violation
/// <summary>
/// Initializes a new instance of the Violation class.
/// </summary>
/// <param name="rule">
/// The rule that triggered the violation.
/// </param>
/// <param name="element">
/// The element that this violation appears in.
/// </param>
/// <param name="location">
/// The location in the source code where the violation occurs.
/// </param>
/// <param name="message">
/// The context message for the violation.
/// </param>
internal Violation(Rule rule, ICodeElement element, CodeLocation location, string message)
{
Param.AssertNotNull(rule, "rule");
Param.Ignore(element);
Param.AssertNotNull(location, "location");
Param.AssertNotNull(message, "message");
this.rule = rule;
this.element = element;
// The CodeLocation passed in is zero based everywhere in StyleCop for the column. The line number is already 1 based.
// We convert is to 1 based here so that are xml reports etc and VisualStudio UI friendly.
this.location = new CodeLocation(
location.StartPoint.Index,
location.EndPoint.Index,
location.StartPoint.IndexOnLine + 1,
location.EndPoint.IndexOnLine + 1,
location.StartPoint.LineNumber,
location.EndPoint.LineNumber);
// If the location has been passed in we set the linenumber.
this.line = location.LineNumber;
this.message = message;
if (this.element != null && this.element.Document != null)
{
this.sourceCode = this.element.Document.SourceCode;
}
this.UpdateKey();
}
示例2: Format
/// <summary>
/// Gets a string representation of a code element using the specified
/// format.
/// </summary>
/// <param name="format">The format.</param>
/// <param name="codeElement">The code element.</param>
/// <returns>Formatted string representation of the code element.</returns>
public static string Format(string format, ICodeElement codeElement)
{
if (format == null)
{
throw new ArgumentNullException("format");
}
else if (codeElement == null)
{
throw new ArgumentNullException("codeElement");
}
StringBuilder formatted = new StringBuilder(format.Length*2);
StringBuilder attributeBuilder = null;
bool inAttribute = false;
using (StringReader reader = new StringReader(format))
{
int data = reader.Read();
while (data > 0)
{
char ch = (char) data;
if (ch == ConditionExpressionParser.ExpressionPrefix &&
(char) (reader.Peek()) == ConditionExpressionParser.ExpressionStart)
{
reader.Read();
attributeBuilder = new StringBuilder(16);
inAttribute = true;
}
else if (inAttribute)
{
if (ch == ConditionExpressionParser.ExpressionEnd)
{
ElementAttributeType elementAttribute = (ElementAttributeType) Enum.Parse(
typeof (ElementAttributeType), attributeBuilder.ToString());
string attribute = GetAttribute(elementAttribute, codeElement);
formatted.Append(attribute);
attributeBuilder = new StringBuilder(16);
inAttribute = false;
}
else
{
attributeBuilder.Append(ch);
}
}
else
{
formatted.Append(ch);
}
data = reader.Read();
}
}
return formatted.ToString();
}
示例3: Violation
/// <summary>
/// Initializes a new instance of the Violation class.
/// </summary>
/// <param name="rule">The rule that triggered the violation.</param>
/// <param name="element">The element that this violation appears in.</param>
/// <param name="line">The line in the source code where the violation occurs.</param>
/// <param name="message">The context message for the violation.</param>
internal Violation(Rule rule, ICodeElement element, int line, string message)
{
Param.AssertNotNull(rule, "rule");
Param.Ignore(element);
Param.AssertGreaterThanOrEqualToZero(line, "line");
Param.AssertNotNull(message, "message");
this.rule = rule;
this.element = element;
this.line = line;
this.message = message;
if (this.element != null && this.element.Document != null)
{
this.sourceCode = this.element.Document.SourceCode;
}
}
示例4: GetTypeParent
/// <summary>
/// Gets the type parent.
/// </summary>
/// <param name="element">The element.</param>
/// <returns>The Type parent.</returns>
private static TypeElement GetTypeParent(ICodeElement element)
{
TypeElement parentTypeElement = element.Parent as TypeElement;
if (parentTypeElement == null &&
(element.Parent is GroupElement || element.Parent is RegionElement))
{
parentTypeElement = GetTypeParent(element.Parent);
}
return parentTypeElement;
}
示例5: AddViolation
/// <summary>
/// Adds one violation to the given code element.
/// </summary>
/// <param name="element">The element that the violation appears in.</param>
/// <param name="line">The line in the code where the violation occurs.</param>
/// <param name="ruleName">The name of the rule that triggered the violation.</param>
/// <param name="values">String parameters to insert into the violation string.</param>
public void AddViolation(ICodeElement element, int line, Enum ruleName, params object[] values)
{
Param.Ignore(element);
Param.Ignore(line);
Param.RequireNotNull(ruleName, "ruleName");
Param.Ignore(values);
this.AddViolation(element, line, ruleName.ToString(), values);
}
示例6: TryParseElement
/// <summary>
/// Tries to parse a code element.
/// </summary>
/// <param name="parentElement">The parent element.</param>
/// <param name="elementBuilder">The element builder.</param>
/// <param name="comments">The comments.</param>
/// <param name="attributes">The attributes.</param>
/// <returns>Code element is succesful, otherwise null.</returns>
private ICodeElement TryParseElement(
ICodeElement parentElement,
StringBuilder elementBuilder,
ReadOnlyCollection<ICommentElement> comments,
ReadOnlyCollection<AttributeElement> attributes)
{
CodeElement codeElement = null;
string processedElementText =
elementBuilder.ToString().Trim();
switch (VBKeyword.Normalize(processedElementText))
{
case VBKeyword.Namespace:
codeElement = ParseNamespace();
break;
case VBKeyword.Imports:
codeElement = ParseImport();
break;
}
if (codeElement == null)
{
string[] words = processedElementText.TrimEnd(
VBSymbol.Assignment,
VBSymbol.BeginParameterList).Split(
WhiteSpaceCharacters,
StringSplitOptions.RemoveEmptyEntries);
if (words.Length > 0)
{
string normalizedKeyWord = VBKeyword.Normalize(words[0]);
if (words.Length > 1 ||
normalizedKeyWord == VBKeyword.Class ||
normalizedKeyWord == VBKeyword.Structure ||
normalizedKeyWord == VBKeyword.Interface ||
normalizedKeyWord == VBKeyword.Enumeration ||
normalizedKeyWord == VBKeyword.Module ||
normalizedKeyWord == VBKeyword.Sub ||
normalizedKeyWord == VBKeyword.Function ||
normalizedKeyWord == VBKeyword.Property ||
normalizedKeyWord == VBKeyword.Delegate ||
normalizedKeyWord == VBKeyword.Event)
{
StringCollection wordList = new StringCollection();
wordList.AddRange(words);
StringCollection normalizedWordList = new StringCollection();
foreach (string word in wordList)
{
normalizedWordList.Add(VBKeyword.Normalize(word));
}
string name = string.Empty;
ElementType elementType;
CodeAccess access = CodeAccess.None;
MemberModifiers memberAttributes = MemberModifiers.None;
TypeElementType? typeElementType = null;
bool isAssignment = processedElementText[processedElementText.Length - 1] == VBSymbol.Assignment;
bool isField = normalizedWordList[normalizedWordList.Count - 1] == VBKeyword.As ||
isAssignment;
if (isField)
{
elementType = ElementType.Field;
}
else
{
GetElementType(normalizedWordList, out elementType, out typeElementType);
}
if (elementType == ElementType.Method ||
elementType == ElementType.Property ||
elementType == ElementType.Event ||
elementType == ElementType.Delegate ||
elementType == ElementType.Type ||
elementType == ElementType.Field)
{
access = GetAccess(normalizedWordList);
memberAttributes = GetMemberAttributes(normalizedWordList);
}
TypeElement parentTypeElement = parentElement as TypeElement;
bool inInterface = parentTypeElement != null &&
parentTypeElement.Type == TypeElementType.Interface;
switch (elementType)
{
case ElementType.Type:
TypeModifiers typeAttributes = (TypeModifiers)memberAttributes;
//.........这里部分代码省略.........
示例7: Visit
public virtual void Visit (ICodeElement node)
{
if (null == node) return;
node.Accept (this);
}
示例8: WriteBlockChildren
/// <summary>
/// Writes children for a block element.
/// </summary>
/// <param name="element">Element whose children will be written.</param>
protected virtual void WriteBlockChildren(ICodeElement element)
{
if (element.Children.Count == 0)
{
Writer.WriteLine();
}
else
{
//
// Process all children
//
WriteChildren(element);
}
}
示例9: Assign
// todo: allow only multiple partial classes
internal void Assign(ICodeElement codeElement)
{
if (codeElement == null)
{
throw new ArgumentException("codeElement");
}
Contract.EndContractBlock();
if (this.codeElement == null)
{
this.codeElement = codeElement;
}
else
{
if (this.codeElements == null)
{
this.codeElements = new List<ICodeElement>();
}
var typeDefinitionMetadataICodeElementAdapter = codeElement as TypeDefinitionMetadataICodeElementAdapter;
if (typeDefinitionMetadataICodeElementAdapter != null
&& !typeDefinitionMetadataICodeElementAdapter.TypeDefinition.Type.HasFlag(CorTypeAttr.Import))
{
this.codeElements.Add(this.codeElement);
this.codeElement = codeElement;
}
else
{
this.codeElements.Add(codeElement);
}
}
}
示例10: AddChild
/// <summary>
/// Adds a child to this element.
/// </summary>
/// <param name="childElement">Child to add.</param>
public virtual void AddChild(ICodeElement childElement)
{
if (childElement != null)
{
lock (_childrenLock)
{
if (childElement != null && !BaseChildren.Contains(childElement))
{
BaseChildren.Add(childElement);
childElement.Parent = this;
}
}
}
}
示例11: ArrangeChildElement
/// <summary>
/// Arranges the child element.
/// </summary>
/// <param name="codeElement">The code element.</param>
/// <param name="childElement">The child element.</param>
private void ArrangeChildElement(ICodeElement codeElement, ICodeElement childElement)
{
//
// Region elements are ignored. Only process their children.
//
RegionElement regionElement = childElement as RegionElement;
if (regionElement != null)
{
List<ICodeElement> regionChildren = new List<ICodeElement>(regionElement.Children);
regionElement.ClearChildren();
foreach (ICodeElement regionChildElement in regionChildren)
{
_childrenArranger.ArrangeElement(codeElement, regionChildElement);
}
}
else
{
_childrenArranger.ArrangeElement(codeElement, childElement);
}
}
示例12: CanArrange
/// <summary>
/// Determines whether or not the specified element can be arranged by
/// this arranger.
/// </summary>
/// <param name="parentElement">The parent element.</param>
/// <param name="codeElement">The code element.</param>
/// <returns>
/// <c>true</c> if this instance can arrange the specified parent element; otherwise, <c>false</c>.
/// </returns>
public virtual bool CanArrange(ICodeElement parentElement, ICodeElement codeElement)
{
// Clone the instance and assign the parent
ICodeElement testCodeElement = codeElement;
if (_filter == null && _elementConfiguration.FilterBy != null)
{
_filter = CreateElementFilter(_elementConfiguration.FilterBy);
}
if (parentElement != null &&
_filter != null && _filter.RequiredScope == ElementAttributeScope.Parent)
{
testCodeElement = codeElement.Clone() as ICodeElement;
testCodeElement.Parent = parentElement.Clone() as ICodeElement;
}
return (_elementConfiguration.ElementType == ElementType.NotSpecified ||
codeElement.ElementType == _elementConfiguration.ElementType) &&
(_filter == null || _filter.IsMatch(testCodeElement));
}
示例13: ArrangeElement
/// <summary>
/// Arranges the element in within the code tree represented in the specified
/// builder.
/// </summary>
/// <param name="parentElement">The parent element.</param>
/// <param name="codeElement">The code element.</param>
public virtual void ArrangeElement(ICodeElement parentElement, ICodeElement codeElement)
{
if (codeElement.Children.Count > 0)
{
if (_childrenArranger == null)
{
_childrenArranger = ElementArrangerFactory.CreateChildrenArranger(_elementConfiguration);
}
if (_childrenArranger != null)
{
List<ICodeElement> children = new List<ICodeElement>(codeElement.Children);
codeElement.ClearChildren();
foreach (ICodeElement childElement in children)
{
ArrangeChildElement(codeElement, childElement);
}
//
// For condition directives, arrange the children of each node in the list.
//
ConditionDirectiveElement conditionDirective = codeElement as ConditionDirectiveElement;
if (conditionDirective != null)
{
//
// Skip the first instance since we've already arranged those child elements.
//
conditionDirective = conditionDirective.ElseCondition;
}
while (conditionDirective != null)
{
children = new List<ICodeElement>(conditionDirective.Children);
conditionDirective.ClearChildren();
foreach (ICodeElement childElement in children)
{
ArrangeChildElement(conditionDirective, childElement);
}
conditionDirective = conditionDirective.ElseCondition;
}
}
}
if (_inserter == null)
{
_inserter = CreateElementInserter(
_elementConfiguration.ElementType,
_elementConfiguration.SortBy,
_elementConfiguration.GroupBy,
_parentConfiguration);
}
// For Type elements, if interdependent static fields are present, correct their
// ordering.
TypeElement typeElement = codeElement as TypeElement;
if (typeElement != null &&
(typeElement.Type == TypeElementType.Class || typeElement.Type == TypeElementType.Structure ||
typeElement.Type == TypeElementType.Module))
{
CorrectStaticFieldDependencies(typeElement);
}
_inserter.InsertElement(parentElement, codeElement);
}
示例14: CanArrange
/// <summary>
/// Determines whether or not this arranger can handle arrangement of
/// the specified element.
/// </summary>
/// <param name="parentElement">The parent element.</param>
/// <param name="codeElement">The code element.</param>
/// <returns>
/// <c>true</c> if this instance can arrange the specified parent element; otherwise, <c>false</c>.
/// </returns>
public bool CanArrange(ICodeElement parentElement, ICodeElement codeElement)
{
InitializeChildrenArranger();
return _childrenArranger.CanArrange(parentElement, codeElement);
}
示例15: Add
internal void Add(ICodeElement codeElement)
{
if (codeElement == null)
{
throw new ArgumentException("codeElement");
}
Contract.EndContractBlock();
this.Add(codeElement.FullyQualifiedName, codeElement);
}