~ubuntu-branches/ubuntu/feisty/monodevelop/feisty

« back to all changes in this revision

Viewing changes to Core/src/MonoDevelop.Projects/MonoDevelop.Projects.Parser/PersistentGenericParamater.cs

  • Committer: Bazaar Package Importer
  • Author(s): Sebastian Dröge
  • Date: 2006-08-18 00:51:23 UTC
  • mfrom: (1.1.3 upstream)
  • Revision ID: james.westby@ubuntu.com-20060818005123-5iit07y0j7wjg55f
Tags: 0.11+svn20060818-0ubuntu1
* New SVN snapshot
  + Works with Gtk# 2.9.0
* debian/control:
  + Updated Build-Depends
* debian/patches/use_nunit2.2.dpatch,
  debian/patches/use_real_libs.dpatch:
  + Updated
* debian/patches/versioncontrol_buildfix.dpatch:
  + Fix build failure in the version control addin

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
//
 
2
// PersistentGenericParamater.cs: A utility class that handles serialization of
 
3
//                                generic parameters.
 
4
//
 
5
// Author:
 
6
//   Matej Urbas (matej.urbas@gmail.com)
 
7
//
 
8
// (C) 2006 Matej Urbas
 
9
//
 
10
//
 
11
// This source code is licenced under The MIT License:
 
12
//
 
13
// Permission is hereby granted, free of charge, to any person obtaining
 
14
// a copy of this software and associated documentation files (the
 
15
// "Software"), to deal in the Software without restriction, including
 
16
// without limitation the rights to use, copy, modify, merge, publish,
 
17
// distribute, sublicense, and/or sell copies of the Software, and to
 
18
// permit persons to whom the Software is furnished to do so, subject to
 
19
// the following conditions:
 
20
//
 
21
// The above copyright notice and this permission notice shall be
 
22
// included in all copies or substantial portions of the Software.
 
23
//
 
24
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
 
25
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
 
26
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
 
27
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
 
28
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
 
29
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
 
30
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 
31
//
 
32
 
 
33
using System;
 
34
using System.IO;
 
35
using System.Reflection;
 
36
 
 
37
namespace MonoDevelop.Projects.Parser
 
38
{
 
39
        internal sealed class PersistentGenericParamater
 
40
        {
 
41
                private PersistentGenericParamater()
 
42
                {
 
43
                }
 
44
                
 
45
                public static GenericParameter Resolve(GenericParameter gp,
 
46
                                                       ITypeResolver typeResolver)
 
47
                {
 
48
                        GenericParameter tmp = new GenericParameter();
 
49
                        tmp.Name = gp.Name;
 
50
                        tmp.SpecialConstraints = gp.SpecialConstraints;
 
51
                        if (gp.BaseTypes != null && gp.BaseTypes.Count > 0) {
 
52
                                tmp.BaseTypes = new ReturnTypeList();
 
53
                                foreach (IReturnType rt in gp.BaseTypes) {
 
54
                                        tmp.BaseTypes.Add(PersistentReturnType.Resolve(rt, typeResolver));
 
55
                                }
 
56
                        }
 
57
                        
 
58
                        return tmp;
 
59
                }
 
60
                
 
61
                public static GenericParameter Read (BinaryReader reader, INameDecoder nameTable)
 
62
                {
 
63
                        GenericParameter gp = new GenericParameter();
 
64
                        gp.Name = PersistentHelper.ReadString(reader, nameTable);
 
65
                        gp.SpecialConstraints = (GenericParameterAttributes) reader.ReadInt16();
 
66
                        uint count = reader.ReadUInt32();
 
67
                        if (count > 0) {
 
68
                                gp.BaseTypes = new ReturnTypeList();
 
69
                                for (uint j = 0; j < count; ++j) {
 
70
                                        gp.BaseTypes.Add(PersistentReturnType.Read(reader, nameTable));
 
71
                                }
 
72
                        }
 
73
                        return gp;
 
74
                }
 
75
 
 
76
                public static void WriteTo (GenericParameter gp, BinaryWriter writer, INameEncoder nameTable)
 
77
                {
 
78
                        PersistentHelper.WriteString(gp.Name, writer, nameTable);
 
79
                        writer.Write((short)gp.SpecialConstraints);
 
80
                        if (gp.BaseTypes == null)
 
81
                                writer.Write((uint)0);
 
82
                        else {
 
83
                                writer.Write((uint)gp.BaseTypes.Count);
 
84
                                foreach (IReturnType rt in gp.BaseTypes) {
 
85
                                        PersistentReturnType.WriteTo(rt, writer, nameTable);
 
86
                                }
 
87
                        }
 
88
                }
 
89
        }
 
90
}