~ubuntu-branches/ubuntu/trusty/monodevelop/trusty-proposed

« back to all changes in this revision

Viewing changes to contrib/ICSharpCode.NRefactory/TypeSystem/Implementation/DefaultParameter.cs

  • Committer: Package Import Robot
  • Author(s): Jo Shields
  • Date: 2013-05-12 09:46:03 UTC
  • mto: This revision was merged to the branch mainline in revision 29.
  • Revision ID: package-import@ubuntu.com-20130512094603-mad323bzcxvmcam0
Tags: upstream-4.0.5+dfsg
Import upstream version 4.0.5+dfsg

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team
2
 
// 
3
 
// Permission is hereby granted, free of charge, to any person obtaining a copy of this
4
 
// software and associated documentation files (the "Software"), to deal in the Software
5
 
// without restriction, including without limitation the rights to use, copy, modify, merge,
6
 
// publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
7
 
// to whom the Software is furnished to do so, subject to the following conditions:
8
 
// 
9
 
// The above copyright notice and this permission notice shall be included in all copies or
10
 
// substantial portions of the Software.
11
 
// 
12
 
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
13
 
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
14
 
// PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
15
 
// FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
16
 
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
17
 
// DEALINGS IN THE SOFTWARE.
18
 
 
19
 
using System;
20
 
using System.Collections.Generic;
21
 
using System.Text;
22
 
 
23
 
namespace ICSharpCode.NRefactory.TypeSystem.Implementation
24
 
{
25
 
        /// <summary>
26
 
        /// Default implementation of <see cref="IParameter"/>.
27
 
        /// </summary>
28
 
        public sealed class DefaultParameter : IParameter
29
 
        {
30
 
                readonly IType type;
31
 
                readonly string name;
32
 
                readonly DomRegion region;
33
 
                readonly IList<IAttribute> attributes;
34
 
                readonly bool isRef, isOut, isParams, isOptional;
35
 
                readonly object defaultValue;
36
 
                
37
 
                public DefaultParameter(IType type, string name)
38
 
                {
39
 
                        if (type == null)
40
 
                                throw new ArgumentNullException("type");
41
 
                        if (name == null)
42
 
                                throw new ArgumentNullException("name");
43
 
                        this.type = type;
44
 
                        this.name = name;
45
 
                }
46
 
                
47
 
                public DefaultParameter(IType type, string name, DomRegion region = default(DomRegion), IList<IAttribute> attributes = null,
48
 
                                        bool isRef = false, bool isOut = false, bool isParams = false, bool isOptional = false, object defaultValue = null)
49
 
                {
50
 
                        if (type == null)
51
 
                                throw new ArgumentNullException("type");
52
 
                        if (name == null)
53
 
                                throw new ArgumentNullException("name");
54
 
                        this.type = type;
55
 
                        this.name = name;
56
 
                        this.region = region;
57
 
                        this.attributes = attributes;
58
 
                        this.isRef = isRef;
59
 
                        this.isOut = isOut;
60
 
                        this.isParams = isParams;
61
 
                        this.isOptional = isOptional;
62
 
                        this.defaultValue = defaultValue;
63
 
                }
64
 
                
65
 
                public IList<IAttribute> Attributes {
66
 
                        get { return attributes; }
67
 
                }
68
 
                
69
 
                public bool IsRef {
70
 
                        get { return isRef; }
71
 
                }
72
 
                
73
 
                public bool IsOut {
74
 
                        get { return isOut; }
75
 
                }
76
 
                
77
 
                public bool IsParams {
78
 
                        get { return isParams; }
79
 
                }
80
 
                
81
 
                public bool IsOptional {
82
 
                        get { return isOptional; }
83
 
                }
84
 
                
85
 
                public string Name {
86
 
                        get { return name; }
87
 
                }
88
 
                
89
 
                public DomRegion Region {
90
 
                        get { return region; }
91
 
                }
92
 
                
93
 
                public IType Type {
94
 
                        get { return type; }
95
 
                }
96
 
                
97
 
                bool IVariable.IsConst {
98
 
                        get { return false; }
99
 
                }
100
 
                
101
 
                public object ConstantValue {
102
 
                        get { return defaultValue; }
103
 
                }
104
 
                
105
 
                public override string ToString()
106
 
                {
107
 
                        return ToString(this);
108
 
                }
109
 
                
110
 
                public static string ToString(IParameter parameter)
111
 
                {
112
 
                        StringBuilder b = new StringBuilder();
113
 
                        if (parameter.IsRef)
114
 
                                b.Append("ref ");
115
 
                        if (parameter.IsOut)
116
 
                                b.Append("out ");
117
 
                        if (parameter.IsParams)
118
 
                                b.Append("params ");
119
 
                        b.Append(parameter.Name);
120
 
                        b.Append(':');
121
 
                        b.Append(parameter.Type.ReflectionName);
122
 
                        if (parameter.IsOptional) {
123
 
                                b.Append(" = ");
124
 
                                if (parameter.ConstantValue != null)
125
 
                                        b.Append(parameter.ConstantValue.ToString());
126
 
                                else
127
 
                                        b.Append("null");
128
 
                        }
129
 
                        return b.ToString();
130
 
                }
131
 
        }
132
 
}