stub out things to get the beatles xbox site up and running
[moon.git] / class / System.Windows / System.Windows.Media.Animation / RepeatBehavior.cs
blob16da004043ba6dda44688b180dbd49eb3953eba6
1 //
2 // RepeatBehavior.cs
3 //
4 // Contact:
5 // Moonlight List (moonlight-list@lists.ximian.com)
6 //
7 // Copyright 2007, 2009 Novell, Inc.
8 //
9 // Permission is hereby granted, free of charge, to any person obtaining
10 // a copy of this software and associated documentation files (the
11 // "Software"), to deal in the Software without restriction, including
12 // without limitation the rights to use, copy, modify, merge, publish,
13 // distribute, sublicense, and/or sell copies of the Software, and to
14 // permit persons to whom the Software is furnished to do so, subject to
15 // the following conditions:
16 //
17 // The above copyright notice and this permission notice shall be
18 // included in all copies or substantial portions of the Software.
19 //
20 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
21 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
23 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
24 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
25 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
26 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
28 namespace System.Windows.Media.Animation {
30 public struct RepeatBehavior : IFormattable {
32 // note: Count is default for the (default) empty ctor, so it needs to have a 0 value
33 enum RepeatBehaviorKind {
34 Count,
35 TimeSpan,
36 Forever
39 private RepeatBehaviorKind kind;
40 private int padding;
41 private double count;
42 private TimeSpan duration;
44 private RepeatBehavior (RepeatBehaviorKind kind, double count, TimeSpan duration)
46 this.kind = kind;
47 this.count = count;
48 this.duration = duration;
49 this.padding = 0;
52 public RepeatBehavior (double count)
54 if ((count < 0) || Double.IsNaN (count) || Double.IsInfinity (count))
55 throw new ArgumentOutOfRangeException ("count");
57 kind = RepeatBehaviorKind.Count;
58 this.count = count;
59 duration = TimeSpan.Zero;
60 padding = 0;
63 public RepeatBehavior (TimeSpan duration)
65 if (duration.Ticks < 0)
66 throw new ArgumentOutOfRangeException ("duration");
68 kind = RepeatBehaviorKind.TimeSpan;
69 this.duration = duration;
70 count = 0;
71 padding = 0;
74 public double Count {
75 get {
76 if (kind == RepeatBehaviorKind.Count)
77 return count;
78 throw new InvalidOperationException ("This RepeatBehavior does not contain a Count");
82 public TimeSpan Duration {
83 get {
84 if (kind == RepeatBehaviorKind.TimeSpan)
85 return duration;
86 throw new InvalidOperationException ("This RepeatBehavior does not contain a Duration");
90 public static RepeatBehavior Forever {
91 get { return new RepeatBehavior (RepeatBehaviorKind.Forever, 0, TimeSpan.Zero); }
95 public bool HasCount {
96 get { return kind == RepeatBehaviorKind.Count; }
99 public bool HasDuration {
100 get { return kind == RepeatBehaviorKind.TimeSpan; }
103 public override bool Equals (object value)
105 if (!(value is RepeatBehavior))
106 return false;
108 return Equals (this, (RepeatBehavior) value);
111 public bool Equals (RepeatBehavior repeatBehavior)
113 return Equals (this, repeatBehavior);
116 public static bool Equals (RepeatBehavior repeatBehavior1, RepeatBehavior repeatBehavior2)
118 if (repeatBehavior1.kind != repeatBehavior2.kind)
119 return false;
121 switch (repeatBehavior1.kind) {
122 case RepeatBehaviorKind.Count:
123 return repeatBehavior1.count == repeatBehavior2.count;
124 case RepeatBehaviorKind.TimeSpan:
125 return repeatBehavior1.duration == repeatBehavior2.duration;
126 case RepeatBehaviorKind.Forever:
127 return true;
128 default:
129 return false;
133 public static bool operator == (RepeatBehavior repeatBehavior1, RepeatBehavior repeatBehavior2)
135 return Equals (repeatBehavior1, repeatBehavior2);
138 public static bool operator != (RepeatBehavior repeatBehavior1, RepeatBehavior repeatBehavior2)
140 return !Equals (repeatBehavior1, repeatBehavior2);
143 public override int GetHashCode ()
145 switch (kind) {
146 case RepeatBehaviorKind.Count:
147 return count.GetHashCode ();
148 case RepeatBehaviorKind.TimeSpan:
149 return duration.GetHashCode ();
150 case RepeatBehaviorKind.Forever:
151 return RepeatBehaviorKind.Forever.GetHashCode ();
152 default:
153 return base.GetHashCode ();
157 public override string ToString ()
159 switch (kind) {
160 case RepeatBehaviorKind.Forever:
161 return "Forever";
162 case RepeatBehaviorKind.Count:
163 return String.Format ("{0}x", count);
164 case RepeatBehaviorKind.TimeSpan:
165 return duration.ToString ();
166 default:
167 return base.ToString ();
171 public string ToString (IFormatProvider formatProvider)
173 return (this as IFormattable).ToString (null, formatProvider);
176 string System.IFormattable.ToString (string format, IFormatProvider formatProvider)
178 if (kind != RepeatBehaviorKind.Count)
179 return ToString ();
181 if (String.IsNullOrEmpty (format))
182 format = null;
184 if (formatProvider != null) {
185 ICustomFormatter cp = (ICustomFormatter) formatProvider.GetFormat (typeof (ICustomFormatter));
186 if (cp != null) {
187 return String.Format ("{0}x", cp.Format (format, count, formatProvider));
191 return String.Format ("{0}x", count.ToString (format, formatProvider));