# Inlined method with generic ref parameters cause problems

**URL:** https://talk.remobjects.com/t/inlined-method-with-generic-ref-parameters-cause-problems/8788
**Category:** C#
**Created:** [March 31, 2016, 3:36am UTC](https://talk.remobjects.com/t/inlined-method-with-generic-ref-parameters-cause-problems/8788 "2016-03-31T03:36:08Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![Esword](https://talk.remobjects.com/user_avatar/talk.remobjects.com/esword/32/1447_2.png) [@Esword](https://talk.remobjects.com/u/Esword)
#### Post date: [March 31, 2016, 3:36am UTC](https://talk.remobjects.com/t/inlined-method-with-generic-ref-parameters-cause-problems/8788/1 "2016-03-31T03:36:08Z")

</div>

**IDE:** VS 2015  
**Version:** 8.3.91.1965  
**Target** (If relevant): .NET/Android/iOS  
**Description** :

```
    public class TestClass {

    public static void doTest() {

        // bug 1) compile error
        int c = 5;
        int d = 6;
        /**
        Android compile error: 
        Uncaught translation error: com.android.dx.cf.code.SimException: expected type java.lang.Object but found int 1 error; aborting

        iOS compiling just crash the VS 2015.
        */
        swap(ref c, ref d);

        // bug 2) won't work for array
        string[] arr = new string[]{"c","d"};
        swap(ref arr[0], ref arr[1]);
        assert(arr[0] == "d"); // failed on .NET/Android/iOS
    }

    public static __inline void swap<T>(ref T a, ref T b) {
        var t = a;
        a = b;
        b = t;
    }
}

```

By the way, I use \_\_inline to optmize the swap function because I guess it’s the only way to generate efficient codes for Java and iOS. If it’s not inlined, the generated Java code will include inefficient lines to construct VarParameter objects to bypass Java limitations. And I’m not sure how the compiler handle generic ref parameter for iOS if raw types are involved.  
I think a built-in cross-platform swap function for Elements is needed, because it’s too tricky to build a homemade one. This function should provide the most efficient way to swap two values.

---

<div class="post-metadata">

### Author: ![RemObjectsSoftware](https://talk.remobjects.com/user_avatar/talk.remobjects.com/remobjectssoftware/32/15947_2.png) [@RemObjectsSoftware](https://talk.remobjects.com/u/RemObjectsSoftware)
#### Post date: [March 31, 2016, 8:10am UTC](https://talk.remobjects.com/t/inlined-method-with-generic-ref-parameters-cause-problems/8788/2 "2016-03-31T08:10:30Z")

</div>

Thanks, logged as bugs://74897

---

<div class="post-metadata">

### Author: ![RemObjectsSoftware](https://talk.remobjects.com/user_avatar/talk.remobjects.com/remobjectssoftware/32/15947_2.png) [@RemObjectsSoftware](https://talk.remobjects.com/u/RemObjectsSoftware)
#### Post date: [May 13, 2016, 8:36am UTC](https://talk.remobjects.com/t/inlined-method-with-generic-ref-parameters-cause-problems/8788/3 "2016-05-13T08:36:51Z")

</div>

bugs://74897 got closed with status fixed.

---

<div class="post-metadata">

### Author: ![RemObjectsSoftware](https://talk.remobjects.com/user_avatar/talk.remobjects.com/remobjectssoftware/32/15947_2.png) [@RemObjectsSoftware](https://talk.remobjects.com/u/RemObjectsSoftware)
#### Post date: [September 1, 2020, 3:28am UTC](https://talk.remobjects.com/t/inlined-method-with-generic-ref-parameters-cause-problems/8788/4 "2020-09-01T03:28:36Z")

</div>

Logged as [bugs://i62932](https://www.remobjects.com/portal/bugs/?id=i62932).

---

<div class="post-metadata">

### Author: ![RemObjectsSoftware](https://talk.remobjects.com/user_avatar/talk.remobjects.com/remobjectssoftware/32/15947_2.png) [@RemObjectsSoftware](https://talk.remobjects.com/u/RemObjectsSoftware)
#### Post date: [September 1, 2020, 3:28am UTC](https://talk.remobjects.com/t/inlined-method-with-generic-ref-parameters-cause-problems/8788/5 "2020-09-01T03:28:37Z")

</div>

[bugs://i62932](https://www.remobjects.com/portal/bugs/?id=i62932) was closed as fixed.
