Example #1
0
        public void Can_proxy_generic_method_in_generic_type_having_valuetyped_parameter_with_in_modifier()
        {
            var proxy          = this.generator.CreateInterfaceProxyWithoutTarget <IGenericTypeAndMethodWithInModifier <bool> >(new DoNothingInterceptor());
            var readOnlyStruct = new ReadOnlyStruct();

            proxy.Method <int>(in readOnlyStruct);
        }
Example #2
0
        public void Can_proxy_method_having_valuetyped_parameter_with_in_modifier()
        {
            var proxy          = this.generator.CreateInterfaceProxyWithoutTarget <IWithInModifier>(new DoNothingInterceptor());
            var readOnlyStruct = new ReadOnlyStruct();

            proxy.Method(in readOnlyStruct);
        }
Example #3
0
        public void CallOnReadOnlyRefReturn()
        {
            // uses implicit temporary:
            GetReadonlyRef <NormalStruct>().Method();
            // direct call:
            GetReadonlyRef <ReadOnlyStruct>().Method();
            // call on a copy, not the original ref:
            ReadOnlyStruct readonlyRef = GetReadonlyRef <ReadOnlyStruct>();

            readonlyRef.Method();
        }
Example #4
0
        public void By_reference_Out_parameter_can_modify_argument_var()
        {
            var x        = new ReadOnlyStruct(1);
            var original = new ReadOnlyStruct(x.Value);

            var different = new ReadOnlyStruct(x.Value + 100);
            var proxy     = generator.CreateInterfaceProxyWithoutTarget <IOut>(new SetArgumentValueInterceptor(0, different));

            proxy.Method(out x);

            Assert.AreNotEqual(original.Value, x.Value);
        }
Example #5
0
        public bool Equals()
        {
            ReadOnlyStruct current = arrayOfReadonlyStructs[0];
            var            result  = false;

            foreach (ReadOnlyStruct readOnlyStruct in arrayOfReadonlyStructs)
            {
                result = current == readOnlyStruct;
            }

            return(result);
        }
Example #6
0
        public void CallOnRefReturn()
        {
            // Both direct calls:
            GetRef <NormalStruct>().Method();
            GetRef <ReadOnlyStruct>().Method();

            // call on a copy, not the original ref:
            NormalStruct @ref = GetRef <NormalStruct>();

            @ref.Method();

            ReadOnlyStruct ref2 = GetRef <ReadOnlyStruct>();

            ref2.Method();
        }
Example #7
0
        public void Setup()
        {
            arrayOfReadonlyStructs         = new ReadOnlyStruct[ElementsCount];
            arrayOfExtendedReadonlyStructs = new ExtendedReadonlyStruct[ElementsCount];

            for (var i = 0; i < ElementsCount; i++)
            {
                arrayOfReadonlyStructs[i] = new ReadOnlyStruct(i, i + 1);
            }

            for (var i = 0; i < ElementsCount; i++)
            {
                arrayOfExtendedReadonlyStructs[i] = new ExtendedReadonlyStruct(i, i + 1);
            }
        }
Example #8
0
        public void Can_intercept_method_having_valuetypes_parameter_with_in_modifier()
        {
            const int expectedValue = 42;

            object receivedArg = null;
            var    proxy       = this.generator.CreateInterfaceProxyWithoutTarget <IWithInModifier>(
                new WithCallbackInterceptor(invocation =>
            {
                receivedArg = invocation.Arguments[0];
            }));
            var readOnlyStruct = new ReadOnlyStruct(expectedValue);

            proxy.Method(in readOnlyStruct);

            Assert.IsAssignableFrom <ReadOnlyStruct>(receivedArg);
            Assert.AreEqual(expectedValue, ((ReadOnlyStruct)receivedArg).Value);
        }
Example #9
0
        public Version7Plus()
        {
            #region C# 7.1
            Console.WriteLine("Now you can create an async Main");

            Func <string, bool> whereClause = default(Func <string, bool>);
            //now it's possible to do
            Func <string, bool> whereClause2 = default;
            int?x = default;  //and so on

            //in C# 7.0
            int    count = 5;
            string label = "Colors used in the map";
            var    pair  = (count : count, label : label);
            //Now
            var pair2 = (count, label); // element names are "count" and "label", compiler knows.

            Console.WriteLine("There are two new compiler options that generate reference-only assemblies: /refout and /refonly.");
            #endregion
            #region C# 7.2
            // The method can be called in the normal way, by using positional arguments.
            PrintOrderDetails("Gift Shop", 31, "Red Mug");
            // Named arguments can be supplied for the parameters in any order.
            PrintOrderDetails(orderNum: 31, productName: "Red Mug", sellerName: "Gift Shop");
            PrintOrderDetails(productName: "Red Mug", sellerName: "Gift Shop", orderNum: 31);
            // Named arguments mixed with positional arguments are valid
            // as long as they are used in their correct position.
            PrintOrderDetails("Gift Shop", 31, productName: "Red Mug");
            // C# 7.2 onwards
            PrintOrderDetails(sellerName: "Gift Shop", 31, productName: "Red Mug");  //position counts
            PrintOrderDetails("Gift Shop", orderNum: 31, "Red Mug");

            ReadOnlyStruct readOnlyStruct = new ReadOnlyStruct();
            RefStruct      refStruct      = new RefStruct();
            Set(readOnlyStruct, refStruct);

            //Finally, a new compound access modifier: private protected indicates that a member may be accessed by containing
            //class or derived classes that are declared in the same assembly.While protected internal allows access by derived
            //classes or classes that are in the same assembly, private protected limits access to derived types declared in the same assembly.
            #endregion
            #region C# 7.3

            #endregion
        }
Example #10
0
 public static void Set(ReadOnlyStruct readOnlyStruct, RefStruct refStruct)
 {
     Console.WriteLine("Calling Set");
 }