コード例 #1
0
        void Method1()
        {
            // Nếu value type xuất hiện như một parameter hoặc local variable, thì nó sẽ nằm trên stack.
            NormalStruct normalStruct = new NormalStruct(); // làm sao biết nằm trên stack.

            // ref struct variable.
            var refStruct = new RefStruct();

            // ref struct không thể là element type của array.
            var points        = new RefStruct[100];
            var normalStructs = new NormalStruct[100];

            // boxing to IInterface1.
            IInterface1 boxingStruct = normalStruct;

            // unboxing to NormalStruct
            var unboxingStruct = (NormalStruct)boxingStruct;

            // ref struct không thể là type argument.
            var genericClass = new GenericClass <RefStruct>();

            // ref struct variable không thể sử dụng trong vòng lặp.

            // biến ref variable không thể ghi lại (capture) bởi một lambda expression hoặc local function.
            Func <int, int> square = x => x * refStruct;

            void localFunction()
            {
                var sum = 10 * refStruct;
            }
        }
コード例 #2
0
 public SetAttributeResponseMessage(Type source, Type destination, IZMIRequestMessage request,
                                    RefStruct <bool> response)
 {
     Source      = source;
     Destination = destination;
     Request     = request;
     Response    = response;
 }
コード例 #3
0
 public UninstallQueryResponseMessage(Type source, Type destination, IZMIRequestMessage request,
                                      RefStruct <bool> response)
 {
     Source      = source;
     Destination = destination;
     Request     = request;
     Response    = response;
 }
コード例 #4
0
        private static async Task Main(string[] args)
        {
            await AsyncIterator.Demo();

            Pattern.Demo();
            DefaultInterfaceMember.Demo();
            IndiceAndRange.Demo();
            UsingStatementSample.Demo();
            NullCoalescingAssignmentSample.Demo();
            StaticLocalFunction.Demo();
            ReadOnlyMember.Demo();
            RefStruct.Demo();
            StackAllocSample.Demo();
            InterpolatedVerbatimString.Demo();
            UnmanagedConstraintSample.Demo();
        }
コード例 #5
0
ファイル: Version7Plus.cs プロジェクト: KeyserDSoze/Test
        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
        }
コード例 #6
0
 public void MethodWithArgsFieldAccess(int argInt, string argStr, RefClass argClass, RefStruct argStruct)
 {
     //var arg6Name = arg666.Name;
     Single.Parse("1.22");
     argClass.CallTest(9);
     argClass.CallTestF(9);
     argStruct.Name = " Accessed";
 }
コード例 #7
0
 /*void Method()
  * {
  *  var reff = new RefClass("TestCase");
  *  refed = new RefClass("TestCase");
  *
  *  string[] TestArray = { "1", "2", "3" };
  *  Array arr = TestArray;
  *  var test = (arr as string[])[1];
  *  string[][] arr_typed = { (string[])arr, (string[])arr };
  * }
  * float MethodWithConstRet()
  * {
  *  return 5;
  * }
  * string MethodWithConstStringRet()
  * {
  *  return "RTCLI Test: Const String";
  * }*/
 public void MethodWithArgsAccess(int argInt, string argStr, RefClass argClass, RefStruct argStruct)
 {
     var argI  = argInt;
     var argSt = argStr;
     var argS  = argStruct;
     var argC  = argClass;
 }
コード例 #8
0
        // Có thể sử dụng trong synchronouns method (return Task hoặc Task<TResult>).
        Task SyncMethod()
        {
            var refStruct = new RefStruct();

            return(Task.FromResult(0));
        }
コード例 #9
0
 // ref struct variable không thể sử dụng trong async method.
 async Task AsyncMethod()
 {
     var refStruct = new RefStruct();
 }
コード例 #10
0
 public ValueDuration(RefStruct <long> value) : base(value)
 {
 }
