本文整理汇总了C#中ICodeElement类的典型用法代码示例。如果您正苦于以下问题:C# ICodeElement类的具体用法?C# ICodeElement怎么用?C# ICodeElement使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ICodeElement类属于命名空间,在下文中一共展示了ICodeElement类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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();
}
开发者ID:transformersprimeabcxyz,项目名称:_TO-FIRST-stylecop,代码行数:46,代码来源:Violation.cs
示例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();
}
开发者ID:MarcStan,项目名称:NArrange,代码行数:64,代码来源:ElementUtilities.cs
示例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;
}
}
开发者ID:katerina-marchenkova,项目名称:my,代码行数:24,代码来源:Violation.cs
示例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;
}
开发者ID:AlmatoolboxCE,项目名称:AlmaStyleFix,代码行数:17,代码来源:VBWriteVisitor.cs
示例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);
}
开发者ID:katerina-marchenkova,项目名称:my,代码行数:16,代码来源:StyleCopAddIn.cs
示例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;
//.........这里部分代码省略.........
开发者ID:samuel-weber,项目名称:NArrange,代码行数:101,代码来源:VBParser.cs
示例7: Visit
public virtual void Visit (ICodeElement node)
{
if (null == node) return;
node.Accept (this);
}
开发者ID:transformersprimeabcxyz,项目名称:cecil-old,代码行数:5,代码来源:AbstractCodeStructureVisitor.cs
示例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);
}
}
开发者ID:raghurana,项目名称:NArrange,代码行数:18,代码来源:CodeWriteVisitor.cs
示例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);
}
}
}
开发者ID:andyhebear,项目名称:CsharpToCppConverter,代码行数:34,代码来源:FullyQualifiedNamesCache.cs
示例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;
}
}
}
}
开发者ID:AlmatoolboxCE,项目名称:AlmaStyleFix,代码行数:18,代码来源:CodeElement.cs
示例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);
}
}
开发者ID:MarcStan,项目名称:NArrange,代码行数:26,代码来源:ElementArranger.cs
示例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));
}
开发者ID:MarcStan,项目名称:NArrange,代码行数:30,代码来源:ElementArranger.cs
示例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);
}
开发者ID:MarcStan,项目名称:NArrange,代码行数:71,代码来源:ElementArranger.cs
示例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);
}
开发者ID:AlmatoolboxCE,项目名称:AlmaStyleFix,代码行数:14,代码来源:RegionArranger.cs
示例15: Add
internal void Add(ICodeElement codeElement)
{
if (codeElement == null)
{
throw new ArgumentException("codeElement");
}
Contract.EndContractBlock();
this.Add(codeElement.FullyQualifiedName, codeElement);
}
开发者ID:andyhebear,项目名称:CsharpToCppConverter,代码行数:11,代码来源:FullyQualifiedNamesCache.cs
示例16: InsertChild
/// <summary>
/// Inserts a child element at the specified index.
/// </summary>
/// <param name="index">Index to insert at.</param>
/// <param name="childElement">Element to insert.</param>
public virtual void InsertChild(int index, ICodeElement childElement)
{
if (childElement != null)
{
lock (_childrenLock)
{
if (BaseChildren.Contains(childElement))
{
BaseChildren.Remove(childElement);
}
BaseChildren.Insert(index, childElement);
childElement.Parent = this;
}
}
}
开发者ID:AlmatoolboxCE,项目名称:AlmaStyleFix,代码行数:21,代码来源:CodeElement.cs
示例17: RemoveChild
/// <summary>
/// Removes a child from this element.
/// </summary>
/// <param name="childElement">Child element to remove.</param>
public virtual void RemoveChild(ICodeElement childElement)
{
if (childElement != null && BaseChildren.Contains(childElement))
{
lock (_childrenLock)
{
if (childElement != null && BaseChildren.Contains(childElement))
{
BaseChildren.Remove(childElement);
childElement.Parent = null;
}
}
}
}
开发者ID:AlmatoolboxCE,项目名称:AlmaStyleFix,代码行数:18,代码来源:CodeElement.cs
示例18: WriteChildren
/// <summary>
/// Writes child elements.
/// </summary>
/// <param name="element">Element whose children will be written.</param>
protected void WriteChildren(ICodeElement element)
{
if (element.Children.Count > 0)
{
Writer.WriteLine();
}
CodeWriter.WriteVisitElements(element.Children, Writer, this);
if (element.Children.Count > 0)
{
Writer.WriteLine();
}
}
开发者ID:raghurana,项目名称:NArrange,代码行数:18,代码来源:CodeWriteVisitor.cs
示例19: WriteBlockChildren
/// <summary>
/// Writes children for a block element.
/// </summary>
/// <param name="element">Block code element.</param>
protected override void WriteBlockChildren(ICodeElement element)
{
if (element.Children.Count > 0)
{
Writer.WriteLine();
}
base.WriteBlockChildren(element);
if (element.Children.Count > 0)
{
Writer.WriteLine();
}
}
开发者ID:AlmatoolboxCE,项目名称:AlmaStyleFix,代码行数:18,代码来源:VBWriteVisitor.cs
示例20: IsRuleSuppressed
/// <summary>
/// Checks whether specified rule is suppressed.
/// </summary>
public override bool IsRuleSuppressed(ICodeElement element, Rule rule)
{
return false;
}
开发者ID:katerina-marchenkova,项目名称:my,代码行数:7,代码来源:CustomNamingRules.cs
注:本文中的ICodeElement类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论