Пример #1
0
    static void Main(string[] args)
    {
        SomeStruct a = new SomeStruct(1, 1);

        a.PublicProperty++;
        a.SetProperty(a.GetProperty() + 1);
    }
Пример #2
0
 static string testExprWithDefault(
     int value         = 10, Enum value2 = Enum.Val2, ExprClass value3 = null, ExprClass value4 = default,
     int value5        = default,
     SomeStruct value6 = new SomeStruct(),
     SomeStruct value7 = default(TestScript.SomeStruct),
     SomeStruct value8 = default
     ) => throw new NotImplementedException();
 public Entity ReplaceSomeStruct(SomeStruct newValue)
 {
     var component = CreateComponent<SomeStructComponent>(ComponentIds.SomeStruct);
     component.value = newValue;
     ReplaceComponent(ComponentIds.SomeStruct, component);
     return this;
 }
Пример #4
0
        public void When_comparing_a_struct_object_to_itself_excluding_base_including_privates()
        {
            var obj = new SomeStruct();

            EasyComparer.Instance.Compare(obj, obj, false, true,
                                          out KeyedCollectionEx <PropertyInfo, Variance> result)
            .ShouldBeTrue();

            result.ShouldNotBeNull();
            result.ShouldNotBeEmpty();
            result.Count.ShouldBe(13);
            result.ShouldAllBe(v => v.Varies == false);

            result.ShouldContain(p => p.Property.Name == "Age");
            result.ShouldContain(p => p.Property.Name == "Stopwatch");
            result.ShouldContain(p => p.Property.Name == "Bytes");
            result.ShouldContain(p => p.Property.Name == "Name");
            result.ShouldContain(p => p.Property.Name == "SomeArray");
            result.ShouldContain(p => p.Property.Name == "SomeList");
            result.ShouldContain(p => p.Property.Name == "SomeCollection");
            result.ShouldContain(p => p.Property.Name == "SomeEnumerable");
            result.ShouldContain(p => p.Property.Name == "SomeDictionary");
            result.ShouldContain(p => p.Property.Name == "SomeNullable");
            result.ShouldContain(p => p.Property.Name == "SomeDate");
            result.ShouldContain(p => p.Property.Name == "SomePrivate");
            result.ShouldContain(p => p.Property.Name == "SomeInternal");
        }
Пример #5
0
        public void When_comparing_equal_struct_objects_with_different_collections()
        {
            var left = new SomeStruct
            {
                Bytes = new byte[] { 1, 2, 0 },
            };

            var right = new SomeStruct
            {
                Bytes = new byte[] { 0, 1, 2 },
            };

            EasyComparer.Instance.Compare(left, right, true, true,
                                          out KeyedCollectionEx <PropertyInfo, Variance> result)
            .ShouldBeFalse();

            result.ShouldNotBeNull();
            result.ShouldNotBeEmpty();
            result.Count.ShouldBe(13);
            result.Count(v => v.Varies == false)
            .ShouldBe(12);

            var varriedProperty = result.Single(p => p.Property.Name == "Bytes");

            varriedProperty.Varies.ShouldBeTrue();
            varriedProperty.LeftValue.ShouldBe(new byte[] { 1, 2, 0 });
            varriedProperty.RightValue.ShouldBe(new byte[] { 0, 1, 2 });
        }
Пример #6
0
        public void NullableOk()
        {
            var s1 = new SomeStruct(5, new object());
            var c1 = Clone((SomeStruct?)s1);

            Assert.True(c1.HasValue);
            Assert.Equal(5, c1.Value.Int);
            Assert.NotNull(c1.Value.Obj);
            Assert.NotSame(s1.Obj, c1.Value.Obj);

            var cloneNull = Clone((SomeStruct?)null);

            Assert.False(cloneNull.HasValue);

            var s2 = new SomeStruct(null, s1);
            var c2 = Clone((SomeStruct?)s2);

            Assert.True(c2.HasValue);
            Assert.False(c2.Value.Int.HasValue);
            Assert.NotNull(c2.Value.Obj);
            Assert.IsType <SomeStruct>(c2.Value.Obj);
            var inner2 = (SomeStruct)c2.Value.Obj;

            Assert.Equal(5, inner2.Int);
            Assert.NotNull(inner2.Obj);
            Assert.NotSame(s1.Obj, inner2.Obj);
        }
Пример #7
0
    public void ReplaceSomeStruct(SomeStruct newValue)
    {
        var component = CreateComponent <SomeStructComponent>(GameComponentsLookup.SomeStruct);

        component.value = newValue;
        ReplaceComponent(GameComponentsLookup.SomeStruct, component);
    }