コード例 #11
0
 protected virtual void TestWithConstraint <T0>(RefStruct refStruct, T outer, T0 parameter) where T0 : T
 {
     throw new MockMissingException(MockType.VirtualMethod, "TestClass", "ITestClass", "TestWithConstraint", "TestWithConstraint");
 }
コード例 #12
0
    static public int run(Ice.Communicator communicator)
    {
        Write("testing serialization... ");
        Flush();

        MyClassPrx proxy = MyClassPrxHelper.uncheckedCast(communicator.stringToProxy("test"));

        MyException ex, ex2;

        ex              = new MyException();
        ex.name         = "";
        ex.vss          = new ValStruct[0];
        ex.vsl          = new List <ValStruct>();
        ex.vsll         = new LinkedList <ValStruct>();
        ex.vssk         = new Stack <ValStruct>();
        ex.vsq          = new Queue <ValStruct>();
        ex.isd          = new Dictionary <int, string>();
        ex.ivd          = new Dictionary <int, ValStruct>();
        ex.ipd          = null;
        ex.issd         = new SortedDictionary <int, string>();
        ex.optName      = new Ice.Optional <string>();
        ex.optInt       = new Ice.Optional <int>();
        ex.optValStruct = new Ice.Optional <ValStruct>();
        ex.optRefStruct = new Ice.Optional <RefStruct>();
        ex.optEnum      = new Ice.Optional <MyEnum>();
        ex.optProxy     = new Ice.Optional <MyClassPrx>();
        ex2             = inOut(ex);
        test(ex.Equals(ex2));

        ex.name   = "MyException";
        ex.b      = 1;
        ex.s      = 2;
        ex.i      = 3;
        ex.l      = 4;
        ex.vs     = new ValStruct(true, 1, 2, 3, 4, MyEnum.enum2);
        ex.rs     = new RefStruct("RefStruct", "prop", null, null);
        ex.vss    = new ValStruct[1];
        ex.vss[0] = ex.vs;
        ex.vsl    = new List <ValStruct>();
        ex.vsl.Add(ex.vs);
        ex.vsll = new LinkedList <ValStruct>();
        ex.vsll.AddLast(ex.vs);
        ex.vssk = new Stack <ValStruct>();
        ex.vssk.Push(ex.vs);
        ex.vsq = new Queue <ValStruct>();
        ex.vsq.Enqueue(ex.vs);
        ex.isd          = new Dictionary <int, string>();
        ex.isd[5]       = "five";
        ex.ivd          = new Dictionary <int, ValStruct>();
        ex.ivd[1]       = ex.vs;
        ex.ipd          = new Dictionary <int, MyClassPrx>();
        ex.issd         = new SortedDictionary <int, string>();
        ex.issd[3]      = "three";
        ex.optName      = new Ice.Optional <string>("MyException");
        ex.optInt       = new Ice.Optional <int>(99);
        ex.optValStruct = new Ice.Optional <ValStruct>(ex.vs);
        ex.optRefStruct = new Ice.Optional <RefStruct>(ex.rs);
        ex.optEnum      = new Ice.Optional <MyEnum>(MyEnum.enum3);
        ex.optProxy     = new Ice.Optional <MyClassPrx>(proxy);

        ex2 = inOut(ex);
        test(!ex.Equals(ex2));
        ex.ipd      = null;          // Not serialized
        ex.optProxy = Ice.Util.None; // Not serialized
        test(ex.optName.Equals(ex2.optName));
        test(ex.optInt.Equals(ex2.optInt));
        test(ex.optValStruct.Equals(ex2.optValStruct));
        test(ex.optRefStruct.Equals(ex2.optRefStruct));
        test(ex.optEnum.Equals(ex2.optEnum));
        test(ex.optProxy.Equals(ex2.optProxy));
        test(ex.Equals(ex2));

        RefStruct rs, rs2;

        rs     = new RefStruct();
        rs.s   = "RefStruct";
        rs.sp  = "prop";
        rs.p   = MyClassPrxHelper.uncheckedCast(communicator.stringToProxy("test"));
        rs.seq = new MyClassPrx[] { rs.p };
        rs2    = inOut(rs);
        test(rs2.s.Equals(rs.s));
        test(rs2.sp.Equals(rs.sp));
        test(rs2.p == null);
        test(rs2.seq == null);

        Base b, b2;

        b  = new Base(true, 1, 2, 3, 4, MyEnum.enum2);
        b2 = inOut(b);
        test(b2.bo == b.bo);
        test(b2.by == b.by);
        test(b2.sh == b.sh);
        test(b2.i == b.i);
        test(b2.l == b.l);
        test(b2.e == b.e);

        MyClass c, c2;

        c   = new MyClass(true, 1, 2, 3, 4, MyEnum.enum1, null, null, new ValStruct(true, 1, 2, 3, 4, MyEnum.enum2));
        c.c = c;
        c.o = c;
        c2  = inOut(c);
        test(c2.bo == c.bo);
        test(c2.by == c.by);
        test(c2.sh == c.sh);
        test(c2.i == c.i);
        test(c2.l == c.l);
        test(c2.e == c.e);
        test(c2.c == c2);
        test(c2.o == c2);
        test(c2.s.Equals(c.s));

        WriteLine("ok");
        return(0);
    }
