using System;
using System.Collections;
using System.Diagnostics;
namespace AnticipatingMinds.Genesis.CodeDOM{
/// <summary>
/// Represents any code element that can exist in a source code file.
/// </summary>
/// <remarks>This class helps to abstract all code elements that have a physical representation in
/// source code file. For example namespace declaration have a clear presentation in source file when assembly
/// has only logical meaning of one or more modules that export types and does not have source
/// code representation.</remarks>
[Serializable]
public abstract class CodeElement : object, ICloneable
{
#region Public instance properties
/// <summary>
/// Gets and sets postion information for code element.
/// </summary>
public CodeElementPosition SourcePosition
{
get
{
return position;
}
set
{
position = value;
if(position == null)
position = new CodeElementPosition();
}
}
/// <summary>
/// Gets or sets documentation comment if one is associated with an element.
/// </summary>
public CodeComment DocumentationComment
{
get
{
return documentationComment;
}
set
{
documentationComment = value;
}
}
/// <summary>
/// Gets or sets a comment associated with the code element.
/// </summary>
public CodeComment Comment
{
get
{
return comment;
}
set
{
comment = value;
}
}
/// <summary>
/// Gets or sets CodeAssemblyFile that contains code element.
/// </summary>
public CodeAssemblyFile CompileUnit
{
get
{
return codeContainer;
}
set
{
codeContainer = value;
}
}
public CodeLanguage Language
{
get
{
if(CompileUnit != null)
return CompileUnit.Language;
return CodeLanguage.Unknown;
}
}
/// <summary>
/// Gets assembly type manager if element is part of assembly and type manager is available
/// </summary>
/// <returns></returns>
public CodeAssemblyTypeManager GetAssemblyTypeManager()
{
if(CompileUnit != null && CompileUnit.Assembly != null)
return CompileUnit.Assembly.TypeManager;
else
return null;
}
/// <summary>
/// Gets a dictinary object to store any data associated with code element.
/// </summary>
public IDictionary ApplicationData
{
get
{
if(applicationData == null)
{
lock(this)
{
if(applicationData == null)
applicationData = new Hashtable() as IDictionary;
}
}
return applicationData;
}
}
/// <summary>
/// Gets or sets code element parent element.
/// </summary>
public CodeElement Parent
{
get
{
return parent;
}
set
{
parent = value;
}
}
#endregion Public instance properties
#region Public instance methods
/// <summary>
/// Clones code element.
/// </summary>
/// <returns>Code element cloned by <see cref="Object.MemberwiseClone"/> method call.</returns>
#region ICloneable Members
public virtual object Clone()
{
return MemberwiseClone();;
}
#endregion
#endregion Public instance methods
#region Private instance fields
private CodeAssemblyFile codeContainer;
private CodeElementPosition position = new CodeElementPosition();
private CodeCommentCollection comments = new CodeCommentCollection();
private CodeComment documentationComment;
private CodeElement parent;
private IDictionary applicationData = null;
private CodeComment comment;
#endregion Private instance fields
}
}
|