/Project/Test/Tests.StyleCop.CSharp.Rules/TestData/BuiltInTypes/InvalidBuiltInTypes.cs

https://github.com/StyleCop/StyleCop · C# · 343 lines · 244 code · 85 blank · 14 comment · 2 complexity · cbd32443adf34bdf114ad4f23d17cfa0 MD5 · raw file

  1. using System;
  2. using System.Collections.Generic;
  3. namespace InvalidBuildInTypes
  4. {
  5. #region The base class of a class or interface.
  6. public class Class1 : List<Boolean>
  7. {
  8. }
  9. public interface Interface1 : IList<System.Boolean>
  10. {
  11. }
  12. #endregion
  13. #region Implemented interfaces on a class or interface
  14. public class Class2 : Class1, IList<Object>
  15. {
  16. }
  17. public interface Interface2 : Interface1, IList<System.Object>
  18. {
  19. }
  20. #endregion
  21. #region Type constraint clauses on a class, interface, struct, method, or delegate
  22. public class Class3<T, S>
  23. where T : string
  24. where S : List<List<String>>
  25. {
  26. }
  27. public interface Interface3<T, S>
  28. where T : String
  29. where S : List<List<string>>
  30. {
  31. }
  32. public struct Struct3<T, S>
  33. where T : string
  34. where S : List<List<System.String>>
  35. {
  36. }
  37. public delegate void Delegate1<T, S>(T x)
  38. where T : Int16
  39. where S : List<List<short>>;
  40. public delegate void Delegate2<T, S>(T x)
  41. where T : short
  42. where S : List<List<Int16>>;
  43. public delegate void Delegate3<T, S>(T x)
  44. where T : short
  45. where S : List<List<System.Int16>>;
  46. public class Class3b
  47. {
  48. public void Method1<T, S>(T x)
  49. where T : uint
  50. where S : List<List<UInt16>>
  51. {
  52. }
  53. public void Method2<T, S>(T x)
  54. where T : UInt16
  55. where S : List<List<uint>>
  56. {
  57. }
  58. public void Method3<T, S>(T x)
  59. where T : uint
  60. where S : List<List<System.UInt16>>
  61. {
  62. }
  63. }
  64. #endregion
  65. #region Parameter list on method, indexer, constructor, or delegate
  66. public class Class4
  67. {
  68. public void Method1(Int32 x, Dictionary<int, List<List<bool>>> y)
  69. {
  70. }
  71. public void Method2(int x, Dictionary<int, List<List<Int32>>> y)
  72. {
  73. }
  74. public void Method3(int x, Dictionary<System.Int32, List<List<int>>> y)
  75. {
  76. }
  77. public void Method4(UInt32 x, Dictionary<uint, List<List<uint>>> y)
  78. {
  79. }
  80. public void Method5(uint x, Dictionary<uint, List<List<UInt32>>> y)
  81. {
  82. }
  83. public void Method6(uint x, Dictionary<System.UInt32, List<List<uint>>> y)
  84. {
  85. }
  86. public int this[Int64 x, Dictionary<long, List<List<long>>> y]
  87. {
  88. get { return 2; }
  89. }
  90. public int this[long x, Dictionary<Int64, List<List<long>>> y]
  91. {
  92. get { return 2; }
  93. }
  94. public int this[long x, Dictionary<long, List<List<System.Int64>>> y]
  95. {
  96. get { return 2; }
  97. }
  98. public int this[UInt64 x, Dictionary<ulong, List<List<ulong>>> y]
  99. {
  100. get { return 2; }
  101. }
  102. public int this[ulong x, Dictionary<UInt64, List<List<ulong>>> y]
  103. {
  104. get { return 2; }
  105. }
  106. public int this[ulong x, Dictionary<ulong, List<List<System.UInt64>>> y]
  107. {
  108. get { return 2; }
  109. }
  110. public Class4(double x, Dictionary<double, List<List<Double>>> y)
  111. {
  112. }
  113. public Class4(Double x, Dictionary<double, List<List<double>>> y)
  114. {
  115. }
  116. public Class4(double x, Dictionary<System.Double, List<List<double>>> y)
  117. {
  118. }
  119. public delegate void Delegate4(float x, Dictionary<Single, List<List<float>>> y);
  120. public delegate void Delegate5(float x, Dictionary<float, List<List<Single>>> y);
  121. public delegate void Delegate6(System.Single x, Dictionary<float, List<List<float>>> y);
  122. }
  123. #endregion
  124. #region Parameter list on anonymous method and lambda expression
  125. public class Class10
  126. {
  127. public void Method1()
  128. {
  129. CallMethod(delegate(Byte x, byte y)
  130. {
  131. System.Byte z = 2;
  132. });
  133. CallMethod2((sbyte x, SByte y) => { System.SByte z = 2; });
  134. }
  135. }
  136. #endregion
  137. #region Return type on method, indexer, property, delegate, or event
  138. public class Class5
  139. {
  140. public Dictionary<char, List<List<System.Char>>> Method5()
  141. {
  142. }
  143. public Dictionary<Char, List<List<char>>> this[char x]
  144. {
  145. get { return null; }
  146. }
  147. public Dictionary<System.Decimal, List<List<decimal>>> Property5
  148. {
  149. get { return null; }
  150. }
  151. public delegate Dictionary<decimal, List<List<Decimal>>> Delegate5();
  152. public event EventHandler<Dictionary<Object, List<List<object>>>> Event5;
  153. }
  154. #endregion
  155. #region Type of Field
  156. public class Class6
  157. {
  158. private Boolean field1;
  159. private System.Char field2;
  160. private const Byte field3 = 0;
  161. private const System.Int32 field4 = null;
  162. private readonly UInt64 field5;
  163. private readonly String field6;
  164. }
  165. #endregion
  166. #region Generic types on class, interface, struct, method, or delegate
  167. public class Class7
  168. {
  169. public void Method1()
  170. {
  171. object x = new Dictionary<string, Dictionary<List<String>, string>, string>();
  172. object y = (IList<Dictionary<string, Dictionary<List<string>, String>>, string>)x;
  173. CallSomeMethod<Dictionary<String, Dictionary<List<string>, string>>, string>();
  174. }
  175. }
  176. #endregion
  177. #region Statements
  178. public class Class9
  179. {
  180. public void Method1()
  181. {
  182. // for statement
  183. for (Int64 x = 0; x < 1; ++x)
  184. {
  185. }
  186. // foreach statement
  187. foreach (Object o in Something())
  188. {
  189. }
  190. // try-catch
  191. try
  192. {
  193. }
  194. catch (SomeException<Object> e)
  195. {
  196. }
  197. // Fixed statement
  198. fixed (Int32 x = 0)
  199. {
  200. }
  201. // throw new
  202. throw new SomeException<System.Char>();
  203. // using statement
  204. using (System.Object o = null)
  205. {
  206. }
  207. // new allocation
  208. Dictionary<List<bool>, string> dict = new Dictionary<List<Boolean>, string>();
  209. // new array
  210. string[] array = new String[3];
  211. }
  212. }
  213. #endregion Statements
  214. #region Expressions
  215. public class Class11
  216. {
  217. public void Method1()
  218. {
  219. // As expression
  220. Object z = null;
  221. object x = z as List<List<String>>;
  222. // Is expression
  223. bool t = z is List<List<String>>;
  224. // Cast expression
  225. System.Object a = null;
  226. object b = (String)a;
  227. // Default value
  228. object c = default(Byte);
  229. // Sizeof
  230. int d = sizeof(Object);
  231. // Typeof
  232. Type e = typeof(Char);
  233. }
  234. }
  235. #endregion
  236. #region Query Expressions
  237. public class Class12
  238. {
  239. public void Method1()
  240. {
  241. Object a;
  242. from System.String s in a where s.Length == 2 select s.Length;
  243. }
  244. }
  245. #endregion
  246. #region Method Access Expressions
  247. public class Class13
  248. {
  249. public void Method1()
  250. {
  251. var a = String.Format("");
  252. var b = System.String.Format("");
  253. object o = Object.Equals(a, b);
  254. object o = System.Object.Equals(a, b);
  255. }
  256. }
  257. #endregion
  258. }