using System;
using System.Text.RegularExpressions;
using System.ComponentModel;
using System.Runtime.Serialization;
using AnticipatingMinds.Genesis.CodeDOM;
namespace AnticipatingMinds.Genesis.KnowledgeManagement{
/// <summary>
/// Summary description for MethodParameterApplicabilityScope.
/// </summary>
[Serializable]
public class MethodParameterApplicabilityScope : ApplicabilityScope,ISerializable, ICloneable
{
#region Instance constructors
public MethodParameterApplicabilityScope():base()
{
}
public MethodParameterApplicabilityScope(MethodParameterApplicabilityScope methodParameterApplicabilityScope) : base(methodParameterApplicabilityScope)
{
if(methodParameterApplicabilityScope.MethodParameterType != null)
MethodParameterType = ((ICloneable)methodParameterApplicabilityScope.MethodParameterType).Clone() as TypeReferenceApplicabilityScope;
if(methodParameterApplicabilityScope.MethodParameterName != null)
MethodParameterName = new Regex(methodParameterApplicabilityScope.MethodParameterName.ToString());
}
#endregion Instance constructors
#region ISerializable Implementation
private MethodParameterApplicabilityScope(SerializationInfo info, StreamingContext context) : base(info,context)
{
if(info.GetString("MethodParameterName").Length != 0)
MethodParameterName = new Regex(info.GetString("MethodParameterName"));
MethodParameterType = info.GetValue("MethodParameterType",typeof(TypeReferenceApplicabilityScope)) as TypeReferenceApplicabilityScope;
}
public override void GetObjectData(SerializationInfo info, StreamingContext context)
{
base.GetObjectData(info,context);
info.AddValue("MethodParameterType",MethodParameterType,typeof(TypeReferenceApplicabilityScope));
if(MethodParameterName != null)
info.AddValue("MethodParameterName",MethodParameterName.ToString());
else
info.AddValue("MethodParameterName",string.Empty);
}
#endregion
#region ICloneable Members
public object Clone()
{
return new MethodParameterApplicabilityScope(this);
}
#endregion
#region Public instance properties
[Category("Behavior")]
[System.ComponentModel.Editor(typeof(TypeReferenceScopeEditor),typeof(System.Drawing.Design.UITypeEditor))]
[TypeConverter(typeof(ApplicabilityScopeTypeConverter))]
[DefaultValue(null)]
[Description("The data type of the method parameter being declared.")]
public TypeReferenceApplicabilityScope MethodParameterType
{
get
{
return methodParameterType;
}
set
{
methodParameterType = value;
}
}
public override string Title
{
get
{
return "Method Parameter Declaration";
}
}
[Category("Behavior")]
[DefaultValue(null)]
[TypeConverter(typeof(RegExpTypeConverter))]
[Description("Regular expression used to define the criteria for the name to be used in scope definition.")]
public virtual Regex MethodParameterName
{
get
{
return methodParameterName;
}
set
{
methodParameterName = value;
}
}
#endregion Public instance properties
#region Protected instance methods
protected override bool DoesElementMatchScopeConditions(CodeElement codeElement)
{
if(!(codeElement is CodeMethodParameter))
return false;
CodeMethodParameter methodParameter = codeElement as CodeMethodParameter;
if(MethodParameterType != null)
if(!MethodParameterType.IsElementInScope(methodParameter.Type))
return false;
if(MethodParameterName != null)
{
if(!MethodParameterName.Match(methodParameter.Name).Success)
return false;
}
return true;
}
#endregion Protected instance methods
#region Private instance fields
TypeReferenceApplicabilityScope methodParameterType = null;
private Regex methodParameterName;
#endregion Private instance fields
}
}
|