⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 baseclassverifier.htm

📁 遗传算法GPE_release_v1.0.tar
💻 HTM
📖 第 1 页 / 共 2 页
字号:
<html>

<head>
<meta name="GENERATOR" content="Microsoft FrontPage 5.0">
<meta name="ProgId" content="FrontPage.Editor.Document">
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<title>Genetic Programming FAQ</title>
</head>

<body>

<div id="nsbanner">
  <table cellSpacing="0" cellPadding="0" width="100%" border="0">
    <tr>
      <td>
      <div id="bannerrow1">
        <table class="bannerparthead" cellSpacing="0">
          <tr id="hdr">
            <td class="runninghead" style="font-size: 70%">
            <font face="Arial"><a class="show" id="design_toggle" title="Show or hide design notes" href="../../index.html"><img src="../../Images/Icons/G.png" width="14" height="14" border="0" align="middle"/></a> Genetic Programming Engine FAQ</font></td>
          </tr>
        </table>
      </div>
      <div id="TitleRow">
        <h1 class="dtH1" style="font-size: 85%; left: 5px; position: relative">
        <font face="Arial">Verifying the Base Class</font></h1>
      </div>
      </td>
      <td vAlign="top" align="right">
      <font face="Arial">
      <img src="../../Images/Icons/GP_blue.png" width="191" height="39"></font></td>
    </tr>
  </table>
  <p><p><font face="Arial">The BaseClassVerifier ensures that the type 
  passed to its constructor is a compatible <b>IIndividual</b> <i>Base Class</i> 
  for use by the <b>GPEngine</b>.&nbsp; It is ensured that the type is for a 
  class; that it is not abstract; that it is not sealed; that it inherits from 
  the IIndividual interface; and that it has a default, parameterless 
  constructor.&nbsp; It also ensures that there is at least one available 
  method.</font><p></div>
