Changeset 1331


Ignore:
Timestamp:
03/12/09 13:49:56 (12 years ago)
Author:
epitzer
Message:

Include storable attributes of base classes. (#506)

Location:
branches/New Persistence Exploration/Persistence
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • branches/New Persistence Exploration/Persistence

    • Property svn:ignore
      •  

        old new  
        33*.suo
        44_ReSharper.Persistence
         5Persistence.4.1.resharper.user
  • branches/New Persistence Exploration/Persistence/Persistence/DeSerializer.cs

    r1330 r1331  
    44  public class DeSerializer {
    55
    6     class ParentReference {     
    7     }
     6    struct ParentReference { }
    87
    98    delegate void Setter(object value);
  • branches/New Persistence Exploration/Persistence/Persistence/StorableAttribute.cs

    r1330 r1331  
    1919      BindingFlags.Public |
    2020      BindingFlags.NonPublic;
    21 
    22 
    23     public static IEnumerable<KeyValuePair<StorableAttribute, MemberInfo>> GetStorableMembers(object obj) {
    24       foreach (MemberInfo memberInfo in obj.GetType().GetMembers(instanceMembers)) {
     21   
     22    public static IEnumerable<KeyValuePair<StorableAttribute, MemberInfo>> GetStorableMembers(Type type) {
     23      return GetStorableMembers(type, true);     
     24    }
     25
     26    public static IEnumerable<KeyValuePair<StorableAttribute, MemberInfo>>
     27        GetStorableMembers(Type type, bool inherited) {
     28      if (type.BaseType != null)
     29        foreach ( var pair in GetStorableMembers(type.BaseType) )
     30          yield return pair;
     31      foreach (MemberInfo memberInfo in type.GetMembers(instanceMembers)) {
    2532        foreach (object attribute in memberInfo.GetCustomAttributes(false)) {         
    2633          StorableAttribute storableAttribute =
     
    3643      Dictionary<string, DataMemberAccessor> storableAccessors =
    3744        new Dictionary<string, DataMemberAccessor>();
    38       foreach (KeyValuePair<StorableAttribute, MemberInfo> pair in GetStorableMembers(obj)) {
     45      foreach (KeyValuePair<StorableAttribute, MemberInfo> pair in GetStorableMembers(obj.GetType())) {
    3946        storableAccessors.Add(pair.Value.Name,
    4047          new DataMemberAccessor(pair.Value, pair.Key, obj));
  • branches/New Persistence Exploration/Persistence/Persistence/Test/NewSerializationTest.cs

    r1329 r1331  
    33using System.Collections;
    44using System.IO;
     5using System.Reflection;
    56
    67namespace Persistence.Test {
    78
    8   public class Root {
     9  public class RootBase {
     10    [Storable] private string baseString = "Serial";
     11  }
     12
     13  public class Root : RootBase {
    914    [Storable]
    1015    public int[] i = new[] { 3, 4, 5, 6 };
     
    240245    }
    241246
     247    public class Base {
     248      [Storable] private int baseInt = 3;     
     249    }
     250
     251    public class Derived: Base {
     252      [Storable] private int derivedInt = 5;
     253    }
     254
    242255    public static void Main() {
     256      int[] i = {1, 2, 3};
     257      object o = i;
     258      Type type = o.GetType().BaseType.BaseType;
     259      foreach (MemberInfo mi in type.GetMembers(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic )) {
     260        if ( mi.MemberType == MemberTypes.Field || mi.MemberType == MemberTypes.Property )
     261          Console.WriteLine(mi.Name);
     262      }
    243263      Test1();
    244264      //Test2();
Note: See TracChangeset for help on using the changeset viewer.