/ICSharpCode.Decompiler/Tests/Types/S_TypeMemberDeclarations.cs

http://github.com/icsharpcode/ILSpy · C# · 1138 lines · 1076 code · 2 blank · 60 comment · 0 complexity · b4dea34ce3a0b762a51c3830434cd757 MD5 · raw file

  1. // Copyright (c) 2014 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. //$CS
  19. using System;
  20. //$CE
  21. //$$ IndexerWithGetOnly
  22. namespace IndexerWithGetOnly
  23. {
  24. public class MyClass
  25. {
  26. public int this[int i]
  27. {
  28. get
  29. {
  30. return i;
  31. }
  32. }
  33. }
  34. }
  35. //$$ IndexerWithSetOnly
  36. namespace IndexerWithSetOnly
  37. {
  38. public class MyClass
  39. {
  40. public int this[int i]
  41. {
  42. set
  43. {
  44. }
  45. }
  46. }
  47. }
  48. //$$ IndexerWithMoreParameters
  49. namespace IndexerWithMoreParameters
  50. {
  51. public class MyClass
  52. {
  53. public int this[int i, string s, Type t]
  54. {
  55. get
  56. {
  57. return 0;
  58. }
  59. }
  60. }
  61. }
  62. //$$ IndexerInGenericClass
  63. namespace IndexerInGenericClass
  64. {
  65. public class MyClass<T>
  66. {
  67. public int this[T t]
  68. {
  69. get
  70. {
  71. return 0;
  72. }
  73. }
  74. }
  75. }
  76. //$$ OverloadedIndexer
  77. namespace OverloadedIndexer
  78. {
  79. public class MyClass
  80. {
  81. public int this[int t]
  82. {
  83. get
  84. {
  85. return 0;
  86. }
  87. }
  88. public int this[string s]
  89. {
  90. get
  91. {
  92. return 0;
  93. }
  94. set
  95. {
  96. Console.WriteLine(value + " " + s);
  97. }
  98. }
  99. }
  100. }
  101. //$$ IndexerInInterface
  102. namespace IndexerInInterface
  103. {
  104. public interface IInterface
  105. {
  106. int this[string s, string s2]
  107. {
  108. set;
  109. }
  110. }
  111. }
  112. //$$ IndexerInterfaceExplicitImplementation
  113. namespace IndexerInterfaceExplicitImplementation
  114. {
  115. public interface IMyInterface
  116. {
  117. int this[string s]
  118. {
  119. get;
  120. }
  121. }
  122. public class MyClass : IMyInterface
  123. {
  124. int IMyInterface.this[string s]
  125. {
  126. get
  127. {
  128. return 3;
  129. }
  130. }
  131. }
  132. }
  133. //$$ IndexerInterfaceImplementation
  134. namespace IndexerInterfaceImplementation
  135. {
  136. public interface IMyInterface
  137. {
  138. int this[string s]
  139. {
  140. get;
  141. }
  142. }
  143. public class MyClass : IMyInterface
  144. {
  145. public int this[string s]
  146. {
  147. get
  148. {
  149. return 3;
  150. }
  151. }
  152. }
  153. }
  154. //$$ IndexerAbstract
  155. namespace IndexerAbstract
  156. {
  157. public abstract class MyClass
  158. {
  159. public abstract int this[string s, string s2]
  160. {
  161. set;
  162. }
  163. protected abstract string this[int index]
  164. {
  165. get;
  166. }
  167. }
  168. }
  169. //$$ MethodExplicit
  170. namespace MethodExplicit
  171. {
  172. public interface IMyInterface
  173. {
  174. void MyMethod();
  175. }
  176. public class MyClass : IMyInterface
  177. {
  178. void IMyInterface.MyMethod()
  179. {
  180. }
  181. }
  182. }
  183. //$$ MethodFromInterfaceVirtual
  184. namespace MethodFromInterfaceVirtual
  185. {
  186. public interface IMyInterface
  187. {
  188. void MyMethod();
  189. }
  190. public class MyClass : IMyInterface
  191. {
  192. public virtual void MyMethod()
  193. {
  194. }
  195. }
  196. }
  197. //$$ MethodFromInterface
  198. namespace MethodFromInterface
  199. {
  200. public interface IMyInterface
  201. {
  202. void MyMethod();
  203. }
  204. public class MyClass : IMyInterface
  205. {
  206. public void MyMethod()
  207. {
  208. }
  209. }
  210. }
  211. //$$ MethodFromInterfaceAbstract
  212. namespace MethodFromInterfaceAbstract
  213. {
  214. public interface IMyInterface
  215. {
  216. void MyMethod();
  217. }
  218. public abstract class MyClass : IMyInterface
  219. {
  220. public abstract void MyMethod();
  221. }
  222. }
  223. //$$ PropertyInterface
  224. namespace PropertyInterface
  225. {
  226. public interface IMyInterface
  227. {
  228. int MyProperty
  229. {
  230. get;
  231. set;
  232. }
  233. }
  234. }
  235. //$$ PropertyInterfaceExplicitImplementation
  236. namespace PropertyInterfaceExplicitImplementation
  237. {
  238. public interface IMyInterface
  239. {
  240. int MyProperty
  241. {
  242. get;
  243. set;
  244. }
  245. }
  246. public class MyClass : IMyInterface
  247. {
  248. int IMyInterface.MyProperty
  249. {
  250. get
  251. {
  252. return 0;
  253. }
  254. set
  255. {
  256. }
  257. }
  258. }
  259. }
  260. //$$ PropertyInterfaceImplementation
  261. namespace PropertyInterfaceImplementation
  262. {
  263. public interface IMyInterface
  264. {
  265. int MyProperty
  266. {
  267. get;
  268. set;
  269. }
  270. }
  271. public class MyClass : IMyInterface
  272. {
  273. public int MyProperty
  274. {
  275. get
  276. {
  277. return 0;
  278. }
  279. set
  280. {
  281. }
  282. }
  283. }
  284. }
  285. //$$ PropertyPrivateGetPublicSet
  286. namespace PropertyPrivateGetPublicSet
  287. {
  288. public class MyClass
  289. {
  290. public int MyProperty
  291. {
  292. private get
  293. {
  294. return 3;
  295. }
  296. set
  297. {
  298. }
  299. }
  300. }
  301. }
  302. //$$ PropertyPublicGetProtectedSet
  303. namespace PropertyPublicGetProtectedSet
  304. {
  305. public class MyClass
  306. {
  307. public int MyProperty
  308. {
  309. get
  310. {
  311. return 3;
  312. }
  313. protected set
  314. {
  315. }
  316. }
  317. }
  318. }
  319. //$$ PropertyOverrideDefaultAccessorOnly
  320. namespace PropertyOverrideDefaultAccessorOnly
  321. {
  322. public class MyClass
  323. {
  324. public virtual int MyProperty
  325. {
  326. get
  327. {
  328. return 3;
  329. }
  330. protected set
  331. {
  332. }
  333. }
  334. }
  335. public class Derived : MyClass
  336. {
  337. public override int MyProperty
  338. {
  339. get
  340. {
  341. return 4;
  342. }
  343. }
  344. }
  345. }
  346. //$$ PropertyOverrideRestrictedAccessorOnly
  347. namespace PropertyOverrideRestrictedAccessorOnly
  348. {
  349. public class MyClass
  350. {
  351. public virtual int MyProperty
  352. {
  353. get
  354. {
  355. return 3;
  356. }
  357. protected set
  358. {
  359. }
  360. }
  361. }
  362. public class Derived : MyClass
  363. {
  364. public override int MyProperty
  365. {
  366. protected set
  367. {
  368. }
  369. }
  370. }
  371. }
  372. //$$ PropertyOverrideOneAccessor
  373. namespace PropertyOverrideOneAccessor
  374. {
  375. public class MyClass
  376. {
  377. protected internal virtual int MyProperty
  378. {
  379. get
  380. {
  381. return 3;
  382. }
  383. protected set
  384. {
  385. }
  386. }
  387. }
  388. public class DerivedNew : MyClass
  389. {
  390. public new virtual int MyProperty
  391. {
  392. set
  393. {
  394. }
  395. }
  396. }
  397. public class DerivedOverride : DerivedNew
  398. {
  399. public override int MyProperty
  400. {
  401. set
  402. {
  403. }
  404. }
  405. }
  406. }
  407. //$$ IndexerOverrideRestrictedAccessorOnly
  408. namespace IndexerOverrideRestrictedAccessorOnly
  409. {
  410. public class MyClass
  411. {
  412. public virtual int this[string s]
  413. {
  414. get
  415. {
  416. return 3;
  417. }
  418. protected set
  419. {
  420. }
  421. }
  422. protected internal virtual int this[int i]
  423. {
  424. protected get
  425. {
  426. return 2;
  427. }
  428. set
  429. {
  430. }
  431. }
  432. }
  433. public class Derived : MyClass
  434. {
  435. protected internal override int this[int i]
  436. {
  437. protected get
  438. {
  439. return 4;
  440. }
  441. }
  442. }
  443. }
  444. //$$ HideProperty
  445. namespace HideProperty
  446. {
  447. public class A
  448. {
  449. public virtual int P
  450. {
  451. get
  452. {
  453. return 0;
  454. }
  455. set
  456. {
  457. }
  458. }
  459. }
  460. public class B : A
  461. {
  462. private new int P
  463. {
  464. get
  465. {
  466. return 0;
  467. }
  468. set
  469. {
  470. }
  471. }
  472. }
  473. public class C : B
  474. {
  475. public override int P
  476. {
  477. set
  478. {
  479. }
  480. }
  481. }
  482. }
  483. //$$ HideMembers
  484. namespace HideMembers
  485. {
  486. public class A
  487. {
  488. public int F;
  489. public int Prop
  490. {
  491. get
  492. {
  493. return 3;
  494. }
  495. }
  496. public int G
  497. {
  498. get
  499. {
  500. return 3;
  501. }
  502. }
  503. }
  504. public class B : A
  505. {
  506. public new int F
  507. {
  508. get
  509. {
  510. return 3;
  511. }
  512. }
  513. public new string Prop
  514. {
  515. get
  516. {
  517. return "a";
  518. }
  519. }
  520. }
  521. public class C : A
  522. {
  523. public new int G;
  524. }
  525. public class D : A
  526. {
  527. public new void F()
  528. {
  529. }
  530. }
  531. public class D1 : D
  532. {
  533. public new int F;
  534. }
  535. public class E : A
  536. {
  537. private new class F
  538. {
  539. }
  540. }
  541. }
  542. //$$ HideMembers2
  543. namespace HideMembers2
  544. {
  545. public class G
  546. {
  547. public int Item
  548. {
  549. get
  550. {
  551. return 1;
  552. }
  553. }
  554. }
  555. public class G2 : G
  556. {
  557. public int this[int i]
  558. {
  559. get
  560. {
  561. return 2;
  562. }
  563. }
  564. }
  565. public class G3 : G2
  566. {
  567. public new int Item
  568. {
  569. get
  570. {
  571. return 4;
  572. }
  573. }
  574. }
  575. public class H
  576. {
  577. public int this[int j]
  578. {
  579. get
  580. {
  581. return 0;
  582. }
  583. }
  584. }
  585. public class H2 : H
  586. {
  587. public int Item
  588. {
  589. get
  590. {
  591. return 2;
  592. }
  593. }
  594. }
  595. public class H3 : H2
  596. {
  597. public new string this[int j]
  598. {
  599. get
  600. {
  601. return null;
  602. }
  603. }
  604. }
  605. }
  606. //$$ HideMembers2a
  607. namespace HideMembers2a
  608. {
  609. public interface IA
  610. {
  611. int this[int i]
  612. {
  613. get;
  614. }
  615. }
  616. public class A : IA
  617. {
  618. int IA.this[int i]
  619. {
  620. get
  621. {
  622. throw new NotImplementedException();
  623. }
  624. }
  625. }
  626. public class A1 : A
  627. {
  628. public int this[int i]
  629. {
  630. get
  631. {
  632. return 3;
  633. }
  634. }
  635. }
  636. }
  637. //$$ HideMembers3
  638. namespace HideMembers3
  639. {
  640. public class G<T>
  641. {
  642. public void M1(T p)
  643. {
  644. }
  645. public int M2(int t)
  646. {
  647. return 3;
  648. }
  649. }
  650. public class G1<T> : G<int>
  651. {
  652. public new int M1(int i)
  653. {
  654. return 0;
  655. }
  656. public int M2(T i)
  657. {
  658. return 2;
  659. }
  660. }
  661. public class G2<T> : G<int>
  662. {
  663. public int M1(T p)
  664. {
  665. return 4;
  666. }
  667. }
  668. public class J
  669. {
  670. public int P
  671. {
  672. get
  673. {
  674. return 2;
  675. }
  676. }
  677. }
  678. public class J2 : J
  679. {
  680. #pragma warning disable 0108 // Deliberate bad code for test case
  681. public int get_P;
  682. #pragma warning restore 0108
  683. }
  684. }
  685. //$$ HideMembers4
  686. namespace HideMembers4
  687. {
  688. public class A
  689. {
  690. public void M<T>(T t)
  691. {
  692. }
  693. }
  694. public class A1 : A
  695. {
  696. public new void M<K>(K t)
  697. {
  698. }
  699. public void M(int t)
  700. {
  701. }
  702. }
  703. public class B
  704. {
  705. public void M<T>()
  706. {
  707. }
  708. public void M1<T>()
  709. {
  710. }
  711. public void M2<T>(T t)
  712. {
  713. }
  714. }
  715. public class B1 : B
  716. {
  717. public void M<T1, T2>()
  718. {
  719. }
  720. public new void M1<R>()
  721. {
  722. }
  723. public new void M2<R>(R r)
  724. {
  725. }
  726. }
  727. public class C<T>
  728. {
  729. public void M<TT>(T t)
  730. {
  731. }
  732. }
  733. public class C1<K> : C<K>
  734. {
  735. public void M<TT>(TT t)
  736. {
  737. }
  738. }
  739. }
  740. //$$ HideMembers5
  741. namespace HideMembers5
  742. {
  743. public class A
  744. {
  745. public void M(int t)
  746. {
  747. }
  748. }
  749. public class A1 : A
  750. {
  751. public void M(ref int t)
  752. {
  753. }
  754. }
  755. public class B
  756. {
  757. public void M(ref int l)
  758. {
  759. }
  760. }
  761. public class B1 : B
  762. {
  763. public void M(out int l)
  764. {
  765. l = 2;
  766. }
  767. public void M(ref long l)
  768. {
  769. }
  770. }
  771. }
  772. //$$ HideMemberSkipNotVisible
  773. namespace HideMemberSkipNotVisible
  774. {
  775. public class A
  776. {
  777. protected int F;
  778. protected string P
  779. {
  780. get
  781. {
  782. return null;
  783. }
  784. }
  785. }
  786. public class B : A
  787. {
  788. private new string F;
  789. private new int P
  790. {
  791. set
  792. {
  793. }
  794. }
  795. }
  796. }
  797. //$$ HideNestedClass
  798. namespace HideNestedClass
  799. {
  800. public class A
  801. {
  802. public class N1
  803. {
  804. }
  805. protected class N2
  806. {
  807. }
  808. private class N3
  809. {
  810. }
  811. internal class N4
  812. {
  813. }
  814. protected internal class N5
  815. {
  816. }
  817. }
  818. public class B : A
  819. {
  820. public new int N1;
  821. public new int N2;
  822. public int N3;
  823. public new int N4;
  824. public new int N5;
  825. }
  826. }
  827. //$$ HidePropertyReservedMethod
  828. namespace HidePropertyReservedMethod
  829. {
  830. public class A
  831. {
  832. public int P
  833. {
  834. get
  835. {
  836. return 1;
  837. }
  838. }
  839. }
  840. public class B : A
  841. {
  842. public int get_P()
  843. {
  844. return 2;
  845. }
  846. public void set_P(int value)
  847. {
  848. }
  849. }
  850. }
  851. //$$ HideIndexerDiffAccessor
  852. namespace HideIndexerDiffAccessor
  853. {
  854. public class A
  855. {
  856. public int this[int i]
  857. {
  858. get
  859. {
  860. return 2;
  861. }
  862. }
  863. }
  864. public class B : A
  865. {
  866. public new int this[int j]
  867. {
  868. set
  869. {
  870. }
  871. }
  872. }
  873. }
  874. //$$ HideIndexerGeneric
  875. namespace HideIndexerGeneric
  876. {
  877. public class A<T>
  878. {
  879. public virtual int this[T r]
  880. {
  881. get
  882. {
  883. return 0;
  884. }
  885. set
  886. {
  887. }
  888. }
  889. }
  890. public class B : A<int>
  891. {
  892. private new int this[int k]
  893. {
  894. get
  895. {
  896. return 0;
  897. }
  898. set
  899. {
  900. }
  901. }
  902. }
  903. public class C<T> : A<T>
  904. {
  905. public override int this[T s]
  906. {
  907. set
  908. {
  909. }
  910. }
  911. }
  912. public class D<T> : C<T>
  913. {
  914. public new virtual int this[T s]
  915. {
  916. set
  917. {
  918. }
  919. }
  920. }
  921. }
  922. //$$ HideMethod
  923. namespace HideMethod
  924. {
  925. public class A
  926. {
  927. public virtual void F()
  928. {
  929. }
  930. }
  931. public class B : A
  932. {
  933. private new void F()
  934. {
  935. base.F();
  936. }
  937. }
  938. public class C : B
  939. {
  940. public override void F()
  941. {
  942. base.F();
  943. }
  944. }
  945. }
  946. //$$ HideMethodGeneric
  947. namespace HideMethodGeneric
  948. {
  949. public class A<T>
  950. {
  951. public virtual void F(T s)
  952. {
  953. }
  954. public new static bool Equals(object o1, object o2)
  955. {
  956. return true;
  957. }
  958. }
  959. public class B : A<string>
  960. {
  961. private new void F(string k)
  962. {
  963. }
  964. public void F(int i)
  965. {
  966. }
  967. }
  968. public class C<T> : A<T>
  969. {
  970. public override void F(T r)
  971. {
  972. }
  973. public void G(T t)
  974. {
  975. }
  976. }
  977. public class D<T1> : C<T1>
  978. {
  979. public new virtual void F(T1 k)
  980. {
  981. }
  982. public virtual void F<T2>(T2 k)
  983. {
  984. }
  985. public virtual void G<T2>(T2 t)
  986. {
  987. }
  988. }
  989. }
  990. //$$ HideMethodGenericSkipPrivate
  991. namespace HideMethodGenericSkipPrivate
  992. {
  993. public class A<T>
  994. {
  995. public virtual void F(T t)
  996. {
  997. }
  998. }
  999. public class B<T> : A<T>
  1000. {
  1001. private new void F(T t)
  1002. {
  1003. }
  1004. private void K()
  1005. {
  1006. }
  1007. }
  1008. public class C<T> : B<T>
  1009. {
  1010. public override void F(T tt)
  1011. {
  1012. }
  1013. public void K()
  1014. {
  1015. }
  1016. }
  1017. public class D : B<int>
  1018. {
  1019. public override void F(int t)
  1020. {
  1021. }
  1022. }
  1023. }
  1024. //$$ HideMethodGeneric2
  1025. namespace HideMethodGeneric2
  1026. {
  1027. public class A
  1028. {
  1029. public virtual void F(int i)
  1030. {
  1031. }
  1032. public void K()
  1033. {
  1034. }
  1035. }
  1036. public class B<T> : A
  1037. {
  1038. protected virtual void F(T t)
  1039. {
  1040. }
  1041. public void K<T2>()
  1042. {
  1043. }
  1044. }
  1045. public class C : B<int>
  1046. {
  1047. protected override void F(int k)
  1048. {
  1049. }
  1050. public new void K<T3>()
  1051. {
  1052. }
  1053. }
  1054. public class D : B<string>
  1055. {
  1056. public override void F(int k)
  1057. {
  1058. }
  1059. public void L<T4>()
  1060. {
  1061. }
  1062. }
  1063. public class E<T>
  1064. {
  1065. public void M<T2>(T t, T2 t2)
  1066. {
  1067. }
  1068. }
  1069. public class F<T> : E<T>
  1070. {
  1071. public void M(T t1, T t2)
  1072. {
  1073. }
  1074. }
  1075. }
  1076. //$$ HideMethodDiffSignatures
  1077. namespace HideMethodDiffSignatures
  1078. {
  1079. public class C1<T>
  1080. {
  1081. public virtual void M(T arg)
  1082. {
  1083. }
  1084. }
  1085. public class C2<T1, T2> : C1<T2>
  1086. {
  1087. public new virtual void M(T2 arg)
  1088. {
  1089. }
  1090. }
  1091. public class C3 : C2<int, bool>
  1092. {
  1093. public new virtual void M(bool arg)
  1094. {
  1095. }
  1096. }
  1097. }
  1098. //$$ HideMethodStatic
  1099. namespace HideMethodStatic
  1100. {
  1101. public class A
  1102. {
  1103. public int N
  1104. {
  1105. get
  1106. {
  1107. return 0;
  1108. }
  1109. }
  1110. }
  1111. public class B
  1112. {
  1113. public int N()
  1114. {
  1115. return 0;
  1116. }
  1117. }
  1118. }
  1119. //$$ HideEvent
  1120. namespace HideEvent
  1121. {
  1122. public class A
  1123. {
  1124. public virtual event EventHandler E;
  1125. public event EventHandler F;
  1126. }
  1127. public class B : A
  1128. {
  1129. public new virtual event EventHandler E;
  1130. public new event EventHandler F;
  1131. }
  1132. public class C : B
  1133. {
  1134. public override event EventHandler E;
  1135. }
  1136. }