<Type Name="DeserializeOptionalFieldRule" FullName="Gendarme.Rules.Serialization.DeserializeOptionalFieldRule">
  <TypeSignature Language="C#" Value="public class DeserializeOptionalFieldRule : Gendarme.Framework.Rule, Gendarme.Framework.ITypeRule" />
  <TypeSignature Language="ILAsm" Value=".class public auto ansi beforefieldinit DeserializeOptionalFieldRule extends Gendarme.Framework.Rule implements class Gendarme.Framework.IRule, class Gendarme.Framework.ITypeRule" />
  <AssemblyInfo>
    <AssemblyName>Gendarme.Rules.Serialization</AssemblyName>
    <AssemblyVersion>2.11.0.0</AssemblyVersion>
  </AssemblyInfo>
  <Base>
    <BaseTypeName>Gendarme.Framework.Rule</BaseTypeName>
  </Base>
  <Interfaces>
    <Interface>
      <InterfaceName>Gendarme.Framework.ITypeRule</InterfaceName>
    </Interface>
  </Interfaces>
  <Attributes>
    <Attribute>
      <AttributeName>Gendarme.Framework.FxCopCompatibility("Microsoft.Usage", "CA2239:ProvideDeserializationMethodsForOptionalFields")</AttributeName>
    </Attribute>
    <Attribute>
      <AttributeName>Gendarme.Framework.Problem("Some fields are marked with [OptionalField] but the type does not provide special deserialization routines.")</AttributeName>
    </Attribute>
    <Attribute>
      <AttributeName>Gendarme.Framework.Solution("Add a deserialization routine, marked with [OnDeserialized], and re-compute the correct value for the optional fields.")</AttributeName>
    </Attribute>
  </Attributes>
  <Docs>
    <summary>
            This rule will fire if a type has fields marked with <c>[OptionalField]</c>, but does
            not have methods decorated with the <c>[OnDeserialized]</c> or <c>[OnDeserializing]</c>
            attributes. This is a problem because the binary deserializer does not actually construct
            objects (it uses <c>System.Runtime.Serialization.FormatterServices.GetUninitializedObject</c>
            instead). So, if binary deserialization is used the optional field(s) will be zeroed instead
            of properly initialized.
            This rule only applies to assemblies compiled with the .NET framework version 2.0
            (or later).
            </summary>
    <remarks>This rule is available since Gendarme 2.0</remarks>
    <example>
            Bad example:
            <code>
            [Serializable]
            public class ClassWithOptionalField {
            	[OptionalField]
            	private int optional;
            }
            </code></example>
    <example>
            Good example:
            <code>
            [Serializable]
            public class ClassWithOptionalField {
            	// Normally the (compiler generated) default constructor will
            	// initialize this. The default constructor will be called by the
            	// XML and Soap deserializers, but not the binary serializer.
            	[OptionalField]
            	private int optional = 1;
            	// This will be called immediately after the object is
            	// deserialized.
            	[OnDeserializing]
            	private void OnDeserializing (StreamingContext context)
            	{
            		optional = 1;
            	}
            }
            </code></example>
  </Docs>
  <Members>
    <Member MemberName=".ctor">
      <MemberSignature Language="C#" Value="public DeserializeOptionalFieldRule ();" />
      <MemberSignature Language="ILAsm" Value=".method public hidebysig specialname rtspecialname instance void .ctor() cil managed" />
      <MemberType>Constructor</MemberType>
      <AssemblyInfo>
        <AssemblyVersion>2.11.0.0</AssemblyVersion>
      </AssemblyInfo>
      <Parameters />
      <Docs>
        <summary>To be added.</summary>
        <remarks>To be added.</remarks>
      </Docs>
    </Member>
    <Member MemberName="CheckType">
      <MemberSignature Language="C#" Value="public Gendarme.Framework.RuleResult CheckType (Mono.Cecil.TypeDefinition type);" />
      <MemberSignature Language="ILAsm" Value=".method public hidebysig newslot virtual instance valuetype Gendarme.Framework.RuleResult CheckType(class Mono.Cecil.TypeDefinition type) cil managed" />
      <MemberType>Method</MemberType>
      <AssemblyInfo>
        <AssemblyVersion>2.11.0.0</AssemblyVersion>
      </AssemblyInfo>
      <ReturnValue>
        <ReturnType>Gendarme.Framework.RuleResult</ReturnType>
      </ReturnValue>
      <Parameters>
        <Parameter Name="type" Type="Mono.Cecil.TypeDefinition" />
      </Parameters>
      <Docs>
        <param name="type">To be added.</param>
        <summary>To be added.</summary>
        <returns>To be added.</returns>
        <remarks>To be added.</remarks>
      </Docs>
    </Member>
    <Member MemberName="Initialize">
      <MemberSignature Language="C#" Value="public override void Initialize (Gendarme.Framework.IRunner runner);" />
      <MemberSignature Language="ILAsm" Value=".method public hidebysig virtual instance void Initialize(class Gendarme.Framework.IRunner runner) cil managed" />
      <MemberType>Method</MemberType>
      <AssemblyInfo>
        <AssemblyVersion>2.11.0.0</AssemblyVersion>
      </AssemblyInfo>
      <ReturnValue>
        <ReturnType>System.Void</ReturnType>
      </ReturnValue>
      <Parameters>
        <Parameter Name="runner" Type="Gendarme.Framework.IRunner" />
      </Parameters>
      <Docs>
        <param name="runner">To be added.</param>
        <summary>To be added.</summary>
        <remarks>To be added.</remarks>
      </Docs>
    </Member>
  </Members>
</Type>
