using System;
namespace AnticipatingMinds.Genesis.CodeDOM{
/// <summary>
/// Base type for all type declarations.
/// </summary>
/// <remarks>A type-declaration is a class-declaration (17.1),
/// a struct-declaration (18.1), an interface-declaration (20.1),
/// an enum-declaration (21.1), or a delegate-declaration (22.1). 12
/// </remarks>
/// <remarks>ECMA 334 - p. 209, line 10.</remarks>
/// <remarks>ECMA 335 - p. 40, line 38 and bellow.</remarks>
[Serializable]
public abstract class CodeTypeDeclaration : CodeElement
{
/// <summary>
/// Represents type declaration modifiers.
/// </summary>
[Flags]
public enum TypeDeclarationModifiers
{
/// <summary>
/// Type hides an inherited class.
/// </summary>
New = 0x1,
/// <summary>
/// Abstract class.
/// </summary>
Abstract = 0x2,
/// <summary>
/// Type is sealed.
/// </summary>
Sealed = 0x4,
/// <summary>
/// Public type accessability.
/// </summary>
Public = 0x8,
/// <summary>
/// Family type accessability
/// </summary>
Family = 0x10,
/// <summary>
/// Private type accessability.
/// </summary>
Private = 0x20,
/// <summary>
/// Assembly accessability (Internal)
/// </summary>
Assembly = 0x40,
/// <summary>
/// Family & assembly accessabilty (internal protected in C#)
/// </summary>
FamilyAndAssembly = 0x80,
/// <summary>
/// Family or assembly accessability (not supported in C#)
/// </summary>
FamilyOrAssembly = 0x100,
/// <summary>
///
/// </summary>
Unsafe = 0x200
}
/// <summary>
/// Initializes new instance of <see cref="CodeTypeDeclaration"/> class.
/// </summary>
protected CodeTypeDeclaration()
{
}
/// <summary>
/// Reference to a namespace that declared this type.
/// </summary>
public CodeNamespace DeclaringNamespace
{
get
{
return Parent as CodeNamespace;
}
}
/// <summary>
/// Type declaration attributes.
/// </summary>
public CodeAttributeCollection Attributes
{
get
{
return attributes;
}
}
/// <summary>
/// Type declaration modifiers.
/// </summary>
public TypeDeclarationModifiers Modifiers
{
get
{
return modifiers;
}
set
{
modifiers = value;
}
}
/// <summary>
/// Declaring type if declartion is nested.
/// </summary>
public CodeTypeDeclaration DeclaringType
{
get
{
return Parent as CodeTypeDeclaration;
}
}
/// <summary>
/// Type name
/// </summary>
public string Name
{
get
{
return name;
}
set
{
name= (value == null ? string.Empty:value);
}
}
/// <summary>
/// Gets type full name.
/// </summary>
public string FullName
{
get
{
if(DeclaringType != null)
return DeclaringType.FullName.Length != 0 ? (DeclaringType.FullName + "." + Name) : Name;
if(DeclaringNamespace != null)
return DeclaringNamespace.FullName.Length != 0 ? (DeclaringNamespace.FullName + "." + Name) : Name;
return Name;
}
}
/// <summary>
/// Gets code metadata type information if available.
/// </summary>
public CodeTypeInfo TypeInfo
{
get
{
if(CompileUnit == null || CompileUnit.Assembly == null)
return null;
else
return CompileUnit.Assembly.TypeManager.FindType(FullName);
}
}
/// <summary>
/// Determines if the declared type is sublass of another type.
/// </summary>
/// <param name="baseTypeName"></param>
/// <returns></returns>
public bool IsSubclassOf(string baseTypeName)
{
return GetAssemblyTypeManager().IsTypeSubclassOf(FullName,baseTypeName);
}
private CodeAttributeCollection attributes = new CodeAttributeCollection();
private TypeDeclarationModifiers modifiers = 0;
private string name;
}
}
|