Free cookie consent management tool by TermsFeed Policy Generator

Changes between Version 1 and Version 2 of Documentation/DevelopmentCenter/DeveloperGuidelinesSourceExample


Ignore:
Timestamp:
08/10/10 02:36:37 (14 years ago)
Author:
swagner
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • Documentation/DevelopmentCenter/DeveloperGuidelinesSourceExample

    v1 v2  
    1 = Source Code Example =
     1= HeuristicLab Development Guidelines - Source Example =
    22
    33{{{
    4 #!cpp
    5 /* A multiline comment
    6  * describing something ...
     4#!text/x-csharp
     5#region License Information
     6/* HeuristicLab
     7 * Copyright (C) 2002-2010 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
     8 *
     9 * This file is part of HeuristicLab.
     10 *
     11 * HeuristicLab is free software: you can redistribute it and/or modify
     12 * it under the terms of the GNU General Public License as published by
     13 * the Free Software Foundation, either version 3 of the License, or
     14 * (at your option) any later version.
     15 *
     16 * HeuristicLab is distributed in the hope that it will be useful,
     17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
     18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     19 * GNU General Public License for more details.
     20 *
     21 * You should have received a copy of the GNU General Public License
     22 * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
    723 */
     24#endregion
     25
    826using System;
    9 using System.Collections.Generic;
    10 using System.Text;
     27using System.Drawing;
     28using HeuristicLab.Common;
     29using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    1130
    1231namespace HeuristicLab.Core {
    13   public class Sheep : Mammal, IAnimal {
    14     private double myWeight;
    15     public double Weight {  // a comment
    16       get { return myWeight; }
     32  /// <summary>
     33  /// Represents the base class for all basic item types.
     34  /// </summary>
     35  [StorableClass]
     36  [Item("Item", "Base class for all HeuristicLab items.")]
     37  public abstract class Item : IItem {
     38    private string filename;
     39    public string Filename {
     40      get { return filename; }
    1741      set {
    18         if (value > 0)
    19           myWeight = value;
     42        if (value == null) throw new ArgumentNullException();
     43        if ((filename == null) || !filename.Equals(value)) {
     44          filename = value;
     45          OnFilenameChanged();
     46        }
    2047      }
    2148    }
    2249
    23 
    24     public Sheep() {
    25       myWeight = 666;
     50    public virtual string ItemName {
     51      get { return ItemAttribute.GetName(this.GetType()); }
    2652    }
    27     public Sheep(double weight) {
    28       myWeight = weight;
     53    public virtual string ItemDescription {
     54      get { return ItemAttribute.GetDescription(this.GetType()); }
     55    }
     56    public Version ItemVersion {
     57      get { return ItemAttribute.GetVersion(this.GetType()); }
     58    }
     59    public virtual Image ItemImage {
     60      get { return HeuristicLab.Common.Resources.VS2008ImageLibrary.Class; }
    2961    }
    3062
     63    protected Item() {
     64      filename = string.Empty;
     65    }
     66    [StorableConstructor]
     67    protected Item(bool deserializing) {
     68      filename = string.Empty;
     69    }
    3170
    32     // a comment describing a method
    33     public string LookABitSilly() {
    34       return "Oo";
     71    public object Clone() {
     72      return Clone(new Cloner());
     73    }
     74    public virtual IDeepCloneable Clone(Cloner cloner) {
     75      Item clone = (Item)Activator.CreateInstance(this.GetType(), true);
     76      cloner.RegisterClonedObject(this, clone);
     77      return clone;
    3578    }
    3679
    3780    public override string ToString() {
    38       return "Sheep (" + Weight.ToString() + " tons)";
     81      return ItemName;
    3982    }
    4083
    41     public event EventHandler Baa;
    42     protected virtual void OnBaa() {
    43       if (Baa != null)
    44         Baa(this, new EventArgs());
     84    public event EventHandler FilenameChanged;
     85    protected virtual void OnFilenameChanged() {
     86      EventHandler handler = FilenameChanged;
     87      if (handler != null) handler(this, EventArgs.Empty);
     88    }
     89    public event EventHandler ItemImageChanged;
     90    protected virtual void OnItemImageChanged() {
     91      EventHandler handler = ItemImageChanged;
     92      if (handler != null) handler(this, EventArgs.Empty);
     93    }
     94    public event EventHandler ToStringChanged;
     95    protected virtual void OnToStringChanged() {
     96      EventHandler handler = ToStringChanged;
     97      if (handler != null) handler(this, EventArgs.Empty);
    4598    }
    4699  }