Пример #8
0
            public void Simple(SomeClass someClass, SomeStruct someStruct)
            {
                if (DictionaryParamInstance[1234] != "it's an instance getter")
                {
                    throw new InvalidOperationException("Incorrect dictionary (instance");
                }

                if (DictionaryParamStatic[1234] != "it's a static getter")
                {
                    throw new InvalidOperationException("Incorrect dictionary (static)");
                }

                if (!(someStruct.RangeEnd == 100 || someStruct.RangeEnd == 1000))
                {
                    throw new InvalidOperationException("Incorrect struct values were passed");
                }

                if (someStruct.RangeEnd != someClass.Values.Length)
                {
                    throw new InvalidOperationException("Incorrect length");
                }

                for (int i = 0; i < someStruct.RangeEnd; i++)
                {
                    if (someClass.Values[i] != i * 2)
                    {
                        throw new InvalidOperationException("Incorrect array values were passed");
                    }
                }
            }
        public Entity AddSomeStruct(SomeStruct newValue)
        {
            var component = CreateComponent <SomeStructComponent>(ComponentIds.SomeStruct);

            component.value = newValue;
            return(AddComponent(ComponentIds.SomeStruct, component));
        }
Пример #10
0
        static void Recursive(int a, int b, int c)
        {
            RuntimeHelpers.EnsureSufficientExecutionStack();

            var ss = new SomeStruct();

            Recursive(a, b, c);
        }
        public Entity ReplaceSomeStruct(SomeStruct newValue)
        {
            var component = CreateComponent <SomeStructComponent>(ComponentIds.SomeStruct);

            component.value = newValue;
            ReplaceComponent(ComponentIds.SomeStruct, component);
            return(this);
        }
Пример #12
0
    public void AddSomeStruct(SomeStruct newValue)
    {
        var index     = GameComponentsLookup.SomeStruct;
        var component = CreateComponent <SomeStructComponent>(index);

        component.value = newValue;
        AddComponent(index, component);
    }
Пример #13
0
        public void AcceptImplementingValuesWhenArrayIsInterfaceType()
        {
            var array = new ISomeInterface[5];

            array[3] = new SomeDerivedClass();
            array[2] = new SomeClass();
            array[0] = new SomeStruct();
        }
Пример #14
0
 public unsafe void TestIndexers()
 {
     var someStruct = new SomeStruct();
     Assert.That(someStruct[0], Is.EqualTo(1));
     Assert.That(someStruct["foo"], Is.EqualTo(1));
     someStruct[0] = 2;
     Assert.That(someStruct[0], Is.EqualTo(2));
 }
Пример #15
0
        public SomeStruct DoStuff(Span <byte> data)
        {
            var someStruct = new SomeStruct();
            var span       = AsSpan(ref someStruct);

            data.CopyTo(span);
            return(someStruct);
        }
Пример #16
0
    public void ReplaceSomeStruct(SomeStruct newValue)
    {
        var index     = GameComponentsLookup.SomeStruct;
        var component = (SomeStructComponent)CreateComponent(index, typeof(SomeStructComponent));

        component.value = newValue;
        ReplaceComponent(index, component);
    }
Пример #17
0
 public static void ByRefValueType(ref SomeStruct data)
 {
     data.Field = 11;
     //for (int i = 0; i < data.Field; ++i)
     //{
     //    Console.WriteLine(data.Field);
     //    data.KeepMeAlive();
     //}
 }
Пример #18
0
 public void NullableValueShouldNotBeNullWithChaining()
 {
     DocExampleWriter.Document(() =>
     {
         SomeStruct?nullableValue = new SomeStruct {
             IntProperty = 41
         };
         nullableValue.ShouldNotBeNull().IntProperty.ShouldBe(42);
     }, _testOutputHelper);
 }
Пример #19
0
 void M <SomeTypeParameter>(
     SomeClass a,
     SomeStruct b,
     SomeRecord c,
     SomeEnum d,
     SomeInterface e,
     SomeDelegate f,
     SomeTypeParameter g)
 {
 }
Пример #20
0
            public static SomeStruct?GetSomeStructFromStringValue(object value)
            {
                var parsedValue = new SomeStruct();

                if ((string)value == parsedValue.ToString())
                {
                    return(parsedValue);
                }

                throw new FormatException();
            }
Пример #21
0
            public override int GetHashCode()
            {
                var result = SomeStruct.GetHashCode();

                if (!_cpuIntensive)
                {
                    return(result);
                }

                return(result ^ List.Aggregate(0, (curr, str) => curr ^ str.GetHashCode()));
            }
Пример #22
0
 void Fun(SomeStruct _s)
 {
     if (_s)
     {
         Debug.Log(true);
     }
     else
     {
         Debug.Log(false);
     }
 }
Пример #23
0
        public void Structs()
        {
            var actual = new SomeStruct {
                Num = 3
            }.ToStringReflection();
            const string expected = "SomeStruct@15 {\n" +
                                    "   Num = 3,\n" +
                                    "}";

            Assert.AreEqual(expected, actual);
        }
Пример #24
0
        public void When_getting_property_names_of_a_struct()
        {
            var model = new SomeStruct();

            var propertyNames = ((object)model).GetPropertyNames(true, false);

            propertyNames.ShouldNotBeNull();
            propertyNames.Length.ShouldBe(2);
            propertyNames[0].ShouldBe("Name");
            propertyNames[1].ShouldBe("Age");
        }
