this rule does not work . i got this code from forum. please see the code

i have included both the rule and target file.

rule does not finde that i do not mark serializable for enum EntityType , please tell me what is the reason for that.

rule

public class EnumerationsAreMarkedSerializable : BaseRule
{
/// <summary>
/// <para>
/// Initializes a new instance of the <see cref="EnumerationsAreMarkedSerializable"/> class.
/// </para>
/// </summary>
public EnumerationsAreMarkedSerializable() : base("EnumerationsAreMarkedSerializable")
{
}

/// <summary>
/// <para>
/// This member overrides <see cref="BaseIntrospectionRule.TargetVisibility"/>.
/// </para>
/// </summary>
/// <value>
/// This property is a combination of <see cref="TargetVisibilities.ExternallyVisible"/> and <see cref="TargetVisibilities.Overridable"/>.
/// </value>
public override TargetVisibilities TargetVisibility
{
get { return TargetVisibilities.ExternallyVisible | TargetVisibilities.Overridable; }
}

/// <summary>
/// <para>
/// This member overrides <see cref="BaseRule.Check(EnumNode)"/>.
/// </para>
/// </summary>
/// <param name="e">
/// The <see cref="EnumNode"/> to check.
/// </param>
/// <returns>
/// A <see cref="ProblemCollection"/> containing the problems associated with <paramref name="e"/>.
/// </returns>
public override ProblemCollection Check(EnumNode e)
{
if (e == null)
return null;

if (RuleUtilities.IsSerializable(e))
return null;

Problems.Add(new Problem(GetResolution(e.Name.Name)));

return Problems;
}
}

my target cs file is as belew

public class Class
{

int myno = 0;
public int my;

const int VIN_MU = 0;

public enum EntityType
{

Customer = 1,
FundingSource = 2,
Inventory = 3,
Lease = 4,
RefurbishmentCentre = 5,
Transaction = 6,
Vendor = 7

}

}

here i did not specify about sirialization attribute.

but the code does not detect it.

pleasee tell me what is the reason.

[2550 byte] By [Vinothkumar] at [2007-12-20]
# 1

This is most likely because RuleUtilities.IsSerializable has been changed to check the underlying type for enums. As the underlying type for a enum is always a primitive (ie Int16, Int32, Int64, etc), IsSerializable will always return true and therefore the problem will never be reported.

I actually wrote orginally wrote the rule you've pasted, and this rule was merely written to make sure that developers on my team always explicitly marked enums with Serializable - even though enums are always seralizable.

Regards

David

DavidM.Kean-MSFT at 2007-9-10 > top of Msdn Tech,Visual Studio Team System,Visual Studio Code Analysis and Code Metrics...

Visual Studio Team System

Site Classified