static void Main(string[] args) { // Instance anExample does not send an argument for the constructor's // optional parameter. ExampleClass anExample = new ExampleClass(); anExample.ExampleMethod(1, "One", 1); anExample.ExampleMethod(2, "Two"); anExample.ExampleMethod(3); // Instance anotherExample sends an argument for the constructor's // optional parameter. ExampleClass anotherExample = new ExampleClass("Provided name"); anotherExample.ExampleMethod(1, "One", 1); anotherExample.ExampleMethod(2, "Two"); anotherExample.ExampleMethod(3); // The following statements produce compiler errors. // An argument must be supplied for the first parameter, and it // must be an integer. //anExample.ExampleMethod("One", 1); //anExample.ExampleMethod(); // You cannot leave a gap in the provided arguments. //anExample.ExampleMethod(3, ,4); //anExample.ExampleMethod(3, 4); // You can use a named parameter to make the previous // statement work. anExample.ExampleMethod(3, optionalint: 4); }
public void AlwaysReturnsGivenInstance() { var instance = new ExampleClass(); var policy = new SpecifiedInstanceLifetimePolicy(instance); Assert.AreEqual(instance, policy.GetInstance()); Assert.AreEqual(instance, policy.GetInstance()); }
public void RoundTrip() { var serializer = new FudgeSerializer(context); var obj1 = new ExampleClass(7); var msg = serializer.SerializeToMsg(obj1); var obj2 = (ExampleClass)serializer.Deserialize(msg); Assert.NotSame(obj1, obj2); Assert.Equal(obj1.Number, obj2.Number); }
static void Main(string[] args) { ExampleClass ec = new ExampleClass(); // The following call to exampleMethod1 causes a compiler error // if exampleMethod1 has only one parameter. Uncomment the line // to see the error. //ec.exampleMethod1(10, 4); dynamic dynamic_ec = new ExampleClass(); // The following line is not identified as an error by the // compiler, but it causes a run-time exception. dynamic_ec.exampleMethod1(10, 4); // The following calls also do not cause compiler errors, whether // appropriate methods exist or not. //dynamic_ec.someMethod("some argument", 7, null); //dynamic_ec.nonexistentMethod(); }
public async Task You_Should_Be_Able_To_Compile_Without_An_Example_Object_With_Partials_And_Settings() { var stubble = new StubbleCompilationRenderer(); var settings = new CompilationSettings { ThrowOnDataMiss = true }; var partials = new Dictionary <string, string> { { "Partial", "{{Foo}}" } }; var input = new ExampleClass { Foo = "Bar" }; var func = stubble.Compile <ExampleClass>("{{> Partial}}", partials, settings); var funcAsync = await stubble.CompileAsync <ExampleClass>("{{> Partial}}", partials, settings); Assert.Equal("Bar", func(input)); Assert.Equal("Bar", funcAsync(input)); }
public static void Test() { //可以從物件Serialize到Ini ExampleClass example = new ExampleClass(); example.StringField = "Hello World"; example.IntField = 1234567890; example.DoubleField = 3.1415926; example.SizeField = new Size(100, 100); example.RectangleField = new Rectangle(1, 2, 3, 4); example.PointField = new Point(5, 6); example.InnerClassField = new ExampleClass.InnerClass(); example.InnerClassField.StringField = "InnerClass String"; example.InnerClassField.IntField = 1000; example.InnerClassField.IntField2 = 2000; example.InnerClassField.DoubleField = 3000; IniWriter writer = new IniWriter(); writer.Serialize(example); String str = writer.ToString(); }
public void ExampleRepository_WhenCalled_InsertsAObjectOnDatabase() { // Arrange // Arrange var testObject = new ExampleClass(); var context = new Mock <DbContext>(); var dbSetMock = new Mock <DbSet <ExampleClass> >(); context.Setup(x => x.Set <ExampleClass>()).Returns(dbSetMock.Object); dbSetMock.Setup(x => x.Add(It.IsAny <ExampleClass>())).Returns(testObject); // Act var repository = new ExampleRepository(context.Object); repository.Inserir(testObject); //Assert context.Verify(x => x.Set <ExampleClass>()); dbSetMock.Verify(x => x.Add(It.Is <ExampleClass>(y => y == testObject))); }
static void Main(string[] args) { var exampleClassFieldProperties = GetExampleClassFieldProperties(); var lines = File.ReadAllLines("datafile.txt"); var records = new List <ExampleClass>(); foreach (var line in lines) { var fields = line.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries); var record = new ExampleClass(); for (int fieldIndex = 0; fieldIndex < fields.Length; fieldIndex++) { if (exampleClassFieldProperties.ContainsKey(fieldIndex)) { ReadValueFromFile(fields[fieldIndex], exampleClassFieldProperties[fieldIndex], record); } } records.Add(record); } Console.WriteLine("Press any key to continue"); Console.ReadKey(); }
public static void SerializedToJson() { Console.WriteLine($"===========Attributes example(HW10 SerializedToJson)============"); Console.WriteLine("Create new object exampleClass"); ExampleClass exampleClass = new ExampleClass { ClassName = "ExampleClass1" }; exampleClass.MyClassExec(); exampleClass.UpdateExecDate(new DateTime(2020, 01, 01)); exampleClass.MyClassExec(); using (FileStream stream = new FileStream(@"D:\ExampleClass.txt", FileMode.OpenOrCreate)) { JsonSerializer.SerializeAsync <ExampleClass>(stream, exampleClass, new JsonSerializerOptions { IncludeFields = true }); } Console.WriteLine("Object was serialized to Json"); }
static void Main(string[] args) { var benchmarks = new[] { new { Name = "Standard Cloning", Action = new Action(() => Benchmarker.Benchmark <ExampleClass>( ExampleClass.GenerateExampleObject() )) }, new { Name = "Non-Generic List", Action = new Action(() => Benchmarker.Benchmark( ExampleOldSchoolList.GenerateExampleObject() )) } }; Console.WriteLine("Which benchmark?"); for (var i = 0; i < benchmarks.Length; i++) { Console.WriteLine(" {0} - {1}", i, benchmarks[i].Name); } var which = int.Parse(Console.ReadLine()); while (true) { benchmarks[which].Action(); } }
public async Task <ExampleClassResponse> UpdateAsync(int id, ExampleClass exampleClass) { //Similar to DeleteAsync var existingExampleClass = await _exampleClassRepository.FindById(id); if (existingExampleClass == null) { return(new ExampleClassResponse("ExampleClass not found")); } //Diferent from DeleteAsync existingExampleClass.Data = exampleClass.Data; try { //Diferent from DeleteAsync _exampleClassRepository.Update(existingExampleClass); await _unitOfWork.CompleteAsync(); return(new ExampleClassResponse(existingExampleClass)); } catch (Exception ex) { return(new ExampleClassResponse($"An error ocurred while deleting ExampleClass: {ex.Message}")); } }
static async void ShowSerialization() { Console.WriteLine($"===========Attributes example(HW10 SerializedToJson)============"); Console.WriteLine("Create new object exampleClass"); ExampleClass exampleClass = new ExampleClass { ClassName = "MyClass" }; exampleClass.MyClassExec(); exampleClass.UpdateExecDate(new DateTime(2021, 02, 01)); exampleClass.MyClassExec(); SerializedExample <ExampleClass> .SerializedToJson(exampleClass); Console.WriteLine("Press key to continue"); Console.ReadKey(); Console.WriteLine($"===========Attributes example(HW10 DeSerializedFromJson)============"); ExampleClass exampleClassNew = await SerializedExample <ExampleClass> .DeSerializedFromJson(); exampleClassNew.MyClassExec(); Console.ReadKey(); }
public void Remove(ExampleClass exampleClass) { _context.ExampleClasses.Remove(exampleClass); }
//CRUD methods implemented public async Task AddAsync(ExampleClass exampleClass) { await _context.ExampleClasses.AddAsync(exampleClass); }
void Start() { ExampleClass.number = 1; ExampleClass.Hello(); }
public LoggerWithConstructor(ExampleClass item) { }
public Dictionary <int, string[]> Resolve(ExampleClass source, ExampleClass destination, Dictionary <int, string[]> member, ResolutionContext context) { // logic to iterate through the dictionarys and resolve into dictionary containing values that you want. }
public void Setup() { example = new ExampleClass(2, 3.14f); }
public void TriggerExceptionCrash() { ExampleClass library = new ExampleClass(); library.ForceAppCrash((Activity)Forms.Context); }
public void RegisterTypes(IContainerRegistry containerRegistry) { var test = new ExampleClass(); containerRegistry.RegisterInstance <IExampleClass>(test); }
public void Update(ExampleClass exampleClass) { _context.ExampleClasses.Update(exampleClass); }
static void Main(string[] args) { ExampleClass ec = new ExampleClass(); int i = ec.Method1; }
public SubSubExampleClass(ExampleClass parent) { this.parent = parent; // save reference to the parent object }
private static int ShimInstanceTestMethod(ExampleClass @this, int a) { Assert.NotNull(@this); return(a); }
public ActionResult Index(ExampleClass model) { return(View()); }
static void Main(string[] args) { //const int size = 1000 * 1000; //// var empty = new Empty(); //var before = GC.GetTotalMemory(true); //var empty = new Empty(); //var after = GC.GetTotalMemory(true); //var diff = after - before; //Console.WriteLine("空对象内存大小:" + diff); //GC.KeepAlive(empty); //// 数组对象 //var array = new Empty[size]; //before = GC.GetTotalMemory(true); //for (int i = 0; i < size; i++) { // array[i] = new Empty(); //} //after = GC.GetTotalMemory(true); //diff = after - before; //Console.WriteLine("数组空对象内存带下:" + diff / size); //GC.KeepAlive(array); //var vt = new ValueTypeBox(); //vt.Name = "summer zhu"; //InvokeWithStructClass(vt); //Console.WriteLine(vt.Name); //// 值类型当参数传递 //void InvokeWithStructClass(ValueTypeBox box) { // box.Name = "marson shine"; // Console.WriteLine(box.Name); //} //// for vs foreach //int[] arr = new int[100]; //for (int i = 0; i < arr.Length; i++) { // arr[i] = i; //} //int sum = 0; //foreach (var val in arr) { // sum += val; //} //sum = 0; //IEnumerable<int> arrEnum = arr; //foreach (var val in arrEnum) { // sum += val; //} //AvoidMemoryAlloctation.Start(); // dump 分析 var ec = new ExampleClass(); var ecg = new ExampleGenericClass <object>(); // 通过按值传递返回关键来避免装箱,值拷贝等消耗 TestMagnitude(); ZeroMiddleValue(new[] { 1, 2, 3, 4, 5, 6 }); RefZeroMiddleValue(new[] { 1, 2, 3, 4, 5, 6 }); var v = new Vector2() { Location = new Point3d { Name = "l", x = 2, y = 2, z = 2 } }; SetVectorToOrigin(v); RefSetVectorToOrigin(v); }
public EventExam1() { ExampleClass obj = new ExampleClass(); ExamEvent += new ClickEvent(obj.OnClick); }
public ExampleClass ObjectEcho(ExampleClass obj) { return(obj); }
public static void Main() { ExampleClass ex = new ExampleClass(); ex.ShowDuration(); }
static void Main(string[] args) { ExampleClass ec = new ExampleClass(); ec = ExampleClass.Method2; }
public ExampleClass ObjectEcho(ExampleClass obj) { return obj; }
public ExampleClassTest() { _exampleClass = new ExampleClass(); }
public static void Process(ExampleClass exampleClass) { Thread.Sleep(100); }
public void TestExampleClass_ExampleMethod() { var result = new ExampleClass().ExampleMethod(); Assert.True(result); }
private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e) { var ex = new ExampleClass(); ex.Dowork(ReportProgresshandler); }