public TestRef2() { // some random data _data = new SampleStruct() { Id = Guid.NewGuid(), Name = "abcdefg", Data1 = 1, Data2 = 2, Data3 = 3, D1 = 1.456m, D2 = 2.456m, D3 = 3.456m, D4 = 4.456m, D5 = 5.456m, D6 = 6.456m, D7 = 7.456m, D8 = 8.456m, N1 = 1, N2 = 2, N3 = 3, N4 = 4, N5 = 5, N6 = 6, N7 = 7, N8 = 8, }; }
public void CallReturnRefReadonly() { for (int i = 0; i < Loop; i++) { ref SampleStruct sampleStruct = ref ReturnRefReadonly(); _x1 = sampleStruct.Data2; }
public void CompareEqualsStructsTest() { var left = new SampleStruct(); var right = new SampleStruct(); Assert.IsTrue(ObjectComparer.AreStructsEqual(left, right)); }
static void HaveALook(out SampleStruct s) { //Insert a breakpoint here to see the //value of s before the assignment: //It will NOT be null... s = new SampleStruct(); }
public void Sample() { //It is impossible to inherit a struct in other struct //but we can implement interfaces //STRUCTS ARE VALUE TYPES //CLASSES ARE REFERENCE TYPES SampleStruct firstStruct; //This is a "group" of variables. All the variables contained on SampleStruct may be accessed //IMPORTANT: AUTOMATICALLY INITIALIZES THE DEFAULT VALUES FOR THE DECLARED TYPES firstStruct.a = 1; firstStruct.b = 1; firstStruct.c = 1; firstStruct.d = 1; //ANOTHER WAY TO USE SampleStruct secondStruct; secondStruct = new SampleStruct() { a = 1, b = 2, c = 3, d = 4 }; //THIRD WAY var otherStruct = new OtherStruct(1, 2); }
public void CallReturnClassic() { for (int i = 0; i < Loop; i++) { SampleStruct sampleStruct = ReturnClassic(); _x1 = sampleStruct.Data2; } }
private SampleStruct GetOutput(Flow flow) { var input = flow.GetValue <SampleStruct>(inputValue); var result = new SampleStruct(); result.Id = input.Id + 1; result.Name = "output_" + input.Name; return(result); }
public void DifferentStructs_ReturnsFalse() { var rightStruct = new SampleStruct { Name = nameof(SampleStruct), Value = 2, }; Assert.IsFalse(ObjectComparer.AreStructsEqual(DefaultStruct, rightStruct)); }
public int Compare(SampleStruct <TMember> x, SampleStruct <TMember> y) { var compare = _memberComparer.Compare(x.Field, y.Field); if (compare != 0) { return(compare); } return(_memberComparer.Compare(x.Property, y.Property)); }
public void SerializeWithStructureTest() { var result = new SampleStruct { Value = 1, Name = "A" }; var data = Json.Serialize(result); Assert.IsNotNull(data); Assert.AreEqual("{\"Value\": 1,\"Name\": \"A\"}", data); }
//public static void StaticMethod() //{ // k = "Rakesh"; // Console.WriteLine(k); //} //public void InstanceMethod() //{ // Console.WriteLine(k); // k = "Dinesh"; //} public void PrintstrutureMember() { //Console.WriteLine(k); SampleStruct ttt = new SampleStruct(); SampleStruct tt; //if you don't use new you will have to initialize structure members before using them otherwise it's error tt.a = 5; Console.WriteLine(tt.a); Console.WriteLine(ttt.a); }
public void CompareDifferentStructsTest() { var left = new SampleStruct() { Name = "PEPE", Value = 1 }; var right = new SampleStruct() { Name = "PEPE", Value = 2 }; Assert.IsFalse(ObjectComparer.AreStructsEqual(left, right)); }
public static string Foo(this SampleStruct self, string a, string b, params string[] any) { var sum = a + b; if (any != null) { for (var i = 0; i < any.Length; i++) { sum += any[i]; } } return(sum); }
public static int Foo(this SampleStruct self, int a, int b, params int[] any) { var sum = a + b; if (any != null) { for (var i = 0; i < any.Length; i++) { sum += any[i]; } } return(sum); }
public static void CallStruct() { SampleStruct sampleStruct = new SampleStruct(); sampleStruct.filed1 = 1; sampleStruct.field2 = "Test"; sampleStruct.field4 = 2.4; Console.WriteLine($"Структура\n{sampleStruct.filed1}\n{sampleStruct.field2}\n{sampleStruct.field4}\n"); SampleStruct sampleStruct1 = new SampleStruct(1, "test2", 2.2); Console.WriteLine($"Структура\n{sampleStruct1.filed1}\n{sampleStruct1.field2}\n{sampleStruct1.field4}\n"); }
public void FromXmlStringTest() { var SampleStruct = new SampleStruct() { Id = "Test", Values = new int[] { 0, 1, 2, 3 }, }; var SampleStructString1 = SampleStruct.ToXmlString(); var SampleStructString2 = SampleStructString1.FromXmlString <SampleStruct>().ToXmlString(); Assert.AreEqual(SampleStructString1, SampleStructString2); }
public void OtherValueTypes_OperatorNotAvailableUnlessOverloaded() { SampleStruct myStruct = new SampleStruct(); SampleStruct myOtherStruct = new SampleStruct(); bool whatEqualsReturns = myStruct.Equals(myOtherStruct); bool whatOperatorReturns = myStruct == myOtherStruct; // Checking equality of two non-primitive value types with == causes compiler error if the operator is not overloaded // in the given type. We had to provide a stub overload in SampleStruct for the test to even compile, and since the overload // calls object.Equals(), which checks for value equality when using value types, the outputs are the same. Assert.True(whatEqualsReturns == whatOperatorReturns); }
public void FromXmlStringTest() { var SampleStruct = new SampleStruct() { Id = "Test", Values = new int[] { 0, 1, 2, 3 }, }; var SampleStructString1 = SampleStruct.ToXmlString(); var SampleStructString2 = SampleStructString1.FromXmlString<SampleStruct>().ToXmlString(); Assert.AreEqual(SampleStructString1, SampleStructString2); }
public static void Main() { SampleStruct s2 = new SampleStruct(0); Console.WriteLine("before call by value : {0}", s2.a); CallByValue(s2); Console.WriteLine("after call by value : {0}", s2.a); SampleClass s1 = new SampleClass(); Console.WriteLine("before call by reference : {0}", s1.a); CallByReference(s1); Console.WriteLine("after call by reference : {0}", s1.a); }
public void StructsEquals_ReturnsTrue() { var leftStruct = new SampleStruct { Name = nameof(SampleStruct), Value = 1, }; var rightStruct = new SampleStruct { Name = nameof(SampleStruct), Value = 1, }; Assert.IsTrue(ObjectComparer.AreEqual(leftStruct, rightStruct)); }
public void StructUnchanged() { var @base = new SampleStruct { Value = 1 }; var changed = new SampleStruct { Value = 1 }; var expected = DiffFactory.Create <SampleStruct>().Class() .MakeDiff(); var ret = Merger.Instance.Partial.Diff(@base, changed); Assert.AreEqual(expected, ret); }
private static void MarshalCOMStructure() { MarshalCOMDataTypeClass comObj = new MarshalCOMDataTypeClass(); SampleStruct sampleStruct = new SampleStruct(); sampleStruct.ID = 1; sampleStruct.stringName = "TestString"; Console.WriteLine("��ʼ�ṹ�����ݣ�\n\tSampleStruct.ID = {0}\n\tSampleStruct.stringName = {1}", sampleStruct.ID, sampleStruct.stringName); comObj.MarshalStructure(ref sampleStruct); Console.WriteLine("���º�ṹ�����ݣ�\n\tSampleStruct.ID = {0}\n\tSampleStruct.stringName = {1}", sampleStruct.ID, sampleStruct.stringName); }
public void CouldSetTypeEnumInJson() { #pragma warning disable 618 Settings.DoAdditionalCorrectnessChecks = false; #pragma warning restore 618 var rm = BufferPool.Retain(10_000); var db = new DirectBuffer(rm.Span); var value = new SampleStruct(42); var size = BinarySerializer.SizeOf(in value, out var tmpBuffer, SerializationFormat.Json); var written = BinarySerializer.Write(in value, ref db, tmpBuffer, SerializationFormat.Json); Assert.AreEqual(size, written); var typeEnumByte = db[1]; Assert.AreEqual(123, typeEnumByte); rm.Dispose(); }
public void Execute() { //Create instance of OpenCL compiler var compiler = new OpenCLCompiler(); //Select a default device compiler.UseDevice(0); //Compile the sample kernel compiler.CompileKernel(typeof(WithStructKernel), typeof(SampleStruct)); var exec = compiler.GetExec(); SampleStruct[] x = new SampleStruct[5]; exec.Fill(x, 2.5); foreach (var item in x) { Console.WriteLine("VarA: {0}, VarB: {1}", item.VarA, item.VarB); } }
static void Main() { // Create objects using default constructors: SampleStruct Location1 = new SampleStruct(); SampleClass Employee1 = new SampleClass(); // Display values: Console.WriteLine("Default values:"); Console.WriteLine(" Struct members: {0}, {1}", Location1.x, Location1.y); Console.WriteLine(" Class members: {0}, {1}", Employee1.name, Employee1.id); // Create objects using parameterized constructors: SampleStruct Location2 = new SampleStruct(10, 20); SampleClass Employee2 = new SampleClass(1234, "Cristina Potra"); // Display values: Console.WriteLine("Assigned values:"); Console.WriteLine(" Struct members: {0}, {1}", Location2.x, Location2.y); Console.WriteLine(" Class members: {0}, {1}", Employee2.name, Employee2.id); }
public static void DoSomethingA(out SampleStruct value) { value = new SampleStruct(); }
public static void DoSomethingB(out SampleStruct value) { DoSomethingA(out value); }
private static extern int Unmanaged_GetSample(ref SampleStruct sampleData);
public int iV_GetSample(ref SampleStruct rawDataSample) { return Unmanaged_GetSample(ref rawDataSample); }
//This is a Constructor public SampleClass() { var aSampleStruct = new SampleStruct(); // This is constructor - it can be left as is or perform additional logic }
private static extern int Unmanaged_GetSample(ref SampleStruct rawDataSample);
private static extern void Sample04(SampleStruct st);
static void Main(string[] args) { Console.WriteLine(Example()); Console.WriteLine(Sample01(10)); var sample02_a = "string 型で文字列を渡すことができます。"; Sample02(2, sample02_a); var sample03_a = new System.Text.StringBuilder(256); sample03_a.Append("文字列のバッファを渡す場合は StringBuilder クラスで受け渡します。"); Sample03(3, sample03_a); Console.WriteLine(sample03_a); var sample04_a = new SampleStruct() { index = 4, name = "構造体サンプル", data = new int[50], }; sample04_a.data[0] = 11; sample04_a.data[1] = 22; sample04_a.data[2] = 33; Sample04(sample04_a); var sample05_a = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(SampleStruct))); try { Sample05(sample05_a); var sample05_b = (SampleStruct)Marshal.PtrToStructure(sample05_a, typeof(SampleStruct)); Console.WriteLine("index = " + sample05_b.index); Console.WriteLine("name = " + sample05_b.name); Console.WriteLine("data[0] = {0}, data[1] = {1}, data[2] = {2}, data[3] = {3}", sample05_b.data[0], sample05_b.data[1], sample05_b.data[2], sample05_b.data[3]); Console.WriteLine("DLL 側できちんと初期化していないと data[3] に値が現れることに注意する必要がある。"); } catch (Exception ex) { System.Diagnostics.Debug.WriteLine(ex); } finally { // 必ずメモリを解放するようにする Marshal.FreeHGlobal(sample05_a); } Console.WriteLine("sssssss"); var sample06_a = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(SampleStruct2))); try { Sample06(sample06_a); var sample06_b = (SampleStruct2)Marshal.PtrToStructure(sample06_a, typeof(SampleStruct2)); for (var i = 0; i < sample06_b.length; i++) { var v = Marshal.ReadInt64(sample06_b.data, i * sizeof(double)); Console.WriteLine("data[{0}] = {1}", i, BitConverter.Int64BitsToDouble(v)); } } catch (Exception ex) { System.Diagnostics.Debug.WriteLine(ex); } finally { // 必ずメモリを解放するようにする Marshal.FreeHGlobal(sample06_a); } Console.WriteLine("rrrrr"); Console.ReadLine(); }
private void OnFrameSampleAcquired(VideoCaptureSample sample) { // Allocate byteBuffer if (_latestImageBytes == null || _latestImageBytes.Length < sample.dataLength) { _latestImageBytes = new byte[sample.dataLength]; } // Fill frame struct SampleStruct s = new SampleStruct(); sample.CopyRawImageDataIntoBuffer(_latestImageBytes); s.data = _latestImageBytes; // Get the cameraToWorldMatrix and projectionMatrix if (!sample.TryGetCameraToWorldMatrix(out s.camera2WorldMatrix) || !sample.TryGetProjectionMatrix(out s.projectionMatrix)) { return; } sample.Dispose(); Matrix4x4 camera2WorldMatrix = LocatableCameraUtils.ConvertFloatArrayToMatrix4x4(s.camera2WorldMatrix); Matrix4x4 projectionMatrix = LocatableCameraUtils.ConvertFloatArrayToMatrix4x4(s.projectionMatrix); UnityEngine.WSA.Application.InvokeOnAppThread(() => { // Upload bytes to texture _pictureTexture.LoadRawTextureData(s.data); _pictureTexture.wrapMode = TextureWrapMode.Clamp; _pictureTexture.Apply(); // Set material parameters _pictureRenderer.sharedMaterial.SetTexture("_MainTex", _pictureTexture); _pictureRenderer.sharedMaterial.SetMatrix("_WorldToCameraMatrix", camera2WorldMatrix.inverse); _pictureRenderer.sharedMaterial.SetMatrix("_CameraProjectionMatrix", projectionMatrix); _pictureRenderer.sharedMaterial.SetFloat("_VignetteScale", 0f); Vector3 inverseNormal = -camera2WorldMatrix.GetColumn(2); // Position the canvas object slightly in front of the real world web camera. Vector3 imagePosition = camera2WorldMatrix.GetColumn(3) - camera2WorldMatrix.GetColumn(2); _picture.transform.position = imagePosition; _picture.transform.rotation = Quaternion.LookRotation(inverseNormal, camera2WorldMatrix.GetColumn(1)); }, false); // Stop the video and reproject the 5 pixels if (stopVideo) { _videoCapture.StopVideoModeAsync(onVideoModeStopped); // Get the ray directions Vector3 imageCenterDirection = LocatableCameraUtils.PixelCoordToWorldCoord(camera2WorldMatrix, projectionMatrix, _resolution, new Vector2(_resolution.width / 2, _resolution.height / 2)); Vector3 imageTopLeftDirection = LocatableCameraUtils.PixelCoordToWorldCoord(camera2WorldMatrix, projectionMatrix, _resolution, new Vector2(0, 0)); Vector3 imageTopRightDirection = LocatableCameraUtils.PixelCoordToWorldCoord(camera2WorldMatrix, projectionMatrix, _resolution, new Vector2(_resolution.width, 0)); Vector3 imageBotLeftDirection = LocatableCameraUtils.PixelCoordToWorldCoord(camera2WorldMatrix, projectionMatrix, _resolution, new Vector2(0, _resolution.height)); Vector3 imageBotRightDirection = LocatableCameraUtils.PixelCoordToWorldCoord(camera2WorldMatrix, projectionMatrix, _resolution, new Vector2(_resolution.width, _resolution.height)); UnityEngine.WSA.Application.InvokeOnAppThread(() => { // Paint the rays on the 3d world _laser.shootLaserFrom(camera2WorldMatrix.GetColumn(3), imageCenterDirection, 10f, _centerMaterial); _laser.shootLaserFrom(camera2WorldMatrix.GetColumn(3), imageTopLeftDirection, 10f, _topLeftMaterial); _laser.shootLaserFrom(camera2WorldMatrix.GetColumn(3), imageTopRightDirection, 10f, _topRightMaterial); _laser.shootLaserFrom(camera2WorldMatrix.GetColumn(3), imageBotLeftDirection, 10f, _botLeftMaterial); _laser.shootLaserFrom(camera2WorldMatrix.GetColumn(3), imageBotRightDirection, 10f, _botRightMaterial); }, false); } }
public void ReadXml(XmlReader reader) { this = new SampleStruct(int.Parse(reader.ReadString())); }