コード例 #13
0
ファイル: ValueTime.cs プロジェクト: swtwsk/cloudatlas
 public ValueTime(RefStruct <long> value) : base(value)
 {
 }
コード例 #14
0
ファイル: Version7Plus.cs プロジェクト: KeyserDSoze/Test
 public static void Set(ReadOnlyStruct readOnlyStruct, RefStruct refStruct)
 {
     Console.WriteLine("Calling Set");
 }
コード例 #15
0
 public void METHOD()
 {
     using (var obj = new RefStruct())
     {
     }
 }
コード例 #16
0
 void ITestClass <T> .TestWithConstraint <T0>(RefStruct refStruct, T outer, T0 parameter) => TestWithConstraint <T0>(refStruct, outer, parameter);
コード例 #17
0
 public void MethodWithArgsVirtCall(int argInt, string argStr, RefClass argClass, RefStruct argStruct)
 {
     var argC     = argClass;
     var argCName = argClass.Name;
 }
コード例 #18
0
ファイル: ValueInt.cs プロジェクト: swtwsk/cloudatlas
 public ValueInt(RefStruct <long> value) : base(value)
 {
 }
コード例 #19
0
ファイル: ValueBoolean.cs プロジェクト: swtwsk/cloudatlas
 public ValueBoolean(RefStruct <bool> value) : base(value)
 {
 }
コード例 #20
0
        // The contents of this class were created by the Mocklis code-generator.
        // Any changes you make will be overwritten if the contents are re-generated.

        protected virtual void Test <T0>(RefStruct refStruct, T outer, T0 parameter)
        {
            throw new MockMissingException(MockType.VirtualMethod, "TestClass", "ITestClass", "Test", "Test");
        }
コード例 #21
0
ファイル: ValueDouble.cs プロジェクト: swtwsk/cloudatlas
 public ValueDouble(RefStruct <double> value) : base(value)
 {
 }
