using System;
using System.ComponentModel;
using System.Runtime.Serialization;
using AnticipatingMinds.Genesis.CodeDOM;
namespace AnticipatingMinds.Genesis.KnowledgeManagement{
/// <summary>
/// Summary description for MethodApplicabilityScope.
/// </summary>
[Serializable]
public class MethodApplicabilityScope : TypeMemberApplicabilityScope, ISerializable,ICloneable
{
#region Instance constructors
public MethodApplicabilityScope():base()
{
}
public MethodApplicabilityScope(MethodApplicabilityScope methodApplicabilityScope) : base(methodApplicabilityScope)
{
if(methodApplicabilityScope.ReturnType != null)
ReturnType = ((ICloneable)methodApplicabilityScope.ReturnType).Clone() as TypeReferenceApplicabilityScope;
if(methodApplicabilityScope.MethodParameters != null)
{
MethodParameters = new MethodParameterApplicabilityScopeCollection();
foreach(MethodParameterApplicabilityScope parameter in methodApplicabilityScope.MethodParameters)
MethodParameters.Add(parameter.Clone() as MethodParameterApplicabilityScope);
}
else
{
MethodParameters = null;
}
}
#endregion Instance constructors
#region ICloneable Members
public override object Clone()
{
return new MethodApplicabilityScope(this);
}
#endregion
#region ISerializable Implementation
private MethodApplicabilityScope(SerializationInfo info, StreamingContext context) : base(info,context)
{
ReturnType = info.GetValue("ReturnType",typeof(TypeReferenceApplicabilityScope)) as TypeReferenceApplicabilityScope;
try
{
MethodParameters = info.GetValue("MethodParameters",typeof(MethodParameterApplicabilityScopeCollection)) as MethodParameterApplicabilityScopeCollection;
}
catch(SerializationException)
{
//Do nothing - old version of the class
}
}
public override void GetObjectData(SerializationInfo info, StreamingContext context)
{
base.GetObjectData(info,context);
info.AddValue("ReturnType",ReturnType,typeof(TypeReferenceApplicabilityScope));
info.AddValue("MethodParameters",MethodParameters,typeof(MethodParameterApplicabilityScopeCollection));
}
#endregion
#region Public instance properties
[Category("Behavior")]
[System.ComponentModel.Editor(typeof(TypeReferenceScopeEditor),typeof(System.Drawing.Design.UITypeEditor))]
[TypeConverter(typeof(ApplicabilityScopeTypeConverter))]
[DefaultValue(null)]
[Description("The return data type of the method being declared.")]
public TypeReferenceApplicabilityScope ReturnType
{
get
{
return returnType;
}
set
{
returnType = value;
}
}
[Category("Behavior")]
[DefaultValue(null)]
[Description("The return data type of the method being declared.")]
[System.ComponentModel.Editor(typeof(MethodParameterApplicabilityScopeCollectionEditor),typeof(System.Drawing.Design.UITypeEditor))]
[TypeConverter(typeof(MethodParameterApplicabilityScopeCollectionConverter))]
public MethodParameterApplicabilityScopeCollection MethodParameters
{
get
{
return methodParameters;
}
set
{
methodParameters = value;
}
}
public override string Title
{
get
{
return "Method Declaration";
}
}
#endregion Public instance properties
#region Protected instance methods
protected override bool DoesElementMatchScopeConditions(CodeElement codeElement)
{
if(!(codeElement is CodeTypeMethodDeclaration))
return false;
CodeTypeMethodDeclaration methodDeclaration = codeElement as CodeTypeMethodDeclaration;
if(ReturnType != null)
if(!ReturnType.IsElementInScope(methodDeclaration.ReturnType))
return false;
if(MethodParameters != null)
{
//No one has paramethers?
if(methodDeclaration.Parameters.Count == 0 && MethodParameters.Count == 0)
return base.DoesElementMatchScopeConditions(codeElement);
if(methodDeclaration.Parameters.Count != MethodParameters.Count)
return false;
for(int parameterIndex = 0; parameterIndex < methodDeclaration.Parameters.Count; parameterIndex++)
if(!MethodParameters[parameterIndex].IsElementInScope(methodDeclaration.Parameters[parameterIndex]))
return false;
}
return base.DoesElementMatchScopeConditions(codeElement);
}
#endregion Protected instance methods
#region Private instance fields
TypeReferenceApplicabilityScope returnType = null;
MethodParameterApplicabilityScopeCollection methodParameters = null;
#endregion Private instance fields
}
}
|