Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
04/16/09 12:58:14 (15 years ago)
Author:
epitzer
Message:

Format white space. (Ctrl-K, Ctrl-D) (#548)

Location:
trunk/sources/HeuristicLab.Persistence/3.3/Core
Files:
18 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Persistence/3.3/Core/Configuration.cs

    r1564 r1566  
    1414    private readonly Dictionary<Type, IDecomposer> decomposerCache;
    1515
    16     [Storable]   
     16    [Storable]
    1717    public IFormat Format { get; private set; }
    1818
     
    2424      this.Format = format;
    2525      this.formatters = new Dictionary<Type, IFormatter>();
    26       foreach ( var pair in formatters ) {
    27         if (pair.Value.SerialDataType != format.SerialDataType ) {
     26      foreach (var pair in formatters) {
     27        if (pair.Value.SerialDataType != format.SerialDataType) {
    2828          throw new ArgumentException("All formatters must have the same IFormat.");
    2929        }
     
    3131      }
    3232      this.decomposers = new List<IDecomposer>(decomposers);
    33       decomposerCache = new Dictionary<Type, IDecomposer>();     
     33      decomposerCache = new Dictionary<Type, IDecomposer>();
    3434    }
    3535
     
    4242    }
    4343
    44     public IFormatter GetFormatter(Type type) {     
     44    public IFormatter GetFormatter(Type type) {
    4545      IFormatter formatter;
    4646      formatters.TryGetValue(type, out formatter);
     
    5050    public IDecomposer GetDecomposer(Type type) {
    5151      if (decomposerCache.ContainsKey(type))
    52         return decomposerCache[type];     
     52        return decomposerCache[type];
    5353      foreach (IDecomposer d in decomposers) {
    5454        if (d.CanDecompose(type)) {
     
    5959      decomposerCache.Add(type, null);
    6060      return null;
    61     }   
    62   } 
    63  
     61    }
     62  }
     63
    6464}
  • trunk/sources/HeuristicLab.Persistence/3.3/Core/ConfigurationService.cs

    r1564 r1566  
    1010
    1111namespace HeuristicLab.Persistence.Core {
    12  
     12
    1313  public class ConfigurationService {
    1414
     
    1818    public List<IDecomposer> Decomposers { get; private set; }
    1919    public List<IFormat> Formats { get; private set; }
    20    
     20
    2121    public static ConfigurationService Instance {
    2222      get {
     
    5454        }
    5555      } catch (Exception e) {
    56         Logger.Warn("Could not load settings.", e);       
     56        Logger.Warn("Could not load settings.", e);
    5757      }
    5858    }
    5959
    60     public void SaveSettings() {     
     60    public void SaveSettings() {
    6161      Serializer serializer = new Serializer(
    6262        customConfigurations,
     
    7878    }
    7979
    80     public void Reset() {     
     80    public void Reset() {
    8181      customConfigurations.Clear();
    8282      Formatters.Clear();
     
    8585      DiscoverFrom(defaultAssembly);
    8686      foreach (Assembly a in AppDomain.CurrentDomain.GetAssemblies())
    87         if ( a != defaultAssembly )
     87        if (a != defaultAssembly)
    8888          DiscoverFrom(a);
    8989      SortDecomposers();
     
    102102    protected void DiscoverFrom(Assembly a) {
    103103      foreach (Type t in a.GetTypes()) {
    104         if (t.GetInterface(typeof (IFormatter).FullName) != null) {
     104        if (t.GetInterface(typeof(IFormatter).FullName) != null) {
    105105          try {
    106             IFormatter formatter = (IFormatter) Activator.CreateInstance(t, true);
    107             if ( ! Formatters.ContainsKey(formatter.SerialDataType) ) {
     106            IFormatter formatter = (IFormatter)Activator.CreateInstance(t, true);
     107            if (!Formatters.ContainsKey(formatter.SerialDataType)) {
    108108              Formatters.Add(formatter.SerialDataType, new List<IFormatter>());
    109109            }
     
    114114              formatter.SerialDataType.VersionInvariantName()));
    115115          } catch (MissingMethodException e) {
    116             Logger.Warn("Could not instantiate " + t.VersionInvariantName(), e);           
     116            Logger.Warn("Could not instantiate " + t.VersionInvariantName(), e);
    117117          } catch (ArgumentException e) {
    118118            Logger.Warn("Could not instantiate " + t.VersionInvariantName(), e);
    119119          }
    120120        }
    121         if (t.GetInterface(typeof (IDecomposer).FullName) != null) {
     121        if (t.GetInterface(typeof(IDecomposer).FullName) != null) {
    122122          try {
    123             Decomposers.Add((IDecomposer) Activator.CreateInstance(t, true));
     123            Decomposers.Add((IDecomposer)Activator.CreateInstance(t, true));
    124124            Logger.Debug("discovered decomposer " + t.VersionInvariantName());
    125125          } catch (MissingMethodException e) {
    126             Logger.Warn("Could not instantiate " + t.VersionInvariantName(), e);         
     126            Logger.Warn("Could not instantiate " + t.VersionInvariantName(), e);
    127127          } catch (ArgumentException e) {
    128128            Logger.Warn("Could not instantiate " + t.VersionInvariantName(), e);
     
    136136              format.Name,
    137137              format.SerialDataType,
    138               t.VersionInvariantName()));             
     138              t.VersionInvariantName()));
    139139          } catch (MissingMethodException e) {
    140             Logger.Warn("Could not instantiate " + t.VersionInvariantName(), e);         
     140            Logger.Warn("Could not instantiate " + t.VersionInvariantName(), e);
    141141          } catch (ArgumentException e) {
    142142            Logger.Warn("Could not instantiate " + t.VersionInvariantName(), e);
    143           }         
     143          }
    144144        }
    145145      }
     
    148148    public Configuration GetDefaultConfig(IFormat format) {
    149149      Dictionary<Type, IFormatter> formatterConfig = new Dictionary<Type, IFormatter>();
    150       foreach ( IFormatter f in Formatters[format.SerialDataType] ) {
    151         if ( ! formatterConfig.ContainsKey(f.SourceType) )
     150      foreach (IFormatter f in Formatters[format.SerialDataType]) {
     151        if (!formatterConfig.ContainsKey(f.SourceType))
    152152          formatterConfig.Add(f.SourceType, f);
    153153      }
     
    161161    }
    162162
    163     public void DefineConfiguration(Configuration configuration) {     
     163    public void DefineConfiguration(Configuration configuration) {
    164164      customConfigurations[configuration.Format] = configuration;
    165165      SaveSettings();
     
    167167
    168168  }
    169  
     169
    170170}
  • trunk/sources/HeuristicLab.Persistence/3.3/Core/DataMemberAccessor.cs

    r1542 r1566  
    1111    public readonly Getter Get;
    1212    public readonly Setter Set;
    13     public readonly string Name;   
     13    public readonly string Name;
    1414    public readonly object DefaultValue;
    1515
     
    2121        FieldInfo fieldInfo = (FieldInfo)memberInfo;
    2222        Get = () => fieldInfo.GetValue(obj);
    23         Set = value => fieldInfo.SetValue(obj, value);       
     23        Set = value => fieldInfo.SetValue(obj, value);
    2424      } else if (memberInfo.MemberType == MemberTypes.Property) {
    2525        PropertyInfo propertyInfo = (PropertyInfo)memberInfo;
     
    2929        }
    3030        Get = () => propertyInfo.GetValue(obj, null);
    31         Set = value => propertyInfo.SetValue(obj, value, null);       
     31        Set = value => propertyInfo.SetValue(obj, value, null);
    3232      } else {
    3333        throw new NotSupportedException(
     
    4141        string name, object defaultValue,
    4242        Getter getter, Setter setter) {
    43       Name = name;     
     43      Name = name;
    4444      DefaultValue = defaultValue;
    4545      Get = getter;
     
    4848
    4949    public DataMemberAccessor(object o) {
    50       Name = null;     
     50      Name = null;
    5151      DefaultValue = null;
    5252      Get = () => o;
     
    5555
    5656    public DataMemberAccessor(object o, string name) {
    57       Name = name;     
     57      Name = name;
    5858      DefaultValue = null;
    5959      Get = () => o;
  • trunk/sources/HeuristicLab.Persistence/3.3/Core/DeSerializer.cs

    r1556 r1566  
    44using HeuristicLab.Persistence.Core.Tokens;
    55
    6 namespace HeuristicLab.Persistence.Core { 
     6namespace HeuristicLab.Persistence.Core {
    77
    8   public class ParentReference {
     8  public class ParentReference { }
    99
    1010  class Midwife {
    11    
    12     public int? Id { get; private set; }   
     11
     12    public int? Id { get; private set; }
    1313    public bool MetaMode { get; set; }
    1414    public object Obj { get; private set; }
     
    2222      this.Obj = value;
    2323    }
    24        
    25     public Midwife(Type type, IDecomposer decomposer, int? id) {   
     24
     25    public Midwife(Type type, IDecomposer decomposer, int? id) {
    2626      this.type = type;
    27       this.decomposer = decomposer;     
     27      this.decomposer = decomposer;
    2828      this.Id = id;
    29       MetaMode = false;     
     29      MetaMode = false;
    3030      metaInfo = new List<Tag>();
    31       customValues = new List<Tag>();           
     31      customValues = new List<Tag>();
    3232    }
    3333
     
    3535      if (Obj != null)
    3636        throw new ApplicationException("object already instantiated");
    37       Obj = decomposer.CreateInstance(type, metaInfo);     
     37      Obj = decomposer.CreateInstance(type, metaInfo);
    3838    }
    3939
     
    4949      decomposer.Populate(Obj, customValues, type);
    5050    }
    51   } 
     51  }
    5252
    5353  public class Deserializer {
    54    
     54
    5555    private readonly Dictionary<int, object> id2obj;
    5656    private readonly Dictionary<Type, object> serializerMapping;
    57     private readonly Stack<Midwife> parentStack;   
     57    private readonly Stack<Midwife> parentStack;
    5858    private readonly Dictionary<int, Type> typeIds;
    5959
     
    7979    }
    8080
    81     public object Deserialize(IEnumerable<ISerializationToken> tokens) {     
     81    public object Deserialize(IEnumerable<ISerializationToken> tokens) {
    8282      foreach (ISerializationToken token in tokens) {
    8383        Type t = token.GetType();
    84         if ( t == typeof(BeginToken) ) {
     84        if (t == typeof(BeginToken)) {
    8585          CompositeStartHandler((BeginToken)token);
    86         } else if ( t == typeof(EndToken) ) {
    87           CompositeEndHandler((EndToken) token);
    88         } else if ( t == typeof(PrimitiveToken) ) {
    89           PrimitiveHandler((PrimitiveToken) token);
    90         } else if ( t == typeof(ReferenceToken) ) {
    91           ReferenceHandler((ReferenceToken) token);
     86        } else if (t == typeof(EndToken)) {
     87          CompositeEndHandler((EndToken)token);
     88        } else if (t == typeof(PrimitiveToken)) {
     89          PrimitiveHandler((PrimitiveToken)token);
     90        } else if (t == typeof(ReferenceToken)) {
     91          ReferenceHandler((ReferenceToken)token);
    9292        } else if (t == typeof(NullReferenceToken)) {
    9393          NullHandler((NullReferenceToken)token);
     
    106106      Type type = typeIds[(int)token.TypeId];
    107107      IDecomposer decomposer = null;
    108       if ( serializerMapping.ContainsKey(type) )
     108      if (serializerMapping.ContainsKey(type))
    109109        decomposer = serializerMapping[type] as IDecomposer;
    110110      if (decomposer == null)
     
    124124    private void PrimitiveHandler(PrimitiveToken token) {
    125125      Type type = typeIds[(int)token.TypeId];
    126       object value = ((IFormatter) serializerMapping[type]).Parse(token.SerialData);
    127       if ( token.Id != null )     
     126      object value = ((IFormatter)serializerMapping[type]).Parse(token.SerialData);
     127      if (token.Id != null)
    128128        id2obj[(int)token.Id] = value;
    129129      SetValue(token.Name, value);
     
    144144
    145145    private void MetaInfoEnd(MetaInfoEndToken token) {
    146       Midwife m = parentStack.Peek();     
     146      Midwife m = parentStack.Peek();
    147147      m.MetaMode = false;
    148148      CreateInstance(m);
     
    152152      m.CreateInstance();
    153153      if (m.Id != null)
    154         id2obj.Add((int)m.Id, m.Obj);     
     154        id2obj.Add((int)m.Id, m.Obj);
    155155    }
    156156
    157157    private void SetValue(string name, object value) {
    158       if (parentStack.Count == 0) {       
     158      if (parentStack.Count == 0) {
    159159        parentStack.Push(new Midwife(value));
    160160      } else {
     
    162162        if (m.MetaMode == false && m.Obj == null)
    163163          CreateInstance(m);
    164         m.AddValue(name, value);       
     164        m.AddValue(name, value);
    165165      }
    166166    }
  • trunk/sources/HeuristicLab.Persistence/3.3/Core/EmptyStorableClassAttribute.cs

    r1555 r1566  
    55namespace HeuristicLab.Persistence.Core {
    66
    7  
     7
    88  [AttributeUsage(
    99    AttributeTargets.Class,
    10     AllowMultiple=false,
    11     Inherited=false)]
     10    AllowMultiple = false,
     11    Inherited = false)]
    1212  public class EmptyStorableClassAttribute : Attribute {
    1313
    1414    private static readonly Dictionary<Type, bool> emptyTypeInfo = new Dictionary<Type, bool>();
    15     public static bool IsEmptyStorable(Type type) {     
     15    public static bool IsEmptyStorable(Type type) {
    1616      if (emptyTypeInfo.ContainsKey(type))
    1717        return emptyTypeInfo[type];
     
    2424      }
    2525      int nFields = 0;
    26       foreach ( MemberInfo memberInfo in type.GetMembers(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic) ) {
     26      foreach (MemberInfo memberInfo in type.GetMembers(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic)) {
    2727        if (memberInfo.MemberType == MemberTypes.Field ||
    2828          memberInfo.MemberType == MemberTypes.Property)
     
    3636      return false;
    3737    }
    38   } 
     38  }
    3939}
  • trunk/sources/HeuristicLab.Persistence/3.3/Core/FormatBase.cs

    r1564 r1566  
    1616
    1717    public override bool Equals(object obj) {
    18       FormatBase<SerialDataFormat> f = obj as FormatBase<SerialDataFormat>;     
     18      FormatBase<SerialDataFormat> f = obj as FormatBase<SerialDataFormat>;
    1919      return Equals(f);
    2020    }
    21    
     21
    2222  }
    2323
  • trunk/sources/HeuristicLab.Persistence/3.3/Core/FormatterBase.cs

    r1564 r1566  
    22
    33namespace HeuristicLab.Persistence.Interfaces {
    4  
     4
    55  public abstract class FormatterBase<Source, SerialData> : IFormatter<Source, SerialData> where SerialData : ISerialData {
    66
     
    1414
    1515    ISerialData IFormatter.Format(object o) {
    16       return Format((Source)o);   
     16      return Format((Source)o);
    1717    }
    1818
     
    2222
    2323  }
    24      
     24
    2525}
  • trunk/sources/HeuristicLab.Persistence/3.3/Core/GeneratorBase.cs

    r1564 r1566  
    1111
    1212namespace HeuristicLab.Persistence.Core {
    13  
     13
    1414  public abstract class GeneratorBase<T> {
    1515    public T Format(ISerializationToken token) {
     
    3838    protected abstract T Format(MetaInfoBeginToken metaInfoBeginToken);
    3939    protected abstract T Format(MetaInfoEndToken metaInfoEndToken);
    40   } 
     40  }
    4141}
  • trunk/sources/HeuristicLab.Persistence/3.3/Core/Serializer.cs

    r1564 r1566  
    1616
    1717    public List<TypeMapping> TypeCache {
    18       get {       
     18      get {
    1919        List<TypeMapping> result = new List<TypeMapping>();
    2020        foreach (var pair in typeCache) {
     
    3030          result.Add(new TypeMapping(pair.Value, pair.Key.VersionInvariantName(), serializer));
    3131        }
    32         return result;                                     
     32        return result;
    3333      }
    3434    }
    3535
    36     public Serializer(object obj, Configuration configuration) :       
     36    public Serializer(object obj, Configuration configuration) :
    3737      this(obj, configuration, "ROOT") { }
    3838
     
    4040      this.obj = obj;
    4141      this.rootName = rootName;
    42       this.configuration = configuration;     
    43       obj2id = new Dictionary<object, int> {{new object(), 0}};
     42      this.configuration = configuration;
     43      obj2id = new Dictionary<object, int> { { new object(), 0 } };
    4444      typeCache = new Dictionary<Type, int>();
    4545    }
     
    5252      return Serialize(new DataMemberAccessor(rootName, null, () => obj, null));
    5353    }
    54    
     54
    5555    private IEnumerator<ISerializationToken> Serialize(DataMemberAccessor accessor) {
    5656      object value = accessor.Get();
     
    5858        return NullReferenceEnumerator(accessor.Name);
    5959      if (obj2id.ContainsKey(value))
    60         return ReferenceEnumerator(accessor.Name, obj2id[value]);             
    61       if ( ! typeCache.ContainsKey(value.GetType()))
     60        return ReferenceEnumerator(accessor.Name, obj2id[value]);
     61      if (!typeCache.ContainsKey(value.GetType()))
    6262        typeCache.Add(value.GetType(), typeCache.Count);
    6363      int typeId = typeCache[value.GetType()];
    6464      int? id = null;
    65       if ( ! value.GetType().IsValueType) {
     65      if (!value.GetType().IsValueType) {
    6666        id = obj2id.Count;
    6767        obj2id.Add(value, (int)id);
     
    7070      if (formatter != null)
    7171        return PrimitiveEnumerator(accessor.Name, typeId, formatter.Format(value), id);
    72       IDecomposer decomposer = configuration.GetDecomposer(value.GetType()); 
     72      IDecomposer decomposer = configuration.GetDecomposer(value.GetType());
    7373      if (decomposer != null)
    7474        return CompositeEnumerator(accessor.Name, decomposer.Decompose(value), id, typeId, decomposer.CreateMetaInfo(value));
     
    7676          String.Format(
    7777          "No suitable method for serializing values of type \"{0}\" found.",
    78           value.GetType().VersionInvariantName()));     
     78          value.GetType().VersionInvariantName()));
    7979    }
    8080
     
    9494    private IEnumerator<ISerializationToken> CompositeEnumerator(
    9595        string name, IEnumerable<Tag> tags, int? id, int typeId, IEnumerable<Tag> metaInfo) {
    96       yield return new BeginToken(name, typeId, id);     
     96      yield return new BeginToken(name, typeId, id);
    9797      bool first = true;
    9898      foreach (var tag in metaInfo) {
     
    114114          yield return it.Current;
    115115      }
    116       yield return new EndToken(name, typeId, id);       
     116      yield return new EndToken(name, typeId, id);
    117117    }
    118118
  • trunk/sources/HeuristicLab.Persistence/3.3/Core/StorableAttribute.cs

    r1555 r1566  
    77  [AttributeUsage(
    88    AttributeTargets.Field | AttributeTargets.Property,
    9     AllowMultiple=false,
    10     Inherited=false)]
     9    AllowMultiple = false,
     10    Inherited = false)]
    1111  public class StorableAttribute : Attribute {
    1212
     
    1919      BindingFlags.NonPublic |
    2020      BindingFlags.DeclaredOnly;
    21    
     21
    2222    public static IEnumerable<KeyValuePair<StorableAttribute, MemberInfo>> GetStorableMembers(Type type) {
    23       return GetStorableMembers(type, true);     
     23      return GetStorableMembers(type, true);
    2424    }
    2525
     
    2727        GetStorableMembers(Type type, bool inherited) {
    2828      if (type.BaseType != null)
    29         foreach ( var pair in GetStorableMembers(type.BaseType) )
     29        foreach (var pair in GetStorableMembers(type.BaseType))
    3030          yield return pair;
    3131      foreach (MemberInfo memberInfo in type.GetMembers(instanceMembers)) {
    32         foreach (object attribute in memberInfo.GetCustomAttributes(false)) {         
     32        foreach (object attribute in memberInfo.GetCustomAttributes(false)) {
    3333          StorableAttribute storableAttribute =
    3434            attribute as StorableAttribute;
    3535          if (storableAttribute != null) {
    36             yield return new KeyValuePair<StorableAttribute, MemberInfo>(storableAttribute, memberInfo);           
     36            yield return new KeyValuePair<StorableAttribute, MemberInfo>(storableAttribute, memberInfo);
    3737          }
    3838        }
    39       }     
     39      }
    4040    }
    4141
     
    4646        storableAccessors.Add(pair.Value.Name,
    4747          new DataMemberAccessor(pair.Value, pair.Key, obj));
    48       }           
     48      }
    4949      return storableAccessors;
    50     }   
     50    }
    5151  }
    5252}
  • trunk/sources/HeuristicLab.Persistence/3.3/Core/Tag.cs

    r1553 r1566  
    55  public class Tag {
    66    public string Name { get; private set; }
    7     public object Value { get; set; }     
     7    public object Value { get; set; }
    88
    99    public Tag(string name, object value) {
  • trunk/sources/HeuristicLab.Persistence/3.3/Core/Tokens/MetaInfoEndToken.cs

    r1556 r1566  
    44
    55  public class MetaInfoEndToken : ISerializationToken { }
    6  
     6
    77}
  • trunk/sources/HeuristicLab.Persistence/3.3/Core/Tokens/NulLReferenceToken.cs

    r1556 r1566  
    22
    33namespace HeuristicLab.Persistence.Core.Tokens {
    4  
     4
    55  public class NullReferenceToken : SerializationTokenBase {
    66    public NullReferenceToken(string name) : base(name) { }
  • trunk/sources/HeuristicLab.Persistence/3.3/Core/Tokens/PrimitiveToken.cs

    r1564 r1566  
    22
    33namespace HeuristicLab.Persistence.Core.Tokens {
    4  
    5   public class PrimitiveToken : SerializationTokenBase {   
     4
     5  public class PrimitiveToken : SerializationTokenBase {
    66    public readonly int TypeId;
    77    public readonly int? Id;
  • trunk/sources/HeuristicLab.Persistence/3.3/Core/Tokens/ReferenceToken.cs

    r1556 r1566  
    22
    33namespace HeuristicLab.Persistence.Core.Tokens {
    4  
    5   public class ReferenceToken : SerializationTokenBase {   
     4
     5  public class ReferenceToken : SerializationTokenBase {
    66    public readonly int Id;
    77    public ReferenceToken(string name, int id)
  • trunk/sources/HeuristicLab.Persistence/3.3/Core/TypeExtensions.cs

    r1555 r1566  
    33
    44namespace HeuristicLab.Persistence.Core {
    5  
     5
    66  public static class TypeExtensions {
    77
     
    1212    }
    1313
    14   } 
    15  
     14  }
     15
    1616}
  • trunk/sources/HeuristicLab.Persistence/3.3/Core/TypeMapping.cs

    r1542 r1566  
    66    public readonly int Id;
    77    public readonly string TypeName;
    8     public readonly string Serializer;   
     8    public readonly string Serializer;
    99    public TypeMapping(int id, string typeName, string serializer) {
    1010      Id = id;
     
    1616        {"id", Id},
    1717        {"typeName", TypeName},
    18         {"serializer", Serializer}};                                           
     18        {"serializer", Serializer}};
    1919    }
    20   } 
     20  }
    2121
    2222}
  • trunk/sources/HeuristicLab.Persistence/3.3/Core/TypeStringBuilder.cs

    r1555 r1566  
    77
    88    internal static void BuildDeclaringTypeChain(Type type, StringBuilder sb) {
    9       if ( type.DeclaringType != null ) {
     9      if (type.DeclaringType != null) {
    1010        BuildDeclaringTypeChain(type.DeclaringType, sb);
    1111        sb.Append(type.DeclaringType.Name).Append('+');
     
    2020        sb.Append("[");
    2121        Type[] args = type.GetGenericArguments();
    22         for ( int i = 0; i<args.Length; i++ ) {
     22        for (int i = 0; i < args.Length; i++) {
    2323          sb.Append("[");
    2424          BuildVersionInvariantName(args[i], sb);
     
    2828          sb.Remove(sb.Length - 1, 1);
    2929        sb.Append("]");
    30       }           
     30      }
    3131      sb.Append(", ").Append(type.Assembly.GetName().Name);
    3232    }
    3333
    3434  }
    35  
     35
    3636}
Note: See TracChangeset for help on using the changeset viewer.