コード例 #22
0
ファイル: AllTests.cs プロジェクト: zxh1986123/ice
    static public int run(TestCommon.Application app)
    {
        Ice.Communicator communicator = app.communicator();

        Write("testing serialization... ");
        Flush();

        Ice.ObjectPrx proxy = communicator.stringToProxy("test");

        MyException ex, ex2;

        ex              = new MyException();
        ex.name         = "";
        ex.vss          = new ValStruct[0];
        ex.vsl          = new List <ValStruct>();
        ex.vsll         = new LinkedList <ValStruct>();
        ex.vssk         = new Stack <ValStruct>();
        ex.vsq          = new Queue <ValStruct>();
        ex.isd          = new Dictionary <int, string>();
        ex.ivd          = new Dictionary <int, ValStruct>();
        ex.ipd          = null;
        ex.issd         = new SortedDictionary <int, string>();
        ex.optName      = new Ice.Optional <string>();
        ex.optInt       = new Ice.Optional <int>();
        ex.optValStruct = new Ice.Optional <ValStruct>();
        ex.optRefStruct = new Ice.Optional <RefStruct>();
        ex.optEnum      = new Ice.Optional <MyEnum>();
        ex.optProxy     = new Ice.Optional <Ice.ObjectPrx>();
        ex2             = inOut(ex, communicator);
        test(ex.Equals(ex2));

        ex.name   = "MyException";
        ex.b      = 1;
        ex.s      = 2;
        ex.i      = 3;
        ex.l      = 4;
        ex.vs     = new ValStruct(true, 1, 2, 3, 4, MyEnum.enum2);
        ex.rs     = new RefStruct("RefStruct", "prop", proxy, new Ice.ObjectPrx[] { proxy, null, proxy });
        ex.vss    = new ValStruct[1];
        ex.vss[0] = ex.vs;
        ex.vsl    = new List <ValStruct>();
        ex.vsl.Add(ex.vs);
        ex.vsll = new LinkedList <ValStruct>();
        ex.vsll.AddLast(ex.vs);
        ex.vssk = new Stack <ValStruct>();
        ex.vssk.Push(ex.vs);
        ex.vsq = new Queue <ValStruct>();
        ex.vsq.Enqueue(ex.vs);
        ex.isd    = new Dictionary <int, string>();
        ex.isd[5] = "five";
        ex.ivd    = new Dictionary <int, ValStruct>();
        ex.ivd[1] = ex.vs;
        ex.ipd    = new Dictionary <int, Ice.ObjectPrx>()
        {
            { 1, proxy }, { 2, null }, { 3, proxy }
        };
        ex.issd         = new SortedDictionary <int, string>();
        ex.issd[3]      = "three";
        ex.optName      = new Ice.Optional <string>("MyException");
        ex.optInt       = new Ice.Optional <int>(99);
        ex.optValStruct = new Ice.Optional <ValStruct>(ex.vs);
        ex.optRefStruct = new Ice.Optional <RefStruct>(ex.rs);
        ex.optEnum      = new Ice.Optional <MyEnum>(MyEnum.enum3);
        ex.optProxy     = new Ice.Optional <Ice.ObjectPrx>(proxy);
        ex2             = inOut(ex, communicator);
        test(ex.Equals(ex2));

        RefStruct rs, rs2;

        rs     = new RefStruct();
        rs.s   = "RefStruct";
        rs.sp  = "prop";
        rs.p   = communicator.stringToProxy("test");
        rs.seq = new Ice.ObjectPrx[] { rs.p };
        rs2    = inOut(rs, communicator);
        test(rs.Equals(rs2));

        Base b, b2;

        b  = new Base(true, 1, 2, 3, 4, MyEnum.enum2);
        b2 = inOut(b, communicator);
        test(b2.bo == b.bo);
        test(b2.by == b.by);
        test(b2.sh == b.sh);
        test(b2.i == b.i);
        test(b2.l == b.l);
        test(b2.e == b.e);

        MyClass c, c2;

        c   = new MyClass(true, 1, 2, 3, 4, MyEnum.enum1, null, null, new ValStruct(true, 1, 2, 3, 4, MyEnum.enum2));
        c.c = c;
        c.o = c;
        c2  = inOut(c, communicator);
        test(c2.bo == c.bo);
        test(c2.by == c.by);
        test(c2.sh == c.sh);
        test(c2.i == c.i);
        test(c2.l == c.l);
        test(c2.e == c.e);
        test(c2.c == c2);
        test(c2.o == c2);
        test(c2.s.Equals(c.s));

        WriteLine("ok");
        return(0);
    }