Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
03/05/10 01:03:30 (15 years ago)
Author:
swagner
Message:

Operator architecture refactoring (#95)

  • worked on ItemAttribute and named items
  • corrected version information in Optimizer
Location:
trunk/sources/HeuristicLab.Core/3.3
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Core/3.3/Attributes/CreatableAttribute.cs

    r2790 r2931  
    2121
    2222using System;
    23 using System.Collections.Generic;
    24 using System.Text;
    2523
    2624namespace HeuristicLab.Core {
  • trunk/sources/HeuristicLab.Core/3.3/Attributes/ItemAttribute.cs

    r2790 r2931  
    2121
    2222using System;
    23 using System.Collections.Generic;
    24 using System.Text;
    25 using System.Resources;
    26 using System.Drawing;
     23using HeuristicLab.Common;
    2724
    2825namespace HeuristicLab.Core {
    2926  [AttributeUsage(AttributeTargets.Class, AllowMultiple = false, Inherited = false)]
    3027  public sealed class ItemAttribute : Attribute {
    31     public string Name { get; set; }
    32     public string Description { get; set; }
     28    private string name;
     29    public string Name {
     30      get { return name; }
     31      set { name = value == null ? string.Empty : value; }
     32    }
     33    private string description;
     34    public string Description {
     35      get { return description; }
     36      set { description = value == null ? string.Empty : value; }
     37    }
    3338
    3439    public ItemAttribute() {
    35       Name = null;
    36       Description = null;
     40      Name = string.Empty;
     41      Description = string.Empty;
    3742    }
    3843    public ItemAttribute(string name, string description) {
     
    4247
    4348    public static string GetName(Type type) {
    44       object[] attribs = type.GetCustomAttributes(typeof(ItemAttribute), true);
     49      object[] attribs = type.GetCustomAttributes(typeof(ItemAttribute), false);
    4550      if (attribs.Length > 0) return ((ItemAttribute)attribs[0]).Name;
    46       else return null;
     51      else return type.GetPrettyName();
    4752    }
    4853    public static string GetDescription(Type type) {
    49       object[] attribs = type.GetCustomAttributes(typeof(ItemAttribute), true);
     54      object[] attribs = type.GetCustomAttributes(typeof(ItemAttribute), false);
    5055      if (attribs.Length > 0) return ((ItemAttribute)attribs[0]).Description;
    51       else return null;
     56      else return string.Empty;
    5257    }
    5358  }
  • trunk/sources/HeuristicLab.Core/3.3/NamedItem.cs

    r2851 r2931  
    2121
    2222using System;
    23 using System.Collections.Generic;
    24 using System.Text;
    25 using System.Xml;
     23using HeuristicLab.Common;
    2624using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    27 using HeuristicLab.Common;
    2825
    2926namespace HeuristicLab.Core {
     
    3835      get { return name; }
    3936      set {
    40         if (!CanChangeName) throw new NotSupportedException("Name of NamedItem cannot be changed.");
    41         if (value == null) throw new ArgumentNullException();
    42         if (!name.Equals(value)) {
    43           CancelEventArgs<string> e = new CancelEventArgs<string>(value);
     37        if (!CanChangeName) throw new NotSupportedException("Name cannot be changed.");
     38        if (!(name.Equals(value) || (value == null) && (name == string.Empty))) {
     39          CancelEventArgs<string> e = value == null ? new CancelEventArgs<string>(string.Empty) : new CancelEventArgs<string>(value);
    4440          OnNameChanging(e);
    4541          if (!e.Cancel) {
    46             name = value;
     42            name = value == null ? string.Empty : value;
    4743            OnNameChanged();
    4844          }
     
    5854      get { return description; }
    5955      set {
    60         if (!CanChangeDescription) throw new NotSupportedException("Description of NamedItem cannot be changed.");
    61         if ((description == null) || (!description.Equals(value))) {
    62           description = value;
     56        if (!CanChangeDescription) throw new NotSupportedException("Description cannot be changed.");
     57        if (!(description.Equals(value) || (value == null) && (description == string.Empty))) {
     58          description = value == null ? string.Empty : value;
    6359          OnDescriptionChanged();
    6460        }
     
    8480    /// <param name="value">The value of the current instance.</param>
    8581    protected NamedItem(string name) {
    86       if (name == null) throw new ArgumentNullException();
    87       this.name = name;
     82      if (name == null) this.name = string.Empty;
     83      else this.name = name;
    8884      description = string.Empty;
    8985    }
    9086    protected NamedItem(string name, string description) {
    91       if (name == null) throw new ArgumentNullException();
    92       this.name = name;
    93       this.description = description;
     87      if (name == null) this.name = string.Empty;
     88      else this.name = name;
     89      if (description == null) this.description = string.Empty;
     90      else this.description = description;
    9491    }
    9592
  • trunk/sources/HeuristicLab.Core/3.3/Scope.cs

    r2830 r2931  
    8282      SubScopes = new ScopeList();
    8383    }
     84    public Scope(string name, string description)
     85      : base(name, description) {
     86      parent = null;
     87      Variables = new VariableCollection();
     88      SubScopes = new ScopeList();
     89    }
    8490
    8591    /// <inheritdoc/>
Note: See TracChangeset for help on using the changeset viewer.