Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
03/13/09 10:34:57 (16 years ago)
Author:
epitzer
Message:

split off test case, format empty variable names, include assembly names (#506)

Location:
branches/New Persistence Exploration/Persistence
Files:
5 added
6 edited

Legend:

Unmodified
Added
Removed
  • branches/New Persistence Exploration/Persistence/Persistence.sln

    r1332 r1338  
    33# Visual Studio 2008
    44Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Persistence", "Persistence\Persistence.csproj", "{102BC7D3-0EF9-439C-8F6D-96FF0FDB8E1B}"
     5EndProject
     6Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Test", "Test\Test.csproj", "{E2245078-6F40-449E-A370-01A97A7C5E6A}"
    57EndProject
    68Global
     
    1820    {102BC7D3-0EF9-439C-8F6D-96FF0FDB8E1B}.Release|Any CPU.Build.0 = Release|Any CPU
    1921    {102BC7D3-0EF9-439C-8F6D-96FF0FDB8E1B}.Release|x86.ActiveCfg = Release|Any CPU
     22    {E2245078-6F40-449E-A370-01A97A7C5E6A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
     23    {E2245078-6F40-449E-A370-01A97A7C5E6A}.Debug|Any CPU.Build.0 = Debug|Any CPU
     24    {E2245078-6F40-449E-A370-01A97A7C5E6A}.Debug|x86.ActiveCfg = Debug|Any CPU
     25    {E2245078-6F40-449E-A370-01A97A7C5E6A}.Release|Any CPU.ActiveCfg = Release|Any CPU
     26    {E2245078-6F40-449E-A370-01A97A7C5E6A}.Release|Any CPU.Build.0 = Release|Any CPU
     27    {E2245078-6F40-449E-A370-01A97A7C5E6A}.Release|x86.ActiveCfg = Release|Any CPU
    2028  EndGlobalSection
    2129  GlobalSection(SolutionProperties) = preSolution
  • branches/New Persistence Exploration/Persistence/Persistence/Persistence.csproj

    r1329 r1338  
    77    <SchemaVersion>2.0</SchemaVersion>
    88    <ProjectGuid>{102BC7D3-0EF9-439C-8F6D-96FF0FDB8E1B}</ProjectGuid>
    9     <OutputType>Exe</OutputType>
     9    <OutputType>Library</OutputType>
    1010    <AppDesignerFolder>Properties</AppDesignerFolder>
    1111    <RootNamespace>Persistence</RootNamespace>
     
    1313    <TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
    1414    <FileAlignment>512</FileAlignment>
    15     <StartupObject>Persistence.Test.NewSerializationTest</StartupObject>
     15    <StartupObject>
     16    </StartupObject>
    1617  </PropertyGroup>
    1718  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
     
    5354  <ItemGroup>
    5455    <Compile Include="DeSerializer.cs" />
     56    <Compile Include="Properties\AssemblyInfo.cs" />
    5557    <Compile Include="Serializer.cs" />
    5658    <Compile Include="CompoundSerializers.cs" />
    5759    <Compile Include="PrimitiveSerializers.cs" />
     60    <Compile Include="Test\NewSerializationTest.cs" />
    5861    <Compile Include="Tokens.cs" />
    5962    <Compile Include="Util.cs" />
    6063    <Compile Include="Test\StorableAttributeTests.cs" />
    6164    <Compile Include="StorableAttribute.cs" />
    62     <Compile Include="Test\NewSerializationTest.cs" />
    6365    <Compile Include="Test\SerializationTest.cs" />
    6466    <Compile Include="XmlFormatter.cs" />
    6567    <Compile Include="XmlParser.cs" />
    6668  </ItemGroup>
     69  <PropertyGroup>
     70    <PreBuildEvent>SubWCRev "$(ProjectDir)\" "$(ProjectDir)\Properties\AssemblyInfo.frame" "$(ProjectDir)\Properties\AssemblyInfo.cs"</PreBuildEvent>
     71  </PropertyGroup>
    6772  <ItemGroup>
    6873    <Folder Include="Interfaces\" />
  • branches/New Persistence Exploration/Persistence/Persistence/StorableAttribute.cs

    r1332 r1338  
    5151  }
    5252
    53   class CloningFactory {
     53  public class CloningFactory {
    5454
    5555    private static readonly CloningFactory instance = new CloningFactory();
     
    208208      }
    209209    }
    210   }
    211  
    212   public interface IDataMemberAccessor {
    213     string Name { get; }
    214     Type Type { get; }
    215     object DefaultValue { get; }
    216     object Get();
    217     void Set(object value);   
    218   }
     210  } 
    219211   
    220   public class DataMemberAccessor : IDataMemberAccessor {
     212  public class DataMemberAccessor {
    221213
    222214    public delegate object Getter();
    223215    public delegate void Setter(object value);
    224216
    225     private readonly Getter getter;
    226     private readonly Setter setter;
     217    public readonly Getter Get;
     218    public readonly Setter Set;
     219    public readonly string Name;
     220    public readonly Type Type;
     221    public readonly object DefaultValue;
    227222
    228223    public DataMemberAccessor(
     
    232227      if (memberInfo.MemberType == MemberTypes.Field) {
    233228        FieldInfo fieldInfo = (FieldInfo)memberInfo;
    234         getter = () => fieldInfo.GetValue(obj);
    235         setter = value => fieldInfo.SetValue(obj, value);
     229        Get = () => fieldInfo.GetValue(obj);
     230        Set = value => fieldInfo.SetValue(obj, value);
    236231        Type = fieldInfo.FieldType;
    237232      } else if (memberInfo.MemberType == MemberTypes.Property) {
     
    241236            "Storable properties must implement both a Get and a Set Accessor. ");
    242237        }
    243         getter = () => propertyInfo.GetValue(obj, null);
    244         setter = value => propertyInfo.SetValue(obj, value, null);
     238        Get = () => propertyInfo.GetValue(obj, null);
     239        Set = value => propertyInfo.SetValue(obj, value, null);
    245240        Type = propertyInfo.PropertyType;
    246241      } else {
     
    258253      Type = type;
    259254      DefaultValue = defaultValue;
    260       this.getter = getter;
    261       this.setter = setter;
     255      Get = getter;
     256      Set = setter;
    262257    }
    263258
    264259    public DataMemberAccessor(object o) {     
     260      Name = null;
    265261      Type = o.GetType();
    266262      DefaultValue = null;
    267       getter = () => o;
    268       setter = null;
    269     }
    270 
    271     public string Name { get; private set; }
    272     public Type Type { get; private set; }
    273     public object DefaultValue { get; private set; }
    274     public object Get() {
    275       return getter();
    276     }
    277     public void Set(object value) {
    278       setter(value);
    279     }
     263      Get = () => o;
     264      Set = null;
     265    }       
    280266    public override string ToString() {
    281267      return String.Format("DataMember({0}, {1}, {2}, {3}, {4}",
     
    283269        Type == null ? "<null>" : Type.FullName,
    284270        DefaultValue ?? "<null>",
    285         getter.Method,
    286         setter.Method);
     271        Get.Method,
     272        Set.Method);
    287273    }
    288274  }
  • branches/New Persistence Exploration/Persistence/Persistence/Test/NewSerializationTest.cs

    r1336 r1338  
    141141    }
    142142  } 
    143 
    144   public class NewSerializationTest {
    145 
    146     public static void Test1() {
    147       Root r = new Root();
    148       r.selfReferences = new List<Root> {r, r};
    149       r.c = new Custom {r = r};
    150       r.dict.Add("one", 1);
    151       r.dict.Add("two", 2);
    152       r.dict.Add("three", 3);
    153       Serializer s = new Serializer(r);       
    154       Persistence.XmlFormatter xmlFormatter = new XmlFormatter();
    155       //StreamWriter writer = new StreamWriter("test.xml");
    156       foreach (ISerializationToken token in s) {
    157         string line = xmlFormatter.Format(token);
    158         //writer.Write(line);
    159         Console.Out.Write(line);
    160       }
    161       //writer.Close();
    162       XmlParser parser = new XmlParser(new StreamReader("test.xml"));
    163       DeSerializer deSerializer = new DeSerializer();       
    164       object o = deSerializer.DeSerialize(parser);
    165       Root t = CloningFactory.DefaultClone(r);
    166       Console.Out.WriteLine(Util.AutoFormat(o, true));     
    167     }
    168 
    169     public static void Test2() {
    170       Manager m = new Manager();     
    171       Serializer s = new Serializer(m);
    172       Persistence.XmlFormatter xmlFormatter = new XmlFormatter();
    173       StreamWriter writer = new StreamWriter("test2.xml");
    174       foreach (ISerializationToken token in s) {
    175         string line = xmlFormatter.Format(token);
    176         writer.Write(line);
    177         Console.Out.Write(line);
    178       }
    179       writer.Close();
    180       XmlParser parser = new XmlParser(new StreamReader("test2.xml"));
    181       DeSerializer deSerializer = new DeSerializer();
    182       object o = deSerializer.DeSerialize(parser);
    183       Manager n = CloningFactory.DefaultClone(m);
    184       Console.Out.WriteLine(Util.AutoFormat(o, true));     
    185     }
    186 
    187     public static void SpeedTest() {
    188       StorableObject storable = new StorableObject();
    189       CloneableObject cloneable = new CloneableObject();
    190       Console.Write("initializing...");
    191       storable.Init();
    192       cloneable.Init();
    193       Console.WriteLine("done");
    194       List<StorableObject> storableClones = new List<StorableObject>();
    195       List<CloneableObject> clonableClones = new List<CloneableObject>();
    196       CloningFactory cloningFactory = new CloningFactory();
    197       for (int i = 0; i < 100000; i++) {
    198         Console.Write("cloning storable.. ");
    199         storableClones.Add(cloningFactory.Clone(storable));
    200         Console.WriteLine();
    201         Console.Write("cloning cloneable.. ");
    202         clonableClones.Add((CloneableObject)cloneable.Clone());
    203         Console.WriteLine();
    204       }
    205     }
    206 
    207     public static void SpeedTest2() {
    208       Root r = new Root();
    209       r.selfReferences = new List<Root> {r, r};
    210       r.c = new Custom {r = r};
    211       r.dict.Add("one", 1);
    212       r.dict.Add("two", 2);
    213       r.dict.Add("three", 3);
    214 
    215       CloneableRoot cr = new CloneableRoot();
    216       cr.selfReferences = new List<CloneableRoot> {cr, cr};
    217       cr.c = new CloneableCustom {r = cr};
    218       cr.dict.Add("one", 1);
    219       cr.dict.Add("two", 2);
    220       cr.dict.Add("three", 3);     
    221       List<Root> storableClones = new List<Root>();
    222       List<CloneableRoot> clonableClones = new List<CloneableRoot>();     
    223       CloningFactory cloningFactory = new CloningFactory();
    224 
    225       DateTime start = DateTime.Now;
    226       Console.Write("cloning storable.. ");
    227       for (int i = 0; i < 100000; i++) {       
    228         storableClones.Add(cloningFactory.Clone(r));                       
    229       }
    230       Console.WriteLine(new TimeSpan(DateTime.Now.Ticks - start.Ticks));
    231 
    232       start = DateTime.Now;
    233       Console.Write("cloning storable again.. ");
    234       for (int i = 0; i < 100000; i++) {
    235         storableClones.Add(cloningFactory.Clone(r));
    236       }
    237       Console.WriteLine(new TimeSpan(DateTime.Now.Ticks - start.Ticks));
    238 
    239       start = DateTime.Now;
    240       Console.Write("cloning cloneable.. ");
    241       for (int i = 0; i < 100000; i++) {       
    242         clonableClones.Add((CloneableRoot)cr.Clone(new Dictionary<object, object>()));
    243       }
    244       Console.WriteLine(new TimeSpan(DateTime.Now.Ticks - start.Ticks));
    245       clonableClones.Clear();
    246      
    247     }
    248 
    249     public class Base {
    250       [Storable] private int baseInt = 3;     
    251     }
    252 
    253     public class Derived: Base {
    254       [Storable] private int derivedInt = 5;
    255     }
    256 
    257     public static void Main() {
    258       int[] i = {1, 2, 3};
    259       object o = i;
    260       Type type = o.GetType().BaseType.BaseType;
    261       foreach (MemberInfo mi in type.GetMembers(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic )) {
    262         if ( mi.MemberType == MemberTypes.Field || mi.MemberType == MemberTypes.Property )
    263           Console.WriteLine(mi.Name);
    264       }
    265       Test1();
    266       //Test2();
    267       //SpeedTest();
    268       //SpeedTest2();
    269       Console.In.ReadLine();
    270     }
    271   }
    272143}
  • branches/New Persistence Exploration/Persistence/Persistence/XmlFormatter.cs

    r1330 r1338  
    5151    }
    5252
    53     private string FormatBegin(ISerializationToken token) {
     53    private string FormatBegin(ISerializationToken token) {     
    5454      BeginToken beginToken = (BeginToken)token;
    5555      string result = Prefix +
     
    5858                                   {
    5959                                     {"name", beginToken.Accessor.Name},
    60                                      {"type", beginToken.Accessor.Get().GetType().ToString()},
     60                                     {"type", beginToken.Accessor.Get().GetType().AssemblyQualifiedName},
    6161                                     {"id", beginToken.Id.ToString()}
    6262                                   }, NodeType.Start) + "\n";
     
    7474      Dictionary<string, string> attributes =
    7575        new Dictionary<string, string> {
    76             {"type", dataToken.Accessor.Get().GetType().ToString()}};
    77       if ( dataToken.Accessor.Name != "" )
     76            {"type", dataToken.Accessor.Get().GetType().AssemblyQualifiedName}};
     77      if ( !string.IsNullOrEmpty(dataToken.Accessor.Name) )
    7878        attributes.Add("name", dataToken.Accessor.Name);
    7979      if ( dataToken.Id != null )
  • branches/New Persistence Exploration/Persistence/Persistence/XmlParser.cs

    r1330 r1338  
    5757    }
    5858    private IEnumerator<IParseToken> ParseComposite() {
    59       string name = reader.GetAttribute("name");
     59      string name = reader.GetAttribute("name");     
    6060      Type type = Type.GetType(reader.GetAttribute("type"));
    6161      int id = int.Parse(reader.GetAttribute("id"));
Note: See TracChangeset for help on using the changeset viewer.