public void ObjectSerialization() { var obj = new TypeB(a: new ScalarA(""), new Uri("https://example.com/lol"), 3); var obj2 = ModelSerializer.DeserializeObject <TypeB>(ModelSerializer.SerializeObject(obj)); Assert.Equal(obj, obj2); }
public void TestPerf() { TypeA typeA = new TypeA(); for (int i = 0; i < 100; i++) { typeA.param1.Add("Item " + i.ToString()); typeA.param2.Add(i); typeA.param3.Add(i % 2 == 0); typeA.param4.Add(i % 3 == 0); } TypeB typeB = new TypeB(); for (int i = 0; i < 100; i++) { ContainedType inner = new ContainedType(); inner.param1 = "Item " + i.ToString(); inner.param2 = i; inner.param3 = i % 2 == 0; inner.param4 = i % 3 == 0; typeB.containedType.Add(inner); } var model = CreateModel(); RunTestIssue103(5000, typeA, typeB, model, "Runtime"); model.CompileInPlace(); RunTestIssue103(50000, typeA, typeB, model, "CompileInPlace"); RunTestIssue103(50000, typeA, typeB, model.Compile(), "Compile"); }
static void Main(string[] args) { TypeA a = new TypeA(); TypeB b = new TypeB(5); List <SampleObject> fakelistList = new List <SampleObject>() { new SampleObject(1), new SampleObject(2), new SampleObject(3), new SampleObject(4), new SampleObject(5), }; // FAKE DATA SampleObject[] fakelistArray = { new SampleObject(6), new SampleObject(7), new SampleObject(8), new SampleObject(9), new SampleObject(10), }; // FAKE DATA a.Setter(fakelistList); b.Setter(fakelistArray); SampleObjectIterator.GetSampleObject(a.Getter()); SampleObjectIterator.GetSampleObject(b.Getter()); }
// Update is called once per frame void Update() { int power = player.GetComponent <Power>().powerValue; if (Input.GetKeyDown(KeyCode.Z) && (power > 0)) //Disparo tipo A { //If raycast hit some collider if (Physics.Raycast(Camera.main.transform.position, Camera.main.transform.forward, out vision, rayLength)) { Power p = player.GetComponent <Power>(); TypeA ta = vision.collider.gameObject.GetComponent <TypeA>(); if (ta != null) { ta.HandleShoot(p.powerValue); } p.changePower(-1); //Quitamos energía al jugador } } else if (Input.GetKeyDown(KeyCode.X)) //Disparo tipo A { //If raycast hit some collider if (Physics.Raycast(Camera.main.transform.position, Camera.main.transform.forward, out vision, rayLength)) { player.GetComponent <Money>().changeMoney(50); TypeB tb = vision.collider.gameObject.GetComponent <TypeB>(); if (tb != null) { tb.HandleShoot(); } Debug.Log(tb); } } }
public void SimpleContainerTest() { var container = new Container(); container.WithSingleton<TypeA>(); var result = container.GetDependencies(new Type[] { typeof(TypeA) }); Assert.IsTrue(container.AreTypesKnown(new Type[] { typeof(IDependencyResolver) })); Assert.IsNotNull(result); Assert.IsTrue(result.Length == 1); Assert.IsTrue(result[0].GetType() == typeof(TypeA)); Assert.IsTrue(container.GetDependency<TypeA>().GetType() == typeof(TypeA)); Assert.IsTrue(container.GetDependency(typeof(TypeA)).GetType() == typeof(TypeA)); Assert.IsTrue(container.GetDependency<TypeA>().GetHashCode() == container.GetDependency<TypeA>().GetHashCode()); Assert.ThrowsException<InvalidOperationException>(() => container.WithSingleton<TypeA>()); var typeB = new TypeB(); container.WithSingleton(new Lazy<TypeB>(() => typeB)); result = container.GetDependencies(new Type[] { typeof(TypeB) }); Assert.IsNotNull(result); Assert.IsTrue(result.Length == 1); Assert.IsTrue(result[0].GetType() == typeof(TypeB)); Assert.IsTrue(container.GetDependency<TypeB>().GetType() == typeof(TypeB)); Assert.IsTrue(container.GetDependency(typeof(TypeB)).GetType() == typeof(TypeB)); Assert.IsTrue(container.GetDependency<TypeB>().GetHashCode() == container.GetDependency<TypeB>().GetHashCode()); Assert.ThrowsException<InvalidOperationException>(() => container.WithSingleton<TypeB>()); Assert.ThrowsException<InvalidOperationException>(() => container.WithSingleton(new Lazy<TypeB>(() => typeB))); container = new Container(); container.WithType<TypeA>(); result = container.GetDependencies(new Type[] { typeof(TypeA) }); Assert.IsNotNull(result); Assert.IsTrue(result.Length == 1); Assert.IsTrue(result[0].GetType() == typeof(TypeA)); Assert.IsTrue(container.GetDependency<TypeA>().GetType() == typeof(TypeA)); Assert.IsTrue(container.GetDependency(typeof(TypeA)).GetType() == typeof(TypeA)); Assert.IsFalse(container.GetDependency<TypeA>().GetHashCode() == container.GetDependency<TypeA>().GetHashCode()); Assert.ThrowsException<InvalidOperationException>(() => container.WithType<TypeA>()); container = new Container(); Assert.ThrowsException<InvalidOperationException>(() => container.GetDependency<TypeA>()); Assert.ThrowsException<ArgumentNullException>(() => container.GetDependency(null)); Assert.IsNotNull(container.GetDependency<IDependencyResolver>()); container.WithSingleton(new List<string>()); Assert.IsNotNull(container.GetDependency<IList>()); container = new Container(); container.WithType<TypeC>(); Assert.ThrowsException<InvalidOperationException>(() => container.GetDependency<TypeC>()); container.WithType<TypeA>(); Assert.IsNotNull(container.GetDependency<TypeC>()); container.WithType<TypeB>(); Assert.IsNotNull(container.GetDependency<TypeC>()); container = new Container(); container.WithType<TypeD>(); Assert.ThrowsException<InvalidOperationException>(() => container.GetDependency<TypeD>()); }
public void SwitchTypeNoValidCase() { bool executed = false; var item = new TypeB(); item.Switch( SwitchType.Case <TypeA>(() => executed = true)); Assert.False(executed); }
private static void RunTestIssue103(int loop, TypeA typeA, TypeB typeB, TypeModel model, string caption) { // for JIT and preallocation MemoryStream ms = new MemoryStream(); ms.SetLength(0); model.Serialize(ms, typeA); ms.Position = 0; model.Deserialize(ms, null, typeof(TypeA)); Stopwatch typeASer = Stopwatch.StartNew(); for (int i = 0; i < loop; i++) { ms.SetLength(0); model.Serialize(ms, typeA); } typeASer.Stop(); Stopwatch typeADeser = Stopwatch.StartNew(); for (int i = 0; i < loop; i++) { ms.Position = 0; model.Deserialize(ms, null, typeof(TypeA)); } typeADeser.Stop(); ms.SetLength(0); model.Serialize(ms, typeB); ms.Position = 0; TypeB clone = (TypeB)model.Deserialize(ms, null, typeof(TypeB)); Assert.Equal(typeB.containedType.Count, clone.containedType.Count); Stopwatch typeBSer = Stopwatch.StartNew(); for (int i = 0; i < loop; i++) { ms.SetLength(0); model.Serialize(ms, typeB); } typeBSer.Stop(); Stopwatch typeBDeser = Stopwatch.StartNew(); for (int i = 0; i < loop; i++) { ms.Position = 0; model.Deserialize(ms, null, typeof(TypeB)); } typeBDeser.Stop(); Console.WriteLine(caption + " A/ser\t" + (typeASer.ElapsedMilliseconds * 1000 / loop) + " μs/item"); Console.WriteLine(caption + " A/deser\t" + (typeADeser.ElapsedMilliseconds * 1000 / loop) + " μs/item"); Console.WriteLine(caption + " B/ser\t" + (typeBSer.ElapsedMilliseconds * 1000 / loop) + " μs/item"); Console.WriteLine(caption + " B/deser\t" + (typeBDeser.ElapsedMilliseconds * 1000 / loop) + " μs/item"); }
public void SwitchTypeCasePassesToNext() { bool executed = false; var item = new TypeB(); item.Switch( SwitchType.Case <TypeA>(() => throw new Exception("This case should not be executed.")), SwitchType.Case <TypeB>(() => executed = true)); Assert.True(executed); }
public void SwitchDefaultExecuted() { bool executed = false; var item = new TypeB(); item.Switch( SwitchType.Case <TypeA>(() => Expression.Empty()), SwitchType.Default(() => executed = true)); Assert.True(executed); }
public CastSample() { var a = new TypeA(); var b = new TypeB(); TypeA c = new TypeB(); var d = b is TypeA; TypeA e = b; var f = b as TypeA; }
public void default_behaviour_where_nothing_is_specified() { TypeB subject = new TypeB(); ITypeFilter filter = new TypeFilter(new List <Type> { }, new List <Type> { }, new List <Type> { }); Assert.That(filter.Matches(subject), Is.False); }
public static void Main() { var t = new TypeB { Id = 1, name = 15 }; if (t is TypeA) { TypeA a = (TypeA)t; // no error Console.WriteLine(a.Id); // no error } }
public void class_not_matched_by_any() { TypeB subject = new TypeB(); ITypeFilter filter = new TypeFilter(new List <Type> { }, new List <Type> { typeof(TypeA), typeof(IType1) }, new List <Type> { }); Assert.That(filter.Matches(subject), Is.False); }
public void GetStructure(int actorHandle, out TypeB typeA) { int index; if (!_entityLookup.TryGetValue(actorHandle, out index)) { index = _entityLookup.Count; _entityLookup.Add(actorHandle, index); } typeA = this.typeB; }
public void AddStructure(int actorHandle, TypeB comp) { int index; if (!_entityLookup.TryGetValue(actorHandle, out index)) { index = _entityLookup.Count; _entityLookup.Add(actorHandle, index); } typeB = comp; }
static void Main(string[] args) { TypeA typeA = new TypeA(); TypeB typeB = new TypeB(); //Read type of user input. Mimicking dynamic value var inputType = Console.ReadLine(); //Comparison with types. Console.WriteLine(typeA.GetType().Name == inputType); Console.WriteLine(typeB.GetType().Name == inputType); Console.ReadKey(); }
private static void RunTestIssue103(int loop, TypeA typeA, TypeB typeB, TypeModel model, string caption) { // for JIT and preallocation MemoryStream ms = new MemoryStream(); ms.SetLength(0); model.Serialize(ms, typeA); ms.Position = 0; model.Deserialize(ms, null, typeof(TypeA)); Stopwatch typeASer = Stopwatch.StartNew(); for (int i = 0; i < loop; i++) { ms.SetLength(0); model.Serialize(ms, typeA); } typeASer.Stop(); Stopwatch typeADeser = Stopwatch.StartNew(); for (int i = 0; i < loop; i++) { ms.Position = 0; model.Deserialize(ms, null, typeof(TypeA)); } typeADeser.Stop(); ms.SetLength(0); model.Serialize(ms, typeB); ms.Position = 0; TypeB clone = (TypeB)model.Deserialize(ms, null, typeof(TypeB)); Assert.AreEqual(typeB.containedType.Count, clone.containedType.Count); Stopwatch typeBSer = Stopwatch.StartNew(); for (int i = 0; i < loop; i++) { ms.SetLength(0); model.Serialize(ms, typeB); } typeBSer.Stop(); Stopwatch typeBDeser = Stopwatch.StartNew(); for (int i = 0; i < loop; i++) { ms.Position = 0; model.Deserialize(ms, null, typeof(TypeB)); } typeBDeser.Stop(); Console.WriteLine(caption + " A/ser\t" + (typeASer.ElapsedMilliseconds * 1000 / loop) + " μs/item"); Console.WriteLine(caption + " A/deser\t" + (typeADeser.ElapsedMilliseconds * 1000 / loop) + " μs/item"); Console.WriteLine(caption + " B/ser\t" + (typeBSer.ElapsedMilliseconds * 1000 / loop) + " μs/item"); Console.WriteLine(caption + " B/deser\t" + (typeBDeser.ElapsedMilliseconds * 1000 / loop) + " μs/item"); }
public static void Main(string[] s) { var anyMessages = new List <AnyMessage> { new TypeA(), new TypeB(), new TypeC(), }; TypeA a = anyMessages[0]; TypeB b = anyMessages[1]; TypeC c = anyMessages[2]; anyMessages.Add(a); anyMessages.Add(b); anyMessages.Add(c); }
static void Main(string[] args) { var w = new TypeA { i = 8 }; var x = new TypeA { i = 16 }; var y = new TypeB { i = 32 }; var z = new TypeC(); // don't pass this to Test! var l = new List <dynamic> { w, x, y }; Test(l); }
public void Run() { while (true) { TypeA a1 = new TypeA("xinyunlian", 15158155512); TypeA a2 = new TypeA("xinyunlian", 15158155512); TypeA a3 = new TypeA("xinyunlian", 15158155512); TypeB b1 = new TypeB(15158155513); TypeB b2 = new TypeB(15158155513); TypeB b3 = new TypeB(15158155513); Console.WriteLine("creat A,B"); if (Console.ReadKey(true).Key == ConsoleKey.Escape) { return; } GC.Collect(2, GCCollectionMode.Forced); GC.WaitForPendingFinalizers(); Console.WriteLine("GC.Collect complet"); } }
public Type createType(string type) { Type returnType = null; switch (type) { case "A": returnType = new TypeA(); break; case "B": returnType = new TypeB(); break; case "C": returnType = new TypeC(); break; } return(returnType); }
public ChannelModeType GetModeType(char mode) { if (TypeA.IndexOf(mode) > -1) { return(ChannelModeType.TypeA); } if (TypeB.IndexOf(mode) > -1) { return(ChannelModeType.TypeB); } if (Statuses.IndexOf(mode) > -1) { return(ChannelModeType.TypeB); } if (TypeC.IndexOf(mode) > -1) { return(ChannelModeType.TypeC); } if (TypeD.IndexOf(mode) > -1) { return(ChannelModeType.TypeD); } return(ChannelModeType.Unknown); }
public void SetAB(TypeA a, TypeB b) { AValue = a; BValue = b; }
public MultiConstructorType(TypeA a, TypeB b, TypeC c, TypeD d, TypeE e) { }
public MultiConstructorType(TypeA a, TypeB b, TypeC c) { }
AnyMessage(TypeB b) { B = b; }
static void Foo(TypeB x) { Console.WriteLine("Foo(TypeB)"); }
public void DoSomething(TypeB fooB) { }
static async Task Main(string[] args) { var client = new MongoClient("mongodb://localhost:27017"); var mongoDatabase = client.GetDatabase("test_db"); var typeACollection = mongoDatabase.GetTypedCollection <TypeA>("test_mix"); typeACollection.CreateTypedKeyIndex(); var typeBCollection = mongoDatabase.GetTypedCollection <TypeB>("test_mix"); typeBCollection.CreateTypedKeyIndex(); var typeCCollection = mongoDatabase.GetTypedCollection <TypeC>("test_mix"); typeCCollection.CreateTypedKeyIndex(); var typeAFilter = MongoDbHelper.CreateTypedFilter <TypeA>(); var typeBFilter = MongoDbHelper.CreateTypedFilter <TypeB>(); var typeCFilter = MongoDbHelper.CreateTypedFilter <TypeC>(); #region Read Demo Console.WriteLine("=== Read Test ==="); var typeACount = typeACollection.CountDocuments(typeAFilter); var typeBCount = typeBCollection.CountDocuments(typeBFilter); var typeCCount = typeCCollection.CountDocuments(typeCFilter); Console.WriteLine($"TypeA count={typeACount}, TypeB count={typeBCount}, TypeC count={typeCCount}"); await PrintCollection(typeACollection, typeAFilter); await PrintCollection(typeBCollection, typeBFilter); await PrintCollection(typeCCollection, typeCFilter); #endregion #region Write Demo Console.WriteLine("\r\n=== Write Test ==="); Console.ReadLine(); var newBObj = new TypeB { Type = "TypeB", Prop1 = Guid.NewGuid(), ValueB = "TestB 2" }; await typeBCollection.InsertOneAsync(newBObj); Console.WriteLine("Inserted TypeB collection:"); await PrintCollection(typeBCollection, typeBFilter); #endregion #region Update Demo Console.WriteLine("\r\n=== Update Test ==="); Console.ReadLine(); Console.WriteLine("Origin TypeC collection:"); await PrintCollection(typeCCollection, typeCFilter); var typeC1st = typeCCollection.TypedFindFluent().First(); var targetFilter = typeCFilter & typeCCollection.TypedFilterBuilder().Eq(nameof(TypeC.Prop1), typeC1st.Prop1); var update = typeCCollection.TypedUpdateBuilder().Set(nameof(TypeC.Prop1), typeC1st.Prop1 + 1); var updateResult = await typeCCollection.UpdateOneAsync(targetFilter, update); Console.WriteLine($"Update on \"TypeC\" collection, updateResult= {updateResult}"); Console.WriteLine("Modified TypeC collection:"); await PrintCollection(typeCCollection, typeCFilter); #endregion #region Delete Demo Console.WriteLine("\r\n=== Delete Test ==="); Console.ReadLine(); Console.WriteLine("Origin TypeB collection:"); await PrintCollection(typeBCollection, typeBFilter); var newBObjFilter = typeBFilter & typeBCollection.TypedFilterBuilder().Eq(nameof(TypeB.ValueB), newBObj.ValueB); var deleteResult = typeBCollection.DeleteOne(newBObjFilter); Console.WriteLine($"Delete on \"TypeB\" collection, deleteResult= {deleteResult}"); Console.WriteLine("Modified TypeB collection:"); await PrintCollection(typeBCollection, typeBFilter); #endregion }
static int Main_old() { try { TypeA Interface_TestClass_explicit_25_2 = new TypeA(); TypeB b = new TypeB(); Interface_TestClass_explicit_25_A Interface_TestClass_explicit_25_1 = new Interface_TestClass_explicit_25_A(); if (((Interface_TestClass_explicit_25_I3)Interface_TestClass_explicit_25_1).foo(Interface_TestClass_explicit_25_2) != 1) return 1; if (((Interface_TestClass_explicit_25_I3)Interface_TestClass_explicit_25_1).foo(b) != 2) return 1; return 0; } catch (System.Exception) { return 1; } }
int Interface_TestClass_explicit_25_I3.foo(TypeB b) { return 2; }
public void Main(TypeA new_args1, TypeB new_args2) { var b = new B(new_args1, new_args2); var a = new A(b); }
public A(TypeA args1, TypeB args2) { _b = new B(args1, args2); }
public B(TypeA new_args1, TypeB new_args2) { }
void MyFun(TypeB a, TypeB b, TypeB c, TypeB d) { base.MyFun(a, b, c, d) }