<div id="nstext">
  <div align="center">
    <center>
    <table border="0" cellpadding="0" cellspacing="0" style="border-collapse: collapse" bordercolor="#111111" width="90%" id="AutoNumber1">
      <tr>
        <td width="100%"><font SIZE="2">
        <p style="margin-top: 0; margin-bottom: 0"></font>
        <font SIZE="2" face="Courier New">public</font><font SIZE="2"><font face="Courier New"> 
        BaseClassVerifier( Type baseClassType ) {</font></p>
        <p style="margin-top: 0; margin-bottom: 0"><font face="Courier New">&nbsp;&nbsp;&nbsp;
        </font></font><font SIZE="2" face="Courier New">//check for null 
        arguments</p>
        </font><font SIZE="2">
        <p style="margin-top: 0; margin-bottom: 0"><font face="Courier New">&nbsp;&nbsp;&nbsp;
        </font></font><font SIZE="2" face="Courier New">if( baseClassType == 
        null</font><font SIZE="2"><font face="Courier New"> ) {</font></p>
        <p style="margin-top: 0; margin-bottom: 0"><font face="Courier New">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
        </font></font><font SIZE="2" face="Courier New">throw new 
        ArgumentNullException( &quot;baseClassType&quot;, &quot;The type passed to</font></p>
        <p style="margin-top: 0; margin-bottom: 0">
        <font face="Courier New" SIZE="2">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
        </font><font SIZE="2"><font face="Courier New">&nbsp;BaseClassVerifier.constructor 
        was null.&quot; );</font></p>
        <p style="margin-top: 0; margin-bottom: 0"><font face="Courier New">&nbsp;&nbsp;&nbsp; 
        }</font></p>
        <p style="margin-top: 0; margin-bottom: 0"><font face="Courier New">&nbsp;&nbsp;&nbsp;
        </font></font><font SIZE="2" face="Courier New">//check that this is an 
        instantiable class of type IIndividual with a default</font></p>
        <p style="margin-top: 0; margin-bottom: 0">
        <font face="Courier New" SIZE="2">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
        constructor</p>
        </font><font SIZE="2">
        <p style="margin-top: 0; margin-bottom: 0"><font face="Courier New">&nbsp;&nbsp;&nbsp;
        </font></font><font SIZE="2" face="Courier New">if</font><font SIZE="2"><font face="Courier New">( 
        !baseClassType.IsClass ) {</font></p>
        <p style="margin-top: 0; margin-bottom: 0"><font face="Courier New">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
        </font></font><font SIZE="2" face="Courier New">throw new 
        ArgumentException( &quot;The type passed to BaseClassVerifier.constructor</font></p>
        <p style="margin-top: 0; margin-bottom: 0">
        <font face="Courier New" SIZE="2">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
        </font><font SIZE="2"><font face="Courier New">&nbsp;was not a class.&quot;, 
        &quot;baseClassType&quot; );</font></p>
        <p style="margin-top: 0; margin-bottom: 0"><font face="Courier New">&nbsp;&nbsp;&nbsp; 
        }</font></p>
        <p style="margin-top: 0; margin-bottom: 0"><font face="Courier New">&nbsp;&nbsp;&nbsp;
        </font></font><font SIZE="2" face="Courier New">if</font><font SIZE="2"><font face="Courier New">( 
        baseClassType.IsAbstract ) {</font></p>
        <p style="margin-top: 0; margin-bottom: 0"><font face="Courier New">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
        </font></font><font SIZE="2" face="Courier New">throw new 
        ArgumentException( &quot;The type passed to BaseClassVerifier.constructor</font></p>
        <p style="margin-top: 0; margin-bottom: 0">
        <font face="Courier New" SIZE="2">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
        </font><font SIZE="2"><font face="Courier New">&nbsp;was abstract.&quot;, &quot;baseClassType&quot; 
        );</font></p>
        <p style="margin-top: 0; margin-bottom: 0"><font face="Courier New">&nbsp;&nbsp;&nbsp; 
        }</font></p>
        <p style="margin-top: 0; margin-bottom: 0"><font face="Courier New">&nbsp;&nbsp;&nbsp;
        </font></font><font SIZE="2" face="Courier New">if</font><font SIZE="2"><font face="Courier New">( 
        baseClassType.IsSealed ) {</font></p>
        <p style="margin-top: 0; margin-bottom: 0"><font face="Courier New">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
        </font></font><font SIZE="2" face="Courier New">throw new 
        ArgumentException( &quot;The type passed to BaseClassVerifier.constructor</font></p>
        <p style="margin-top: 0; margin-bottom: 0">
        <font face="Courier New" SIZE="2">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
        </font><font SIZE="2"><font face="Courier New">&nbsp;was sealed.&quot;, &quot;baseClassType&quot; 
        );</font></p>
        <p style="margin-top: 0; margin-bottom: 0"><font face="Courier New">&nbsp;&nbsp;&nbsp; 
        }</font></p>
        <p style="margin-top: 0; margin-bottom: 0"><font face="Courier New">&nbsp;&nbsp;&nbsp;
        </font></font><font SIZE="2" face="Courier New">if( 
        baseClassType.GetInterface( typeof(IIndividual).FullName ) == null</font><font SIZE="2"><font face="Courier New"> 
        ) {</font></p>
        <p style="margin-top: 0; margin-bottom: 0"><font face="Courier New">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
        </font></font><font SIZE="2" face="Courier New">throw new 
        ArgumentException( &quot;The type passed to BaseClassVerifier.constructor</font></p>
        <p style="margin-top: 0; margin-bottom: 0">
        <font face="Courier New" SIZE="2">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
        </font><font SIZE="2"><font face="Courier New">&nbsp;was not of type 
        IIndividual.&quot;, &quot;baseClassType&quot; );</font></p>
        <p style="margin-top: 0; margin-bottom: 0"><font face="Courier New">&nbsp;&nbsp;&nbsp; 
        }</font></p>
        <p style="margin-top: 0; margin-bottom: 0"><font face="Courier New">&nbsp;&nbsp;&nbsp; 
        MethodInfo testMethod = baseClassType.GetMethod( &quot;Test&quot;, Type.EmptyTypes 
        );</font></p>
        <p style="margin-top: 0; margin-bottom: 0"><font face="Courier New">&nbsp;&nbsp;&nbsp;
        </font></font><font SIZE="2" face="Courier New">if</font><font SIZE="2"><font face="Courier New">( 
        !testMethod.IsVirtual || testMethod.IsFinal ) {</font></p>
        <p style="margin-top: 0; margin-bottom: 0"><font face="Courier New">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
        </font></font><font SIZE="2" face="Courier New">throw new 
        ArgumentException( &quot;The type passed to BaseClassVerifier.constructor</font></p>
        <p style="margin-top: 0; margin-bottom: 0">
        <font face="Courier New" SIZE="2">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
        </font><font SIZE="2"><font face="Courier New">&nbsp;does not define the 
        Test method as virtual.&quot;, &quot;baseClassType&quot; );</font></p>
        <p style="margin-top: 0; margin-bottom: 0"><font face="Courier New">&nbsp;&nbsp;&nbsp; 
        }</font></p>
        <p style="margin-top: 0; margin-bottom: 0"><font face="Courier New">&nbsp;&nbsp;&nbsp;
        </font></font><font SIZE="2" face="Courier New">if( 
        baseClassType.GetConstructor( Type.EmptyTypes ) == null</font><font SIZE="2"><font face="Courier New"> 
        ) {</font></p>
        <p style="margin-top: 0; margin-bottom: 0"><font face="Courier New">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
        </font></font><font SIZE="2" face="Courier New">throw new 
        ArgumentException( &quot;The type passed to BaseClassVerifier.constructor</font></p>
        <p style="margin-top: 0; margin-bottom: 0">
        <font face="Courier New" SIZE="2">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
        </font><font SIZE="2"><font face="Courier New">&nbsp;does not have a 
        parameterless constructor.&quot;, &quot;baseClassType&quot; );</font></p>
        <p style="margin-top: 0; margin-bottom: 0"><font face="Courier New">&nbsp;&nbsp;&nbsp; 
        }</font></p>
        <p style="margin-top: 0; margin-bottom: 0"><font face="Courier New">&nbsp;&nbsp;&nbsp;
        </font></font><font SIZE="2" face="Courier New">//get type's methods</p>
        </font><font SIZE="2">
        <p style="margin-top: 0; margin-bottom: 0"><font face="Courier New">&nbsp;&nbsp;&nbsp; 
        MethodInfoCollection extraMethods = </font></p>
        <p style="margin-top: 0; margin-bottom: 0"><font face="Courier New">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
        </font></font><font SIZE="2" face="Courier New">new MethodInfoCollection( 
        baseClassType.GetMethods( BindingFlags.Public |</font></p>
        <p style="margin-top: 0; margin-bottom: 0">
        <font face="Courier New" SIZE="2">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
        </font><font SIZE="2"><font face="Courier New">&nbsp;BindingFlags.Instance 
        ) );</font></p>
        <p style="margin-top: 0; margin-bottom: 0"><font face="Courier New">&nbsp;&nbsp;&nbsp;
        </font></font><font SIZE="2" face="Courier New">//remove methods 
        inherited from object in-line</p>
        </font><font SIZE="2">
        <p style="margin-top: 0; margin-bottom: 0"><font face="Courier New">&nbsp;&nbsp;&nbsp;
        </font></font><font SIZE="2" face="Courier New">for( int</font><font SIZE="2"><font face="Courier New"> 
        index = 0; index &lt; extraMethods.Count; ++index ) {</font></p>
        <p style="margin-top: 0; margin-bottom: 0"><font face="Courier New">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
        </font></font><font SIZE="2" face="Courier New">if( 
        extraMethods[index].DeclaringType == typeof(object</font><font SIZE="2"><font face="Courier New">) 
        ) {</font></p>
        <p style="margin-top: 0; margin-bottom: 0"><font face="Courier New">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
        extraMethods.RemoveAt( index );</font></p>
        <p style="margin-top: 0; margin-bottom: 0"><font face="Courier New">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
        --index;</font></p>
        <p style="margin-top: 0; margin-bottom: 0"><font face="Courier New">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
        }</font></p>
        <p style="margin-top: 0; margin-bottom: 0"><font face="Courier New">&nbsp;&nbsp;&nbsp; 
        }</font></p>
        <p style="margin-top: 0; margin-bottom: 0"><font face="Courier New">&nbsp;&nbsp;&nbsp;
        </font></font><font SIZE="2" face="Courier New">//remove interface 
        methods</p>
        </font><font SIZE="2">
        <p style="margin-top: 0; margin-bottom: 0"><font face="Courier New">&nbsp;&nbsp;&nbsp; 
        MethodInfo[] removeMethods = </font></p>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -