PageRenderTime 30ms CodeModel.GetById 15ms app.highlight 11ms RepoModel.GetById 1ms app.codeStats 0ms

/ICSharpCode.Decompiler/Tests/ValueTypes.cs

http://github.com/icsharpcode/ILSpy
C# | 188 lines | 139 code | 31 blank | 18 comment | 5 complexity | 5348510929248c613e20912d2d018caa MD5 | raw file
  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
 19using System;
 20
 21public static class ValueTypes
 22{
 23	public struct S
 24	{
 25		public int Field;
 26		
 27		public S(int field)
 28		{
 29			this.Field = field;
 30		}
 31		
 32		public void SetField()
 33		{
 34			this.Field = 5;
 35		}
 36		
 37		public void MethodCalls()
 38		{
 39			this.SetField();
 40			ValueTypes.S.Test(this);
 41			ValueTypes.S.Test(ref this);
 42		}
 43		
 44		private static void Test(ValueTypes.S byVal)
 45		{
 46		}
 47		
 48		private static void Test(ref ValueTypes.S byRef)
 49		{
 50		}
 51	}
 52	
 53	private static readonly ValueTypes.S ReadOnlyS = default(ValueTypes.S);
 54	private static ValueTypes.S MutableS = default(ValueTypes.S);
 55	private static volatile int VolatileInt;
 56	
 57	public static void CallMethodViaField()
 58	{
 59		ValueTypes.ReadOnlyS.SetField();
 60		ValueTypes.MutableS.SetField();
 61		ValueTypes.S mutableS = ValueTypes.MutableS;
 62		mutableS.SetField();
 63	}
 64	
 65	public static ValueTypes.S InitObj1()
 66	{
 67		ValueTypes.S result = default(ValueTypes.S);
 68		ValueTypes.MakeArray();
 69		return result;
 70	}
 71	
 72	public static ValueTypes.S InitObj2()
 73	{
 74		return default(ValueTypes.S);
 75	}
 76	
 77	public static void InitObj3(out ValueTypes.S p)
 78	{
 79		p = default(ValueTypes.S);
 80	}
 81	
 82	public static ValueTypes.S CallValueTypeCtor1()
 83	{
 84		return new ValueTypes.S(10);
 85	}
 86	
 87	public static ValueTypes.S CallValueTypeCtor2()
 88	{
 89		ValueTypes.S result = new ValueTypes.S(10);
 90		return result;
 91	}
 92	
 93	public static ValueTypes.S Copy1(ValueTypes.S p)
 94	{
 95		return p;
 96	}
 97	
 98	public static ValueTypes.S Copy2(ref ValueTypes.S p)
 99	{
100		return p;
101	}
102	
103	public static void Copy3(ValueTypes.S p, out ValueTypes.S o)
104	{
105		o = p;
106	}
107	
108	public static void Copy4(ref ValueTypes.S p, out ValueTypes.S o)
109	{
110		o = p;
111	}
112	
113	public static void Copy4b(ref ValueTypes.S p, out ValueTypes.S o)
114	{
115		// test passing through by-ref arguments
116		ValueTypes.Copy4(ref p, out o);
117	}
118	
119	public static void Issue56(int i, out string str)
120	{
121		str = "qq";
122		str += i.ToString();
123	}
124	
125	public static void CopyAroundAndModifyField(ValueTypes.S s)
126	{
127		ValueTypes.S s2 = s;
128		s2.Field += 10;
129		s = s2;
130	}
131	
132	private static int[] MakeArray()
133	{
134		return null;
135	}
136	
137	public static void IncrementArrayLocation()
138	{
139		ValueTypes.MakeArray()[Environment.TickCount]++;
140	}
141	
142	public static bool Is(object obj)
143	{
144		return obj is ValueTypes.S;
145	}
146	
147	public static bool IsNullable(object obj)
148	{
149		return obj is ValueTypes.S?;
150	}
151	
152	public static ValueTypes.S? As(object obj)
153	{
154		return obj as ValueTypes.S?;
155	}
156	
157	public static ValueTypes.S OnlyChangeTheCopy(ValueTypes.S p)
158	{
159		ValueTypes.S s = p;
160		s.SetField();
161		return p;
162	}
163	
164	public static void UseRefBoolInCondition(ref bool x)
165	{
166		if (x) 
167		{
168			Console.WriteLine("true");
169		}
170	}
171
172	public static void CompareNotEqual0IsReallyNotEqual(IComparable<int> a)
173	{
174		if (a.CompareTo(0) != 0)
175		{
176			Console.WriteLine("true");
177		}
178	}
179
180	public static void CompareEqual0IsReallyEqual(IComparable<int> a)
181	{
182		if (a.CompareTo(0) == 0)
183		{
184			Console.WriteLine("true");
185		}
186	}
187
188}