Пример #25
0
        public void NoCloneStatic()
        {
            var o = SomeStruct.NoCloneObj = new object();
            var s = new SomeStruct(5, new object());
            var c = Clone(s);

            Assert.Equal(5, c.Int);
            Assert.NotNull(c.Obj);
            Assert.NotSame(s.Obj, c.Obj);
            Assert.Same(o, SomeStruct.NoCloneObj);
        }
    public void Setup()
    {
        classes = new SomeClass[limit];
        structs = new SomeStruct[limit];

        for (int i = 0; i < limit; i++)
        {
            classes[i] = new SomeClass(i);
            structs[i] = new SomeStruct(i);
        }
    }
Пример #27
0
 void UseSomeStruct()
 {
     SomeStruct[] LotsOfStructs = new SomeStruct[10000000];
     //allocates a bunch of memory.
     // about 40MBs also causes Unity to warn about a
     // memory leak!
     for (int i = 0; i < 10000000; i++)
     {
         LotsOfStructs[i] = new SomeStruct(i);
     }
     //as soon as we exit this function they're all gone.
 }
Пример #28
0
		/// <summary>
		/// SomeStruct[] call on element
		/// </summary>
		public static uint CMPStructArrayCall ()
		{
			SomeStruct [] arr = new SomeStruct [1];
			int i = 0;

			arr [0] = new SomeStruct (42);

			if (arr [i].Value != 42)
				return 0;

			return 1;
		}
Пример #29
0
            public SomeClass(int x, bool cpuIntensive)
            {
                SomeStruct    = new SomeStruct(x, x + 1);
                _cpuIntensive = cpuIntensive;

                for (var i = 0; i < 1000; ++i)
                {
                    List.AddLast(new LinkedListNode <SomeStruct>(new SomeStruct(i, i + 1)));
                }

                Bytes = new byte[1020];
            }
Пример #30
0
    static void Main(string[] args)
    {
        var someStruct = new SomeStruct {
            b1 = 1, b2 = 2, i1 = 3, i2 = 4
        };

        Console.WriteLine("field b1 offset: {0}", GetFieldOffset("b1").Value);
        Console.WriteLine("field b2 offset: {0}", GetFieldOffset("b2").Value);
        Console.WriteLine("field i1 offset: {0}", GetFieldOffset("i1").Value);
        Console.WriteLine("field i2 offset: {0}", GetFieldOffset("i2").Value);

        Console.ReadLine();
    }
Пример #31
0
        public void GetValue_StateUnderTest_ExpectedBehavior()
        {
            // Arrange
            var someStruct = new SomeStruct(TODO, TODO);
            int c          = 0;

            // Act
            var result = someStruct.GetValue(
                c);

            // Assert
            Assert.Fail();
        }
Пример #32
0
        public void TestSimpleSerialization()
        {
            SomeStruct s = new SomeStruct();
            s.header = "dkjkgk";
            s.later = 911100299;
            s.ater = true;
            s.color = HairColor.WHITE;

            r2.CreateTable("characters");
            TableTwo c = r2.GetTable("characters");
            c.AddField<string>("name");
            c.AddField<int>("age");
            c.AddField<HairColor>("hairColor");
            c.AddField<SomeStruct>("other");

            c.CreateRow().Set("name", @"Johann3||¤%¤%&'''\'es").Set("age", 23).Set("hairColor", HairColor.RAT).Set("other", s);
            Console.WriteLine(String.Join("|", c[0].valuesAsStrings));
        }
Пример #33
0
        public void CreatePropertiesFormatter_expands_fields_of_objects()
        {
            var func = new FormatterSet().CreatePropertiesFormatter<SomeStruct>();
            var today = DateTime.Today;
            var tomorrow = DateTime.Today.AddDays(1);
            var id = new SomeStruct
            {
                DateField = today,
                DateProperty = tomorrow
            };

            var value = func(id);

            Console.WriteLine(value);

            Assert.That(value,
                        Contains.Substring("DateField = "));
            Assert.That(value,
                        Contains.Substring("DateProperty = "));
        }
Пример #34
0
        public virtual void GenerateForAllMembers_expands_fields_of_objects()
        {
            var write = Formatter<SomeStruct>.GenerateForAllMembers();
            var today = DateTime.Today;
            var tomorrow = DateTime.Today.AddDays(1);
            var id = new SomeStruct
            {
                DateField = today,
                DateProperty = tomorrow
            };
            var writer = new StringWriter();

            write(id, writer);
            var value = writer.ToString();

            Assert.That(value,
                        Contains.Substring("DateField = "));
            Assert.That(value,
                        Contains.Substring("DateProperty = "));
        }
 public Entity AddSomeStruct(SomeStruct newValue)
 {
     var component = CreateComponent<SomeStructComponent>(ComponentIds.SomeStruct);
     component.value = newValue;
     return AddComponent(ComponentIds.SomeStruct, component);
 }