logic issue while setting condition
<p>I got a comment like this</p>

<p>This check (<code>if (rp != null)</code>) should not be here.  The variable <code>irp.ResourcePolicy</code> should be set to <code>null</code> when rp is <code>null</code> because the Resource Policy is unknown.  Otherwise the previous value will be used and the previous value might be incorrect.</p>

<pre><code>// Search for the specified resource policy
                                ResourcePolicy rp = null;
                                try
                                {
                                    int rpindex = allObjects.Find(new Guid(policyGuid));
                                    if (rpindex != -1)
                                    {
                                        rp = (ResourcePolicy)allObjects.GetAt(rpindex);
                                    }
                                }
                                catch (System.Exception err)
                                {
                                    SpoDebug.DebugTraceSevere(func, "Bad GUID: " + policyGuid + "  Exception: " + err.Message);
                                    rp = null;
                                }

                                if (rp == null)
                                {
                                    SpoDebug.DebugTraceSevere(func, "Unable to find ResourcePolicy with GUID: " + policyGuid);
                                }

                                // Search for the specified host   


foreach (DataModelObject dmo in allObjects)
{
    if (dmo is IResourcePolicy &amp;&amp; string.Compare(dmo.Name, hostName, true) == 0)
    {
        IResourcePolicy irp = (IResourcePolicy)dmo;
        irp.AgentVersion = agentVersion;
        if (rp != null)  // this is the condition we need to look
        {
            irp.ResourcePolicy = rp;
            irp.AgentPolicyVersion.Version = Convert.ToInt64(policyVersion);
            irp.ResourcePolicyEnabled = Convert.ToBoolean(enabled);
        }
        // Distribute the object without saving it.
        SpoServer.Spurt.ServerSendObject(dmo, true, 0);

        break;
   }

}
</code></pre>

<p>So I made it this way:</p>

<pre><code>foreach (DataModelObject dmo in allObjects)
{
    if (dmo is IResourcePolicy &amp;&amp; string.Compare(dmo.Name, hostName, true) == 0)
    {
        IResourcePolicy irp = (IResourcePolicy)dmo;
        irp.AgentVersion = agentVersion;
        if (rp == null)
        {
            irp.ResourcePolicy = null;
        }
        else
        {
            irp.ResourcePolicy = rp;
            irp.AgentPolicyVersion.Version = Convert.ToInt64(policyVersion);
            irp.ResourcePolicyEnabled = Convert.ToBoolean(enabled);
        }

        // Distribute the object without saving it.
        SpoServer.Spurt.ServerSendObject(dmo, true, 0);

        break;
    }
}
</code></pre>

<p>Is that sufficient?</p>
