/// <summary> /// Initializes a new instance of the Parameter class. /// </summary> /// <param name="type"> /// The type of the parameter. /// </param> /// <param name="name"> /// The name of the parameter. /// </param> /// <param name="parent"> /// The parent of the parameter. /// </param> /// <param name="modifiers"> /// Modifiers applied to this parameter. /// </param> /// <param name="defaultArgument"> /// The optional default argument for the parameter. /// </param> /// <param name="location"> /// The location of the parameter in the code. /// </param> /// <param name="tokens"> /// The tokens that form the parameter. /// </param> /// <param name="generated"> /// Indicates whether the parameter is located within a block of generated code. /// </param> internal Parameter( TypeToken type, string name, Reference <ICodePart> parent, ParameterModifiers modifiers, Expression defaultArgument, CodeLocation location, CsTokenList tokens, bool generated) { Param.Ignore(type); Param.AssertValidString(name, "name"); Param.AssertNotNull(parent, "parent"); Param.Ignore(modifiers); Param.Ignore(defaultArgument); Param.AssertNotNull(location, "location"); Param.Ignore(tokens); Param.Ignore(generated); this.type = type; this.name = CodeLexer.DecodeEscapedText(name, true); this.parent = parent; this.modifiers = modifiers; this.defaultArgument = defaultArgument; this.location = location; this.tokens = tokens; this.generated = generated; }
/// <summary> /// Initializes a new instance of the Declaration class. /// </summary> /// <param name="tokens"> /// The array of tokens that make up the declaration. /// </param> /// <param name="name"> /// The name of the element. /// </param> /// <param name="elementType"> /// The type of the element. /// </param> /// <param name="accessModifierType"> /// The access type of the element. /// </param> /// <param name="modifiers"> /// The list of modifier keywords in the declaration. /// </param> internal Declaration(CsTokenList tokens, string name, ElementType elementType, AccessModifierType accessModifierType, Dictionary <CsTokenType, CsToken> modifiers) { Param.AssertNotNull(tokens, "tokens"); Param.AssertNotNull(name, "name"); Param.Ignore(elementType); Param.Ignore(accessModifierType); Param.AssertNotNull(modifiers, "modifiers"); this.tokens = tokens; this.name = CodeLexer.DecodeEscapedText(name, true); this.elementType = elementType; this.accessModifierType = accessModifierType; this.modifiers = modifiers; this.tokens.Trim(); }
/// <summary> /// Initializes a new instance of the Variable class. /// </summary> /// <param name="type"> /// The type of the variable. /// </param> /// <param name="name"> /// The name of the variable. /// </param> /// <param name="modifiers"> /// Modifiers applied to this variable. /// </param> /// <param name="location"> /// The location of the variable. /// </param> /// <param name="parent"> /// The parent code part. /// </param> /// <param name="generated"> /// Indicates whether the variable is located within a block of generated code. /// </param> internal Variable(TypeToken type, string name, VariableModifiers modifiers, CodeLocation location, Reference <ICodePart> parent, bool generated) { Param.Ignore(type); Param.AssertValidString(name, "name"); Param.Ignore(modifiers); Param.AssertNotNull(location, "location"); Param.AssertNotNull(parent, "parent"); Param.Ignore(generated); this.type = type; this.name = CodeLexer.DecodeEscapedText(name, true); this.modifiers = modifiers; this.location = location; this.parent = parent; this.generated = generated; }
/// <summary> /// Creates a text string based on the child tokens in the attribute. /// </summary> private void CreateTextString() { StringBuilder tokenText = new StringBuilder(); foreach (CsToken token in this.Tokens) { // Strip out comments and preprocessor directives. if (token.CsTokenType != CsTokenType.SingleLineComment && token.CsTokenType != CsTokenType.MultiLineComment && token.CsTokenType != CsTokenType.PreprocessorDirective) { string decodedText = CodeLexer.DecodeEscapedText(token.Text, true); tokenText.Append(decodedText); } } this.text = tokenText.ToString(); }
/// <summary> /// Initializes a new instance of the CsElement 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="unsafeCode"> /// Indicates whether the element is unsafe. /// </param> /// <param name="generated"> /// Indicates whether the element was generated or written by hand. /// </param> internal CsElement( CsDocument document, CsElement parent, ElementType type, string name, XmlHeader header, ICollection <Attribute> attributes, Declaration declaration, bool unsafeCode, bool generated) : base(CodePartType.Element) { Param.AssertNotNull(document, "document"); Param.Ignore(parent); Param.Ignore(type); Param.AssertNotNull(name, "name"); Param.Ignore(header); Param.Ignore(attributes); Param.Ignore(declaration); Param.Ignore(unsafeCode); Param.Ignore(generated); this.document = document; if (this.document == null) { throw new ArgumentException(Strings.DocumentMustBeCsDocument, "document"); } if (parent != null && parent.Document != document) { throw new ArgumentException(Strings.ElementMustBeInParentsDocument, "parent"); } this.type = type; this.name = CodeLexer.DecodeEscapedText(name, true); this.header = header; this.attributes = attributes; this.declaration = declaration; this.unsafeCode = unsafeCode; this.generated = generated; if (!unsafeCode && this.declaration.ContainsModifier(CsTokenType.Unsafe)) { this.unsafeCode = true; } // Fill in the element reference in the header object. if (this.header != null) { Debug.Assert(this.header.Element == null, "The header element should not be empty."); this.header.Element = this; } // Fill in the element reference in the attributes list items. if (this.attributes != null) { Debug.Assert(this.attributes.IsReadOnly, "The attributes collection should be read-only."); foreach (Attribute attribute in this.attributes) { Debug.Assert(attribute.Element == null, "The attribute element should not be empty"); attribute.Element = this; } } // Set the fully qualified base name if (parent != null) { this.fullyQualifiedBase = parent.FullyQualifiedName; this.MergeAccess(parent.ActualAccess); } else { if (this.declaration != null) { this.actualAccess = this.declaration.AccessModifierType; } else { this.actualAccess = AccessModifierType.Public; } } // Set the fully qualified name this.fullyQualifiedName = this.fullyQualifiedBase; if (this.declaration != null && this.declaration.Name != null && this.declaration.Name.Length > 0) { if (this.fullyQualifiedBase != null && this.fullyQualifiedBase.Length > 0) { this.fullyQualifiedName += "."; } int index = this.declaration.Name.LastIndexOf("\\", StringComparison.Ordinal); if (index != -1) { this.fullyQualifiedName += this.declaration.Name.Substring(index + 1, this.declaration.Name.Length - index - 1); } else { this.fullyQualifiedName += this.declaration.Name; } index = this.fullyQualifiedName.IndexOf(".cs.", StringComparison.OrdinalIgnoreCase); if (-1 == index) { this.fullNamespaceName = this.fullyQualifiedName; } else { this.fullNamespaceName = this.fullyQualifiedName.Substring(index + 4, this.fullyQualifiedName.Length - index - 4); } } // There is only one type of element which is allowed to have a token // list consisting of nothing other than whitespace, newlines, etc., // which is the document root. This happens if you have a document which // contains nothing other than whitespace. Due to this we do not want to // trim down the token list for the root element, but we do want to for // all other types of elements. if (type == ElementType.Root) { this.TrimTokens = false; } }
/// <summary> /// Gets the contents of the expression as a string. /// </summary> /// <returns>Returns the string.</returns> public override string ToString() { return(CodeLexer.DecodeEscapedText(this.tokenNode.Value.Text, false)); }