using System;
using System.Runtime.Serialization;
using System.Text.RegularExpressions;
using System.Collections;
using System.Collections.Specialized;
using System.ComponentModel;
using AnticipatingMinds.Genesis.CodeDOM;
namespace AnticipatingMinds.Genesis.KnowledgeManagement{
[Serializable]
public sealed class ClassApplicabilityScope : TypeApplicabilityScope, ICloneable,ISerializable
{
#region Instance constructors
public ClassApplicabilityScope():base()
{
}
public ClassApplicabilityScope(ClassApplicabilityScope classApplicabilityScope):base(classApplicabilityScope)
{
SubClassOf = classApplicabilityScope.SubClassOf;
foreach(string implementedInterface in classApplicabilityScope.implementedInterfaces)
implementedInterfaces.Add(implementedInterface);
}
#endregion Instance constructors
#region ISerializable Implementation
private ClassApplicabilityScope(SerializationInfo info, StreamingContext context) : base(info,context)
{
SubClassOf = info.GetString("SubClassOf");
implementedInterfaces = info.GetValue("ImplementedInterfaces",typeof(StringCollection)) as StringCollection;
}
public override void GetObjectData(
SerializationInfo info, StreamingContext context)
{
base.GetObjectData(info,context);
info.AddValue("SubClassOf",SubClassOf);
info.AddValue("ImplementedInterfaces",implementedInterfaces,typeof(StringCollection));
}
#endregion
#region Public instance properties
[Category("Behavior")]
[DefaultValue(null)]
[Description("A class type that the type declaration must inherit from (directly or indirectly). Value must be fully qualified, such as 'System.Windows.Forms.Form'")]
public string SubClassOf
{
get
{
return subClassOf;
}
set
{
subClassOf = value;
}
}
[Category("Behavior")]
[System.ComponentModel.Editor(typeof(StringCollectionEditor),typeof(System.Drawing.Design.UITypeEditor))]
[TypeConverter(typeof(StringCollectionTypeConverter))]
[DefaultValue("(any)")]
[Description("A list of zero or more interfaces that the type implements. Value must be fully qualified, such as 'System.IDisposable'")]
public StringCollection ImplementedInterfaces
{
get
{
return implementedInterfaces;
}
set
{
implementedInterfaces = value;
}
}
public override string Title
{
get
{
return "Class Declaration";
}
}
#endregion Public instance properties
#region Public instance methods
protected override bool DoesElementMatchScopeConditions(AnticipatingMinds.Genesis.CodeDOM.CodeElement codeElement)
{
if(!(codeElement is CodeClassDeclaration))
return false;
if(!base.DoesElementMatchScopeConditions(codeElement))
return false;
CodeClassDeclaration classDeclaration = codeElement as CodeClassDeclaration;
if(SubClassOf != null && SubClassOf.Length != 0)
{
if(codeElement.GetAssemblyTypeManager()!= null && !codeElement.GetAssemblyTypeManager().IsTypeSubclassOf(classDeclaration.FullName,SubClassOf))
return false;
}
if(ImplementedInterfaces != null && ImplementedInterfaces.Count != 0)
{
StringCollection typeInterface = new StringCollection();
foreach(CodeTypeReference baseType in classDeclaration.BaseTypes)
typeInterface.Add(baseType.TypeInfo != null ? baseType.TypeInfo.FullName : baseType.TypeName );
foreach(string requestedInterface in ImplementedInterfaces)
if(!typeInterface.Contains(requestedInterface))
return false;
}
return true;
}
#region ICloneable Members
public override object Clone()
{
return new ClassApplicabilityScope(this);
}
#endregion
#endregion Public instance methods
#region Private instance fields
private string subClassOf = null;
private StringCollection implementedInterfaces = new StringCollection();
#endregion Private instance fields
}
}
|