本文整理汇总了C#中CsElement类的典型用法代码示例。如果您正苦于以下问题:C# CsElement类的具体用法?C# CsElement怎么用?C# CsElement使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
CsElement类属于命名空间,在下文中一共展示了CsElement类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。
示例1: GetCodeIssues
public IEnumerable<StyleCopCodeIssue> GetCodeIssues(
ISourceCode sourceCode,
Func<ElementTypeFilter, IEnumerable<IElement>> enumerate,
Violation violation,
CsElement csElement)
{
CodePoint startPoint = null;
CodePoint endPoint = null;
foreach (var token in from token in csElement.ElementTokens
where token.LineNumber >= violation.Line
select token)
{
if (token.CsTokenType == CsTokenType.UsingDirective || token.CsTokenType == CsTokenType.Using)
{
startPoint = token.Location.StartPoint;
continue;
}
if (token.CsTokenType == CsTokenType.Semicolon)
{
endPoint = token.Location.EndPoint;
}
if (startPoint != null && endPoint != null)
{
var sourceRange = new SourceRange(startPoint.LineNumber, startPoint.IndexOnLine + 1, endPoint.LineNumber, endPoint.IndexOnLine + 2);
yield return new StyleCopCodeIssue(CodeIssueType.CodeSmell, sourceRange);
}
}
}
开发者ID:kevinmiles,项目名称:dxcorecommunityplugins,代码行数:30,代码来源:UsingDirectiveCodeIssue.cs
示例2: GetCodeIssues
public IEnumerable<StyleCopCodeIssue> GetCodeIssues(
ISourceCode sourceCode,
Func<ElementTypeFilter, IEnumerable<IElement>> enumerate,
Violation violation,
CsElement csElement)
{
var preprocessorToken = (from token in csElement.ElementTokens
where token.LineNumber == violation.Line && token.CsTokenType == CsTokenType.PreprocessorDirective
select token).FirstOrDefault();
if (preprocessorToken != null)
{
int underlineLength = 1;
while (preprocessorToken.Text[underlineLength] == ' ' || preprocessorToken.Text[underlineLength] == '\t')
{
underlineLength++;
}
while (underlineLength < preprocessorToken.Text.Length && preprocessorToken.Text[underlineLength] != ' ' && preprocessorToken.Text[underlineLength] != '\t')
{
underlineLength++;
}
var startPoint = preprocessorToken.Location.StartPoint;
var sourceRange = new SourceRange(startPoint.LineNumber, startPoint.IndexOnLine + 1, startPoint.LineNumber, startPoint.IndexOnLine + 1 + underlineLength);
yield return new StyleCopCodeIssue(CodeIssueType.CodeSmell, sourceRange);
}
}
开发者ID:kevinmiles,项目名称:dxcorecommunityplugins,代码行数:27,代码来源:PreprocessorDirectiveIssueLocator.cs
示例3: Property
/// <summary>
/// Initializes a new instance of the Property class.
/// </summary>
/// <param name="document">
/// The document that contains the element.
/// </param>
/// <param name="parent">
/// The parent of the element.
/// </param>
/// <param name="header">
/// The Xml header for this element.
/// </param>
/// <param name="attributes">
/// The list of attributes attached to this element.
/// </param>
/// <param name="declaration">
/// The declaration code for this element.
/// </param>
/// <param name="returnType">
/// The property return type.
/// </param>
/// <param name="unsafeCode">
/// Indicates whether the element resides within a block of unsafe code.
/// </param>
/// <param name="generated">
/// Indicates whether the code element was generated or written by hand.
/// </param>
internal Property(
CsDocument document,
CsElement parent,
XmlHeader header,
ICollection<Attribute> attributes,
Declaration declaration,
TypeToken returnType,
bool unsafeCode,
bool generated)
: base(document, parent, ElementType.Property, "property " + declaration.Name, header, attributes, declaration, unsafeCode, generated)
{
Param.AssertNotNull(document, "document");
Param.AssertNotNull(parent, "parent");
Param.Ignore(header);
Param.Ignore(attributes);
Param.AssertNotNull(declaration, "declaration");
Param.AssertNotNull(returnType, "returnType");
Param.Ignore(unsafeCode);
Param.Ignore(generated);
this.returnType = returnType;
// If this is an explicit interface member implementation and our access modifier
// is currently set to private because we don't have one, then it should be public instead.
if (this.Declaration.Name.IndexOf(".", StringComparison.Ordinal) > -1 && !this.Declaration.Name.StartsWith("this.", StringComparison.Ordinal))
{
this.Declaration.AccessModifierType = AccessModifierType.Public;
}
}
开发者ID:RainsSoft,项目名称:StyleCop,代码行数:56,代码来源:Property.cs
示例4: CheckClasses
/// <summary>
/// Checks whether specified element conforms to custom rule GP0001
/// </summary>
/// <param name="element">
/// The current element that is to be inspected.
/// </param>
/// <param name="parentElement">
/// The parent element for the element currently being inspected.
/// </param>
/// <param name="context">
/// The context.
/// </param>
/// <returns>
/// True/False indicating whether to continue walking the elements within the class.
/// </returns>
private bool CheckClasses(CsElement element, CsElement parentElement, object context)
{
// If the overall StyleCop is cancelled externally, then stop processing
if (Cancel)
{
return false;
}
// if current element is not a class then continue walking
if (element.ElementType != ElementType.Class)
{
return true;
}
// check whether class name contains "a" letter
var classElement = (Class)element;
if (classElement.Declaration.Name.Contains("a"))
{
// add violation
// (note how custom message arguments could be used)
AddViolation(
classElement, classElement.Location, "AvoidUsingAInClassNames", classElement.FriendlyTypeText);
}
if (classElement.Declaration.Name.Length > MaximumClassNameLength)
{
// add violation
// (note how custom message arguments could be used)
AddViolation(classElement, classElement.Location, "AvoidLongClassNames", classElement.FriendlyTypeText);
}
// continue walking in order to find all classes in file
return true;
}
开发者ID:gep13,项目名称:StyleCopDemos,代码行数:49,代码来源:MyCustomAnalyzer.cs
示例5: VisitElement
public override void VisitElement(CsElement element, CsElement parentElement, object context)
{
if ((element.ElementType == ElementType.Method && ((Method)element).ReturnType.Text != "void") // Func
|| (element.ElementType == ElementType.Accessor && ((Accessor)element).AccessorType == AccessorType.Get)) // Getter
{
if (element.ElementTokens.Count(x => x.CsTokenType == CsTokenType.Return) > 1)
{
this.SourceAnalyzer.AddViolation(element, ContribRule.SingleReturnStatement);
}
}
else if (element.ElementType == ElementType.Constructor
|| (element.ElementType == ElementType.Method && ((Method)element).ReturnType.Text == "void") // Proc
|| (element.ElementType == ElementType.Accessor && ((Accessor)element).AccessorType != AccessorType.Get)) // Setter, Add, Remove
{
if (element.ElementTokens.Any(x => x.CsTokenType == CsTokenType.Return))
{
this.SourceAnalyzer.AddViolation(element, ContribRule.ReturnStatementOnlyInFunctions);
}
}
else if (element.ElementType == ElementType.Class)
{
if (element.Declaration.Name.Length > MaximumClassNameLength)
{
this.SourceAnalyzer.AddViolation(element, ContribRule.ClassNameLengthExceeded);
}
}
}
开发者ID:gep13,项目名称:StyleCopDemos,代码行数:27,代码来源:MaintainabilityAnalyzer.cs
示例6: GetCodeIssues
public IEnumerable<StyleCopCodeIssue> GetCodeIssues(
ISourceCode sourceCode,
Func<ElementTypeFilter, IEnumerable<IElement>> enumerate,
Violation violation,
CsElement csElement)
{
bool specialPredecessorFound = true;
bool whitespaceFound = false;
foreach (var token in this.getTokens(csElement).Flatten().Where(x => x.LineNumber == violation.Line))
{
if (!specialPredecessorFound && whitespaceFound && this.reportIssueFor(token, violation))
{
whitespaceFound = false;
yield return new StyleCopCodeIssue(CodeIssueType.CodeSmell, new SourceRange(token.Location.StartPoint.LineNumber, token.Location.StartPoint.IndexOnLine + 1, token.Location.EndPoint.LineNumber, token.Location.EndPoint.IndexOnLine + 2));
}
else if (this.specialPredecessors.Contains(token.CsTokenType))
{
specialPredecessorFound = true;
whitespaceFound = false;
}
else if (token.CsTokenType == CsTokenType.WhiteSpace)
{
whitespaceFound = true;
}
else
{
specialPredecessorFound = false;
whitespaceFound = false;
}
}
}
开发者ID:kevinmiles,项目名称:dxcorecommunityplugins,代码行数:31,代码来源:AllTokensPrecededByBannedWhitespaceNotPrecededBySpecialElementIssueLocator.cs
示例7: elementCallback
private bool elementCallback(CsElement element, CsElement parentElement, object context)
{
if (element.Header != null)
{
XDocument xml;
try
{
var xmlText = string.Format("<root>{0}</root>", element.Header.RawText);
xml = XDocument.Parse(xmlText, LoadOptions.PreserveWhitespace); // Header.Text / Header.RawText の違いを気にしていない
}
catch
{
return true; // XMLコメントの形式ミスはこのルールで検出しない
}
foreach (var xpathRule in rules)
{
if (xml.XPathEvaluate<XObject>(xpathRule.XPath).Any())
{
this.Violate(element, element.Header.Location, xpathRule.Message);
}
}
}
return true;
}
开发者ID:lavn0,项目名称:CodeAnalysis,代码行数:26,代码来源:XmlCommentRule.cs
示例8: Destructor
/// <summary>
/// Initializes a new instance of the Destructor class.
/// </summary>
/// <param name="document">The documenent that contains the element.</param>
/// <param name="parent">The parent of the element.</param>
/// <param name="header">The Xml header for this element.</param>
/// <param name="attributes">The list of attributes attached to this element.</param>
/// <param name="declaration">The declaration code for this element.</param>
/// <param name="unsafeCode">Indicates whether the element resides within a block of unsafe code.</param>
/// <param name="generated">Indicates whether the code element was generated or written by hand.</param>
internal Destructor(
CsDocument document,
CsElement parent,
XmlHeader header,
ICollection<Attribute> attributes,
Declaration declaration,
bool unsafeCode,
bool generated)
: base(document,
parent,
ElementType.Destructor,
"destructor " + declaration.Name,
header,
attributes,
declaration,
unsafeCode,
generated)
{
Param.AssertNotNull(document, "document");
Param.AssertNotNull(parent, "parent");
Param.Ignore(header);
Param.Ignore(attributes);
Param.AssertNotNull(declaration, "declaration");
Param.Ignore(unsafeCode);
Param.Ignore(generated);
// Static destructors are always public.
if (this.Declaration.ContainsModifier(CsTokenType.Static))
{
this.Declaration.AccessModifierType = AccessModifierType.Public;
}
}
开发者ID:katerina-marchenkova,项目名称:my,代码行数:42,代码来源:Destructor.cs
示例9: GetCodeIssues
public IEnumerable<StyleCopCodeIssue> GetCodeIssues(
ISourceCode sourceCode,
Func<ElementTypeFilter, IEnumerable<IElement>> enumerate,
Violation violation,
CsElement csElement)
{
foreach (BinaryOperatorExpression operation in from x in enumerate(new ElementTypeFilter(LanguageElementType.BinaryOperatorExpression))
let binaryOperation = (BinaryOperatorExpression)x.ToLanguageElement()
where binaryOperation.RecoveredRange.Start.Line == violation.Line
&& (binaryOperation.LeftSide.ElementType == LanguageElementType.BinaryOperatorExpression
|| binaryOperation.RightSide.ElementType == LanguageElementType.BinaryOperatorExpression)
select binaryOperation)
{
var parentType = operators[operation.Name];
var leftChildType = operation.LeftSide.ElementType == LanguageElementType.BinaryOperatorExpression ? operators[operation.LeftSide.Name] : parentType;
var rightChildType = operation.RightSide.ElementType == LanguageElementType.BinaryOperatorExpression ? operators[operation.RightSide.Name] : parentType;
var isLeftModulo = operation.LeftSide.ElementType == LanguageElementType.BinaryOperatorExpression ? operation.LeftSide.Name == "%" : operation.Name == "%";
var isRightModulo = operation.RightSide.ElementType == LanguageElementType.BinaryOperatorExpression ? operation.RightSide.Name == "%" : operation.Name == "%";
if (rightChildType > parentType)
{
yield return new StyleCopCodeIssue(CodeIssueType.CodeSmell, operation.RightSide.RecoveredRange);
}
else if (leftChildType > parentType || (leftChildType == rightChildType && isLeftModulo != isRightModulo))
{
yield return new StyleCopCodeIssue(CodeIssueType.CodeSmell, operation.LeftSide.RecoveredRange);
}
}
}
开发者ID:kevinmiles,项目名称:dxcorecommunityplugins,代码行数:28,代码来源:SA1407_ArithmeticExpressionsMustDeclarePrecedence.cs
示例10: GetCodeIssues
public IEnumerable<StyleCopCodeIssue> GetCodeIssues(
ISourceCode sourceCode,
Func<ElementTypeFilter, IEnumerable<IElement>> enumerate,
Violation violation,
CsElement csElement)
{
bool predecessorFound = true;
CodeLocation issueLocation = null;
foreach (var token in this.getTokens(csElement).Flatten().Where(x => x.LineNumber == violation.Line))
{
if (!predecessorFound && !requiredFollowers.Contains(token.CsTokenType) && issueLocation != null)
{
yield return new StyleCopCodeIssue(CodeIssueType.CodeSmell, new SourceRange(issueLocation.StartPoint.LineNumber, issueLocation.StartPoint.IndexOnLine + 1, issueLocation.EndPoint.LineNumber, issueLocation.EndPoint.IndexOnLine + 2));
predecessorFound = false;
issueLocation = null;
}
else if (reportIssueFor(token, violation))
{
issueLocation = token.Location;
}
else if (requiredPredecessors.Contains(token.CsTokenType))
{
predecessorFound = true;
}
else
{
predecessorFound = false;
issueLocation = null;
}
}
}
开发者ID:kevinmiles,项目名称:dxcorecommunityplugins,代码行数:31,代码来源:SA1025_CodeMustNotContainMultipleWhitespaceInARow.cs
示例11: Accessor
/// <summary>
/// Initializes a new instance of the Accessor class.
/// </summary>
/// <param name="document">
/// The document that contains the element.
/// </param>
/// <param name="parent">
/// The parent of the element.
/// </param>
/// <param name="accessorType">
/// The type of the accessor.
/// </param>
/// <param name="header">
/// The Xml header for this element.
/// </param>
/// <param name="attributes">
/// The list of attributes attached to this element.
/// </param>
/// <param name="declaration">
/// The declaration code for this element.
/// </param>
/// <param name="unsafeCode">
/// Indicates whether the element resides within a block of unsafe code.
/// </param>
/// <param name="generated">
/// Indicates whether the code element was generated or written by hand.
/// </param>
internal Accessor(
CsDocument document,
CsElement parent,
AccessorType accessorType,
XmlHeader header,
ICollection<Attribute> attributes,
Declaration declaration,
bool unsafeCode,
bool generated)
: base(document, parent, ElementType.Accessor, declaration.Name + " accessor", header, attributes, declaration, unsafeCode, generated)
{
Param.AssertNotNull(document, "document");
Param.AssertNotNull(parent, "parent");
Param.Ignore(accessorType);
Param.Ignore(header);
Param.Ignore(attributes);
Param.AssertNotNull(declaration, "declaration");
Param.Ignore(unsafeCode);
Param.Ignore(generated);
this.accessorType = accessorType;
// Make sure the type and name match.
Debug.Assert(
(accessorType == AccessorType.Get && declaration.Name == "get") || (accessorType == AccessorType.Set && declaration.Name == "set")
|| (accessorType == AccessorType.Add && declaration.Name == "add") || (accessorType == AccessorType.Remove && declaration.Name == "remove"),
"The accessor type does not match its name.");
this.FillDetails(parent);
}
开发者ID:kopelli,项目名称:Visual-StyleCop,代码行数:57,代码来源:Accessor.cs
示例12: GetCodeIssues
public IEnumerable<StyleCopCodeIssue> GetCodeIssues(
ISourceCode sourceCode,
Func<ElementTypeFilter, IEnumerable<IElement>> enumerate,
Violation violation,
CsElement csElement)
{
int prefixLength = "The call to ".Length;
var memberName = violation.Message.Substring(prefixLength, violation.Message.IndexOf(" must") - prefixLength);
var thisFound = false;
foreach (var token in from token in csElement.ElementTokens
where token.LineNumber == violation.Line && token.CsTokenType != CsTokenType.WhiteSpace
select token)
{
if (token.CsTokenType == CsTokenType.This || (thisFound && token.Text == "."))
{
thisFound = true;
}
else
{
if (token.Text == memberName && !thisFound)
{
var sourceRange = new SourceRange(token.Location.StartPoint.LineNumber, token.Location.StartPoint.IndexOnLine + 1, token.Location.EndPoint.LineNumber, token.Location.EndPoint.IndexOnLine + 2);
yield return new StyleCopCodeIssue(CodeIssueType.CodeSmell, sourceRange);
}
thisFound = false;
}
}
}
开发者ID:kevinmiles,项目名称:dxcorecommunityplugins,代码行数:29,代码来源:SA1101_PrefixLocalCallsWithThis.cs
示例13: Method
internal Method(CsDocument document, CsElement parent, XmlHeader header, ICollection<Microsoft.StyleCop.CSharp.Attribute> attributes, Declaration declaration, TypeToken returnType, IList<Parameter> parameters, ICollection<TypeParameterConstraintClause> typeConstraints, bool unsafeCode, bool generated)
: base(document, parent, ElementType.Method, "method " + declaration.Name, header, attributes, declaration, unsafeCode, generated)
{
this.returnType = returnType;
this.parameters = parameters;
this.typeConstraints = typeConstraints;
if ((this.parameters.Count > 0) && base.Declaration.ContainsModifier(new CsTokenType[] { CsTokenType.Static }))
{
foreach (Parameter parameter in this.parameters)
{
if ((parameter.Modifiers & ParameterModifiers.This) != ParameterModifiers.None)
{
this.extensionMethod = true;
}
break;
}
}
base.QualifiedName = CodeParser.AddQualifications(this.parameters, base.QualifiedName);
if ((base.Declaration.Name.IndexOf(".", StringComparison.Ordinal) > -1) && !base.Declaration.Name.StartsWith("this.", StringComparison.Ordinal))
{
base.Declaration.AccessModifierType = AccessModifierType.Public;
}
if (typeConstraints != null)
{
foreach (TypeParameterConstraintClause clause in typeConstraints)
{
clause.ParentElement = this;
}
}
}
开发者ID:katerina-marchenkova,项目名称:my,代码行数:30,代码来源:Method.cs
示例14: GetCodeIssues
public IEnumerable<StyleCopCodeIssue> GetCodeIssues(
ISourceCode sourceCode,
Func<ElementTypeFilter, IEnumerable<IElement>> enumerate,
Violation violation,
CsElement csElement)
{
foreach (var operation in from x in enumerate(new ElementTypeFilter(LanguageElementType.LogicalOperation))
let logicalOperation = (LogicalOperation)x.ToLanguageElement()
where logicalOperation.RecoveredRange.Start.Line == violation.Line
&& (logicalOperation.LeftSide.ElementType == LanguageElementType.LogicalOperation
|| logicalOperation.RightSide.ElementType == LanguageElementType.LogicalOperation)
select logicalOperation)
{
var parentType = operators[operation.Name];
var leftChildType = operation.LeftSide.ElementType == LanguageElementType.LogicalOperation ? operators[operation.LeftSide.Name] : parentType;
var rightChildType = operation.RightSide.ElementType == LanguageElementType.LogicalOperation ? operators[operation.RightSide.Name] : parentType;
if (rightChildType > parentType)
{
yield return new StyleCopCodeIssue(CodeIssueType.CodeSmell, operation.RightSide.RecoveredRange);
}
else if (leftChildType > parentType)
{
yield return new StyleCopCodeIssue(CodeIssueType.CodeSmell, operation.LeftSide.RecoveredRange);
}
}
}
开发者ID:kevinmiles,项目名称:dxcorecommunityplugins,代码行数:26,代码来源:SA1408_ConditionalExpressionsMustDeclarePrecedence.cs
示例15: GetCodeIssues
public IEnumerable<StyleCopCodeIssue> GetCodeIssues(
ISourceCode sourceCode,
Func<ElementTypeFilter, IEnumerable<IElement>> enumerate,
Violation violation,
CsElement csElement)
{
foreach (var method in from x in enumerate(new ElementTypeFilter(LanguageElementType.Method))
let method = (DX.Method)x.ToLanguageElement()
where method.RecoveredRange.Start.Line == violation.Line
&& method.IsStatic && method.IsConstructor
&& method.FirstChild == null
select method)
{
yield return new StyleCopCodeIssue(CodeIssueType.CodeSmell, method.NameRange);
}
foreach (var statement in from x in enumerate(new ElementTypeFilter(deleteWhenEmpty))
let statement = x.ToLanguageElement()
where statement.RecoveredRange.Start.Line == violation.Line
&& (statement.ElementType == LanguageElementType.Try || statement.FirstChild == null)
select statement)
{
yield return new StyleCopCodeIssue(CodeIssueType.CodeSmell, statement.GetKeywordRange());
}
}
开发者ID:kevinmiles,项目名称:dxcorecommunityplugins,代码行数:25,代码来源:SA1409_RemoveUnnecessaryCode.cs
示例16: GetCodeIssues
public IEnumerable<StyleCopCodeIssue> GetCodeIssues(
ISourceCode sourceCode,
Func<ElementTypeFilter, IEnumerable<IElement>> enumerate,
Violation violation,
CsElement csElement)
{
SourcePoint? startPoint = null;
SourcePoint? endPoint = null;
foreach (var token in from token in csElement.ElementTokens
where token.LineNumber == violation.Line && token.CsTokenType != CsTokenType.WhiteSpace
select token)
{
if (token.CsTokenType == CsTokenType.Namespace)
{
startPoint = endPoint = new SourcePoint(token.Location.StartPoint.LineNumber, token.Location.StartPoint.IndexOnLine + 1);
}
else if (token.CsTokenType == CsTokenType.OpenCurlyBracket || token.CsTokenType == CsTokenType.EndOfLine)
{
if (startPoint != null)
{
var sourceRange = new SourceRange(startPoint.Value, endPoint.Value);
yield return new StyleCopCodeIssue(CodeIssueType.CodeSmell, sourceRange);
}
yield break;
}
else if (startPoint != null)
{
endPoint = new SourcePoint(token.Location.EndPoint.LineNumber, token.Location.EndPoint.IndexOnLine + 2);
}
}
}
开发者ID:kevinmiles,项目名称:dxcorecommunityplugins,代码行数:32,代码来源:SA1403_FileMayOnlyContainASingleNamespace.cs
示例17: Field
/// <summary>
/// Initializes a new instance of the Field class.
/// </summary>
/// <param name="document">The documenent that contains the element.</param>
/// <param name="parent">The parent of the element.</param>
/// <param name="header">The Xml header for this element.</param>
/// <param name="attributes">The list of attributes attached to this element.</param>
/// <param name="declaration">The declaration code for this element.</param>
/// <param name="fieldType">The type of the field.</param>
/// <param name="unsafeCode">Indicates whether the element resides within a block of unsafe code.</param>
/// <param name="generated">Indicates whether the code element was generated or written by hand.</param>
internal Field(
CsDocument document,
CsElement parent,
XmlHeader header,
ICollection<Attribute> attributes,
Declaration declaration,
TypeToken fieldType,
bool unsafeCode,
bool generated)
: base(document,
parent,
ElementType.Field,
"field " + declaration.Name,
header,
attributes,
declaration,
unsafeCode,
generated)
{
Param.AssertNotNull(document, "document");
Param.AssertNotNull(parent, "parent");
Param.Ignore(header);
Param.Ignore(attributes);
Param.AssertNotNull(declaration, "declaration");
Param.AssertNotNull(fieldType, "fieldType");
Param.Ignore(unsafeCode);
Param.Ignore(generated);
this.type = fieldType;
// Determine whether the item is const or readonly.
this.isConst = this.Declaration.ContainsModifier(CsTokenType.Const);
this.isReadOnly = this.Declaration.ContainsModifier(CsTokenType.Readonly);
}
开发者ID:katerina-marchenkova,项目名称:my,代码行数:45,代码来源:Field.cs
示例18: ContainsPartialMembers
/// <summary>
/// Determines whether the given element contains any partial members.
/// </summary>
/// <param name="element">
/// The element to check.
/// </param>
/// <returns>
/// Returns true if the element contains at least one partial member.
/// </returns>
public static bool ContainsPartialMembers(CsElement element)
{
Param.AssertNotNull(element, "element");
if (element.ElementType == ElementType.Class || element.ElementType == ElementType.Struct || element.ElementType == ElementType.Interface)
{
if (element.Declaration.ContainsModifier(CsTokenType.Partial))
{
return true;
}
}
if (element.ElementType == ElementType.Root || element.ElementType == ElementType.Namespace || element.ElementType == ElementType.Class
|| element.ElementType == ElementType.Struct)
{
foreach (CsElement child in element.ChildElements)
{
if (ContainsPartialMembers(child))
{
return true;
}
}
}
return false;
}
开发者ID:transformersprimeabcxyz,项目名称:_TO-FIRST-stylecop,代码行数:35,代码来源:Utils.cs
示例19: ClassBase
/// <summary>
/// Initializes a new instance of the ClassBase class.
/// </summary>
/// <param name="document">
/// The document that contains the element.
/// </param>
/// <param name="parent">
/// The parent of the element.
/// </param>
/// <param name="type">
/// The element type.
/// </param>
/// <param name="name">
/// The name of this element.
/// </param>
/// <param name="header">
/// The Xml header for this element.
/// </param>
/// <param name="attributes">
/// The list of attributes attached to this element.
/// </param>
/// <param name="declaration">
/// The declaration code for this element.
/// </param>
/// <param name="typeConstraints">
/// The list of type constraints on the element.
/// </param>
/// <param name="unsafeCode">
/// Indicates whether the element resides within a block of unsafe code.
/// </param>
/// <param name="generated">
/// Indicates whether the code element was generated or written by hand.
/// </param>
internal ClassBase(
CsDocument document,
CsElement parent,
ElementType type,
string name,
XmlHeader header,
ICollection<Attribute> attributes,
Declaration declaration,
ICollection<TypeParameterConstraintClause> typeConstraints,
bool unsafeCode,
bool generated)
: base(document, parent, type, name, header, attributes, declaration, unsafeCode, generated)
{
Param.Ignore(document, parent, type, name, header, attributes, declaration, typeConstraints, unsafeCode, generated);
this.typeConstraints = typeConstraints;
// Set the parent of the type constraint clauses.
if (typeConstraints != null)
{
Debug.Assert(typeConstraints.IsReadOnly, "The typeconstraints collection should be read-only.");
foreach (TypeParameterConstraintClause constraint in typeConstraints)
{
constraint.ParentElement = this;
}
}
}
开发者ID:transformersprimeabcxyz,项目名称:_TO-FIRST-stylecop,代码行数:61,代码来源:ClassBase.cs
示例20: GetCodeIssues
public IEnumerable<StyleCopCodeIssue> GetCodeIssues(
ISourceCode sourceCode,
Func<ElementTypeFilter, IEnumerable<IElement>> enumerate,
Violation violation,
CsElement csElement)
{
CodePoint startPoint = null;
CodePoint endPoint = null;
bool emptyLine = true;
foreach (var token in csElement.ElementTokens.Flatten().Where(x => x.LineNumber == violation.Line))
{
if (startPoint == null)
{
startPoint = token.Location.StartPoint;
endPoint = token.Location.EndPoint;
emptyLine = token.CsTokenType == CsTokenType.WhiteSpace || token.CsTokenType == CsTokenType.EndOfLine;
}
if (token.CsTokenType != CsTokenType.WhiteSpace && token.CsTokenType != CsTokenType.EndOfLine)
{
if (emptyLine)
{
startPoint = token.Location.StartPoint;
emptyLine = false;
}
endPoint = token.Location.EndPoint;
}
else if (token.CsTokenType == CsTokenType.EndOfLine)
{
yield return new StyleCopCodeIssue(CodeIssueType.CodeSmell, new SourceRange(startPoint.LineNumber, startPoint.IndexOnLine + 1, endPoint.LineNumber, endPoint.IndexOnLine + 2));
}
}
}
开发者ID:kevinmiles,项目名称:dxcorecommunityplugins,代码行数:34,代码来源:WholeLineIssueLocator.cs
注:本文中的CsElement类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论