本文整理汇总了C#中CsDocument类的典型用法代码示例。如果您正苦于以下问题:C# CsDocument类的具体用法?C# CsDocument怎么用?C# CsDocument使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
CsDocument类属于命名空间,在下文中一共展示了CsDocument类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetElementByQualifiedName
/// <summary>
/// Gets element by name.
/// </summary>
private static CsElement GetElementByQualifiedName(CsDocument document, string qualifiedName)
{
return GetElementByName(
document.RootElement.ChildElements,
qualifiedName,
true);
}
示例2: GetElementByName
/// <summary>
/// Gets element by name.
/// </summary>
private static CsElement GetElementByName(CsDocument document, string name)
{
return GetElementByName(
document.RootElement.ChildElements,
name,
false);
}
示例3: AnalyzePlainText
/// <summary>
/// Analyzes source code as plain text.
/// </summary>
private void AnalyzePlainText(CsDocument document, CustomRulesSettings settings)
{
string source;
using (TextReader reader = document.SourceCode.Read())
{
source = reader.ReadToEnd();
}
List<string> lines = new List<string>(
source.Split(
new[] { "\r\n", "\r", "\n" },
StringSplitOptions.None));
for (int i = 0; i < lines.Count; i++)
{
int currentLineNumber = i + 1;
string currentLine = lines[i];
string previousLine = i > 0 ? lines[i - 1] : null;
CheckLineEnding(document, currentLine, currentLineNumber);
CheckIndentation(document, currentLine, previousLine, currentLineNumber, settings);
CheckLineLength(document, currentLine, currentLineNumber, settings);
}
CheckLastLine(document, source, lines.Count, settings);
}
示例4: 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;
}
}
}
示例5: Field
internal Field(CsDocument document, CsElement parent, XmlHeader header, ICollection<Microsoft.StyleCop.CSharp.Attribute> attributes, Declaration declaration, TypeToken fieldType, bool unsafeCode, bool generated)
: base(document, parent, ElementType.Field, "field " + declaration.Name, header, attributes, declaration, unsafeCode, generated)
{
this.type = fieldType;
this.isConst = base.Declaration.ContainsModifier(new CsTokenType[] { CsTokenType.Const });
this.isReadOnly = base.Declaration.ContainsModifier(new CsTokenType[] { CsTokenType.Readonly });
}
示例6: EnumItem
/// <summary>
/// Initializes a new instance of the EnumItem 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="initialization">The initialization expression, if there is one.</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 EnumItem(
CsDocument document,
Enum parent,
XmlHeader header,
ICollection<Attribute> attributes,
Declaration declaration,
Expression initialization,
bool unsafeCode,
bool generated)
: base(document,
parent,
ElementType.EnumItem,
"enum item " + declaration.Name,
header,
attributes,
declaration,
unsafeCode,
generated)
{
Param.Ignore(document, parent, header, attributes, declaration, initialization, unsafeCode, generated);
this.initialization = initialization;
if (this.initialization != null)
{
this.AddExpression(this.initialization);
}
}
示例7: GetElementByLine
/// <summary>
/// Gets first code element at specified line number.
/// </summary>
/// <remarks>
/// Returns object because it is ICodeElement for 4.4 and CodeElement for 4.3.
/// </remarks>
public static object GetElementByLine(CsDocument document, int lineNumber)
{
object[] args = new object[] { lineNumber, null };
document.WalkDocument(FindByLineElementVisitor, null, args);
return args[1];
}
示例8: UsingDirective
/// <summary>
/// Initializes a new instance of the UsingDirective class.
/// </summary>
/// <param name="document">The document that contains the element.</param>
/// <param name="parent">The parent of the element.</param>
/// <param name="declaration">The declaration code for this element.</param>
/// <param name="generated">Indicates whether the code element was generated or written by hand.</param>
/// <param name="namespace">The namespace being used.</param>
/// <param name="alias">Optional alias for the namespace, if any.</param>
internal UsingDirective(
CsDocument document,
CsElement parent,
Declaration declaration,
bool generated,
string @namespace,
string alias)
: base(document,
parent,
ElementType.UsingDirective,
"using " + declaration.Name,
null,
null,
declaration,
false,
generated)
{
Param.Ignore(document);
Param.Ignore(parent);
Param.Ignore(declaration);
Param.Ignore(generated);
Param.AssertValidString(@namespace, "namespace");
Param.Ignore(alias);
this.namespaceType = @namespace;
if (alias != null)
{
this.alias = alias;
}
}
示例9: CheckLineLength
private void CheckLineLength(CsDocument csharpDocument)
{
var lengthProperty = GetSetting(csharpDocument.Settings, LineLengthProperty) as IntProperty;
if (lengthProperty == null)
{
return;
}
using (var reader = csharpDocument.SourceCode.Read())
{
string line;
var lineNumber = 0;
while ((line = reader.ReadLine()) != null)
{
lineNumber++;
if (line.Length > lengthProperty.Value)
{
AddViolation(
csharpDocument.RootElement,
lineNumber,
RuleName,
lengthProperty.Value);
}
}
}
}
示例10: 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;
}
}
示例11: 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);
}
示例12: 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;
}
}
}
示例13: DocumentRoot
/// <summary>
/// Initializes a new instance of the DocumentRoot class.
/// </summary>
/// <param name="document">
/// The document that this element belongs to.
/// </param>
/// <param name="declaration">
/// The declaration class for this element.
/// </param>
/// <param name="generated">
/// Indicates whether the element contains generated code.
/// </param>
internal DocumentRoot(CsDocument document, Declaration declaration, bool generated)
: base(document, null, ElementType.Root, Strings.DocumentRoot, null, null, declaration, false, generated)
{
Param.AssertNotNull(document, "document");
Param.AssertNotNull(declaration, "declaration");
Param.Ignore(generated);
}
示例14: 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;
}
}
示例15: CodeUnitProxy
/// <summary>
/// Initializes a new instance of the CodeUnitProxy class.
/// </summary>
/// <param name="document">The parent document.</param>
public CodeUnitProxy(CsDocument document)
{
Param.Ignore(document);
this.document = document;
this.children = new CodeUnitCollection(this);
}