public void TestGetTextProperty() { const string textValue = "Mock Serialized String"; var values = new List<string> { "Foo string 1", "Foo string 2" }; var obj = new ClassA { Foo = "Foo String", ElementsBlobbed = textValue }; var mockSerializer = new Mock<ITextBlobSerializer>(); TextBlobOperations.SetTextSerializer(mockSerializer.Object); // Override default JSON serializer var obj1 = obj; var elementsProperty = typeof (ClassA).GetProperty("Elements"); mockSerializer.Setup(serializer => serializer.Deserialize(textValue, elementsProperty.PropertyType)).Returns(() => values); TextBlobOperations.GetTextBlobChild(obj, typeof(ClassA).GetProperty("Elements")); Assert.AreEqual(values, obj1.Elements); }
public void SingleIndexWithMultipleTypes() { var data = Enumerable.Range(0, 100) .Select(i => { MyBaseClass o = null; if (i % 2 == 0) o = new ClassA() { ClassAProperty = Guid.NewGuid().ToString() }; else o = new ClassB() { ClassBProperty = Guid.NewGuid().ToString() }; o.Title = Guid.NewGuid().ToString(); return o; }); var result = this._client.IndexMany(data, new SimpleBulkParameters { Refresh = true }); result.IsValid.Should().BeTrue(); result.Items.Count().Should().Be(100); var queryResults = this._client.Search<MyBaseClass>(s => s .From(0) .Size(100) .MatchAll() .ConcreteTypeSelector((o, h) => o.classBProperty != null ? typeof(ClassB) : typeof(ClassA)) ); Assert.True(queryResults.IsValid); Assert.True(queryResults.Documents.Any()); queryResults.Documents.OfType<ClassA>().Any().Should().BeTrue(); queryResults.Documents.OfType<ClassB>().Any().Should().BeTrue(); }
public void MultipleTypesUsingBaseClass() { var data = Enumerable.Range(0, 100) .Select(i => { MyBaseClass o = null; if (i % 2 == 0) o = new ClassA() { ClassAProperty = Guid.NewGuid().ToString() }; else o = new ClassB() { ClassBProperty = Guid.NewGuid().ToString() }; o.Title = Guid.NewGuid().ToString(); return o; }); var resulta = this._client.IndexMany(data.OfType<ClassA>(), new SimpleBulkParameters { Refresh = true }); var resultb = this._client.IndexMany(data.OfType<ClassB>(), new SimpleBulkParameters { Refresh = true }); var queryResults = this._client.Search<MyBaseClass>(s => s .Types(typeof(ClassA), typeof(ClassB)) .From(0) .Size(100) .MatchAll() ); Assert.True(queryResults.IsValid); Assert.True(queryResults.Documents.Any()); queryResults.Documents.OfType<ClassA>().Any().Should().BeTrue(); queryResults.Documents.OfType<ClassB>().Any().Should().BeTrue(); }
public void Contains_ReturnsFalse_ForObjectNotInCache() { var objA = new ClassA(); var objB = new ClassA(); cache.Add(objA); Assert.IsFalse(cache.Contains(objB)); }
public void AnnotateNonOwnedProperty() { var targetA = new ClassA(); var targetB = new ClassB(); targetA.Annotate(() => targetB.FirstName, Suffix => "Mr"); Assert.AreEqual("Mr", targetA.Annotation<string>(() => targetB.FirstName, "Suffix")); }
static void Main(string[] args) { Checker check = new Checker(); ClassA try1 = new ClassA(); ClassB try2 = new ClassB(); ClassC try3 = new ClassC(); ClassD try4 = new ClassD(); MyStruct try5 = new MyStruct(); object try6 = try5; Console.WriteLine("Analyzing ClassA type variable:"); // Анализ переменной типа ClassA check.Check(try1); Console.WriteLine("\nAnalyzing ClassB type variable:"); // Анализ переменной типа ClassB check.Check(try2); Console.WriteLine("\nAnalyzing ClassC type variable:"); // Анализ переменной типа ClassC check.Check(try3); Console.WriteLine("\nAnalyzing ClassD type variable:"); // Анализ переменной типа ClassD check.Check(try4); Console.WriteLine("\nAnalyzing MyStruct type variable:"); // Анализ переменной типа MyStruct check.Check(try5); Console.WriteLine("\nAnalyzing boxed MyStruct type variable:"); // Анализ упакованной check.Check(try6); Console.ReadKey(); }
public void execute() { ClassA a = new ClassA(); a.addCallBack(myCallBack); ClassB b = new ClassB(); }
public void execute() { ClassB b = new ClassB(); ClassA a = new ClassA(); b = a; }
public void execute() { ClassA<ClassC> a = new ClassA<ClassC>(); ClassB<ClassC> b = new ClassB<ClassC>(); a = b; }
public void execute() { ClassA a = new ClassA(); ClassB b = new ClassB(); ClassC<ClassA> ca = new ClassC<ClassA>(); ca.result(test); }
public void execute() { ClassA a = new ClassA(); a.addCallBack(myCallBack); ClassB b = new ClassB(); b.process(callbackAction); }
public void TestAddInt () { var one = new ClassA (10); var two = one + 1; Assert.AreEqual (one.Value + 1, two.Value); }
public void execute() { ClassA a = new ClassA(); a.addCallBack(myCallBack); a.addActionCallBack(callbackAction); }
public void RegisterInstanceGeneric() { var obj = new ClassA (); ServiceContainer.Register (obj); Assert.That (ServiceContainer.Resolve<ClassA>(), Is.EqualTo (obj)); }
public void RegisterInterface() { var obj = new ClassA (); ServiceContainer.Register<InterfaceA> (obj); Assert.That (ServiceContainer.Resolve<InterfaceA> (), Is.EqualTo (obj)); }
public void T02_Dispose_Instance() { var container = new Container(defaultLifestyle: DefaultLifestyle.Singleton, log: Write); var instance = new ClassA(); container.RegisterInstance(instance); container.Dispose(); Assert.True(instance.IsDisposed); }
public void AccessAnnotationDirectly() { var target = new ClassA(); target.Annotation()["Tags"] = new[] {"C#", "Tests"}; CollectionAssert.AreEqual(target.Annotation<string[]>("Tags"), new[] {"C#", "Tests"}); }
public void execute() { ClassA<ClassC> ac = new ClassB<ClassC>(); ClassA<ClassD> a2 = new ClassA<ClassD>(); a2 = a1; }
public void ShouldMatchAnyExpression() { var r = CreateReport(); var o = new ClassA(); //Simulate an error occuring on ClassA r.AddError(new ValidationError(CreateRule(), EquatableExpression.Create<ClassA, int>(a => a.A), new object[0], o, o, EquatableExpression.Create<ClassA, int>(a => a.A))); //Passing in null should match any errors on any expressions... Assert.IsTrue(r.HasError(o, null)); }
public void execute() { ClassA<string> a1 = new ClassB<ClassC>(); ClassA<object> a2 = new ClassA<object>(); a2 = a1; }
public void execute() { ClassA a = new ClassA(); ClassB b = new ClassB(); ClassC<ClassA> ca = new ClassC<ClassA>(); }
public void TestPreDecrement () { var one = new ClassA (10); var two = --one; Assert.AreEqual (9, one.Value); Assert.AreEqual (9, two.Value); }
public void TestPreIncrement () { var one = new ClassA (10); var two = ++one; Assert.AreEqual (11, one.Value); Assert.AreEqual (11, two.Value); }
public void TestPostDecrement () { var one = new ClassA (10); var two = one--; Assert.AreEqual (9, one.Value); Assert.AreEqual (9, two.Value); }
public void TestAdd () { var one = new ClassA (10); var two = new ClassA (10); var three = one + two; Assert.AreEqual (one.Value + two.Value, three.Value); }
public void execute() { ClassA a = new ClassA(); a.addCallBack(myCallBack); //for regular processing , its always actions a.addActionCallBack(callbackAction); a.addFuncCallBack(addFuncCallBack); }
public void Add_ReturnsUniqueId_ForEachObjectAdded() { var objA = new ClassA(); var objB = new ClassA(); var idA = cache.Add(objA); var idB = cache.Add(objB); Assert.AreNotEqual(idA, idB); Assert.AreEqual(idA, cache.GetID(objA)); Assert.AreEqual(idB, cache.GetID(objB)); }
public void WhenPropertyInTargetObjectHasWrongTypeThenExceptionIsRaised() { var classA = new ClassA(1, "Test"); var classAWithWrongPropType = new ClassAWithWrongPropType(1, "Test"); Assert.Throws<InvalidCastException>(() => { classA.If().PropertyValuesMatch(classAWithWrongPropType).ThenReturn(true); }); }
public void RegisterInstance() { var container = new Container(); var a = new ClassA(); container.RegisterInstance(a); var b = container.Resolve<ClassA>(); Assert.IsNotNull(a); Assert.AreSame(a, b); }
public void WhenMissingPropertyInTargetObjectThenExceptionIsRaised() { var classA = new ClassA(null, "Test"); var classAMissingProp = new ClassAWithMissingProp("Test"); Assert.Throws<MissingMemberException>(() => { classA.If().PropertyValuesMatch(classAMissingProp).ThenReturn(true); }); }
public static ClassB ParseAToB(ClassA a) { return(new ClassB { OtherNumber = a.SomeNumber, OtherString = a.SomeString }); }
public void MapObjects() { // Unknown mapping { var mapper = new ObjectMapper(); var from = new ClassA() { Age = 11, Name = "Joe Smith", Time = new DateTime(2010, 1, 1), }; var to = new ClassB(); AssertEx.Throws <InvalidOperationException>(() => { mapper.MapObjects(from, to); }); } // Nulls { var mapper = new ObjectMapper(); mapper.AddMapping(this.GetMapping()); ClassA from = null; ClassB to = null; AssertEx.Throws <ArgumentNullException>(() => { mapper.MapObjects(from, to); }); from = new ClassA() { Age = 11, Name = "Joe Smith", Time = new DateTime(2010, 1, 1), }; AssertEx.Throws <ArgumentNullException>(() => { mapper.MapObjects(from, to); }); } // Known mapping { var mapper = new ObjectMapper(); mapper.AddMapping(this.GetMapping()); var from = new ClassA() { Age = 11, Name = "Joe Smith", Time = new DateTime(2010, 1, 1), }; var to = new ClassB(); mapper.MapObjects(from, to); Assert.AreEqual(from.Age, to.Age); Assert.AreEqual(from.Name, to.FullName); Assert.IsNull(to.City); } }
public void TestNotNull() { TryCatch(() => { var testObject = new ClassA { NameA = "A.1", ClassBs = new List <ClassB> { new ClassB { NameB = "A1.B1", ClassCs = new List <ClassC> { new ClassC { NameC = "A1.B1.C1" }, new ClassC { NameC = "A1.B1.C2" }, new ClassC { NameC = "A1.B1.C3" }, new ClassC { NameC = "A1.B1.C4" } } }, new ClassB { NameB = "A1.B2", ClassCs = new List <ClassC> { new ClassC { NameC = "A1.B2.C1" }, new ClassC { NameC = "A1.B2.C2" } } }, new ClassB { NameB = "A1.B3", ClassCs = new List <ClassC> { new ClassC { NameC = "A1.B3.C1" }, new ClassC { NameC = "A1.B3.C2" }, new ClassC { NameC = "A1.B3.C3" } } } } }; { WriteLine("F"); var items = testObject.ClassBs.SelectMany(b => b.ClassCs.Select(c => c.NameC)).Distinct(); foreach (var item in items) { Dump(item); } } { WriteLine("C.NameC.Contains(\"C1\")"); var items = testObject.ClassBs.SelectMany(b => b.ClassCs.Where(c => c.NameC.Contains("C1")).Select(c => c.NameC)); foreach (var item in items) { Dump(item); } } }); }
public static void method3(this ClassA classA) { }
static void Main(string[] args) { // 封箱&拆箱 // struct MyStruct valType1 = new MyStruct(); valType1.Val = 5; // object 对象副本的引用 object refType = valType1; // 封箱 valType1.Val = 6; MyStruct valType2 = (MyStruct)refType; // 拆箱 Console.WriteLine($"valType2.Val = {valType2.Val}"); // class MyClass1 valType3 = new MyClass1(); valType3.Val = 5; object refType2 = valType3; valType3.Val = 6; MyClass1 valType4 = (MyClass1)refType2; Console.WriteLine($"valType4.Val = {valType4.Val}"); // struct 实现接口将值类型封箱到接口类型 MyStruct valType5 = new MyStruct(); valType5.Val = 5; IMyInterface refType3 = valType5; valType5.Val = 6; MyStruct valType6 = (MyStruct)refType3; Console.WriteLine($"valType6.Val = {valType6.Val}"); Console.WriteLine(); // is // <operand> is <type> Checker check = new Checker(); ClassA try1 = new ClassA(); ClassB try2 = new ClassB(); ClassC try3 = new ClassC(); ClassD try4 = new ClassD(); MyStruct try5 = new MyStruct(); object try6 = try5; Console.WriteLine("Analyzing ClassA type variable:"); check.Check(try1); Console.WriteLine("\nAnalyzing ClassB type variable:"); check.Check(try2); Console.WriteLine("\nAnalyzing ClassC type variable:"); check.Check(try3); Console.WriteLine("\nAnalyzing ClassD type variable:"); check.Check(try4); Console.WriteLine("\nAnalyzing MyStruct type variable:"); check.Check(try5); Console.WriteLine("\nAnalyzing boxed MyStruct type variable:"); check.Check(try6); Console.WriteLine(); // 值比较 // 运算符重载 AddClass1 op1 = new AddClass1(); op1.val = 5; AddClass1 op2 = new AddClass1(); op2.val = 5; bool isSame = op1 == op2; // 是否引用同一个对象, 非验证值相等 AddClass1 op3 = op1 + op2; AddClass1 op4 = -op1; Console.WriteLine($"isSame = {isSame}."); Console.WriteLine($"op1.val + op2.val = {op3.val}."); Console.WriteLine($"-op1.val = {op4.val}."); Console.WriteLine(); // 列表排序 ArrayList list = new ArrayList(); list.Add(new Person("Rual", 30)); list.Add(new Person("Donna", 25)); list.Add(new Person("Mary", 27)); list.Add(new Person("Ben", 44)); Console.WriteLine("Unsorted people:"); for (int i = 0; i < list.Count; i++) { Console.WriteLine($"{(list[i] as Person).Name} ({(list[i] as Person).Age})"); } Console.WriteLine(); Console.WriteLine("People sorted with nondefault comparer (by name):"); list.Sort(PersonComparerName.Default); for (int i = 0; i < list.Count; i++) { Console.WriteLine($"{(list[i] as Person).Name} ({(list[i] as Person).Age})"); } // 转换 ConvClass1 conv1 = new ConvClass1(); conv1.val = 3; ConvClass2 conv2 = conv1; // implicit 隐式转换 ConvClass2 conv3 = new ConvClass2(); conv3.val = 3; // conv3.val = 3e15; // System.OverflowException ConvClass1 conv4 = (ConvClass1)conv3; // explicit 显式转换 // as Console.WriteLine(); AsClassA MyAnimal = new AsClassA(); AsClassD MyCow = MyAnimal as AsClassD; // MyAnimal ==null AsClassD MyCow2 = new AsClassD(); AsClassA MyAnimal2 = MyCow2; AsClassD MyNewCow2 = MyAnimal2 as AsClassD; // MyNewCow2 包含 MyCow2引用 MyCow2.MilkCow(MyCow2); MyCow2.MilkCow(MyNewCow2); Console.ReadKey(); }
public ClassB(ClassA classA) { this.classA = classA; }
public void ClassBMethod() { ClassA classAInstance = new ClassA(); classAInstance.ClassAMethod(); }
public static ClassA Write(ClassA c1, ClassA c2) { return(c1); }
public void MultipleTypesUsingBaseClassMultiSearch() { var data = Enumerable.Range(0, 100) .Select(i => { MyBaseClass o = null; if (i % 2 == 0) { o = new ClassA() { ClassAProperty = Guid.NewGuid().ToString() } } ; else { o = new ClassB() { ClassBProperty = Guid.NewGuid().ToString() } }; o.Title = Guid.NewGuid().ToString(); return(o); }); var resulta = this._client.IndexMany(data.OfType <ClassA>(), new SimpleBulkParameters { Refresh = true }); var resultb = this._client.IndexMany(data.OfType <ClassB>(), new SimpleBulkParameters { Refresh = true }); var queryResults = this._client.MultiSearch(ms => ms .Search <MyBaseClass>("using_types", s => s.AllIndices() .Types(typeof(ClassA), typeof(ClassB)) .From(0) .Size(100) .MatchAll() ) .Search <MyBaseClass>("using_selector", s => s.AllIndices() .Types("classas", "classbs") .ConcreteTypeSelector((o, h) => o.classBProperty != null ? typeof(ClassB) : typeof(ClassA)) .From(0) .Size(100) .MatchAll() ) ); Assert.True(queryResults.IsValid); var firstResult = queryResults.GetResponse <MyBaseClass>("using_types"); Assert.True(firstResult.Documents.Any()); firstResult.Documents.OfType <ClassA>().Any().Should().BeTrue(); firstResult.Documents.OfType <ClassB>().Any().Should().BeTrue(); var secondResult = queryResults.GetResponse <MyBaseClass>("using_selector"); Assert.True(secondResult.Documents.Any()); secondResult.Documents.OfType <ClassA>().Any().Should().BeTrue(); secondResult.Documents.OfType <ClassB>().Any().Should().BeTrue(); }
void Start() { ClassA instance = new ClassA(gameObject); instance.Foo(new Vector3(10.5f, 15.2f, 20.8f)); }
public void setLink(ClassA x) { _classA.Entity = x; }
public ClassC(ClassA a, ClassB b) => (ClsA, ClsB) = (a, b);
public virtual void SetClassA(ClassA classA) { this.classA = classA; }
public void CreateGetter(ClassA classA) { var getter = LambdaCompiler.CreateGetter <ClassA, string>("P1"); Assert.True(classA.P1 == getter(classA)); }
public static void Main() { ClassA objA = new ClassA(); }
public void TestMethod(out ClassA <TT> enter) { enter = null; }
public static void SaveToFile(this ClassA obj) { // write your saving logic here. // obj will represent your current instance of ClassA on which you're invoking the method. SaveToFile(obj). }
protected override bool InsertRecord(string[] entries) { bool wasInserted = false; connec = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source= " + GetDirectory() + userDir + MAIN_USER_DATABASE + ";"); string command = GetCommandString(Command.INSERT); OleDbCommand cmd = new OleDbCommand(command, connec); { int i = 1; string prodDesc = ""; if (entries.Length > 0) { prodDesc = MyUtilities.clean(entries[0]).Trim(); } for (int j = 0; j < entries.Length && i < FIELDS.Length; j++) { if (mode.Equals("Standard")) { while (i < FIELDS.Length && ADVANCED_FIELDS[i]) { i++; } } if (i < FIELDS.Length) { string value = MyUtilities.clean(entries[j]); if (value.Trim().Length > 0) { value = value.Trim(); } if (CHECKBOXES[i]) { value = value.ToLower().Equals("true") ? "1" : "0"; } if (FIELDS[i].Equals("LaborDesc") || FIELDS[i].Equals("EquipDesc") || FIELDS[i].Equals("ProdDesc") || FIELDS[i].Equals("OpNam")) { value = value.ToUpper(); } cmd.Parameters.AddWithValue(FIELDS[i], value); i++; } } try { connec.Open(); int result = cmd.ExecuteNonQuery(); wasInserted = true; connec.Close(); this.SetData(); int prodId = int.Parse(GetId(prodDesc)); { ClassA classA = new ClassA(GetDirectory() + userDir); classA.addoper_1(prodId); classA.Close(); } } catch { try { connec.Close(); connec = null; } catch { } } } FillDefaultInsertRow(); return(wasInserted); }
static void Main(string[] args) { #region//深克隆 浅克隆 MemberwiseClone() clone() //#region ////Animal a1 = new Dog(1, 2, 3, "A", "B"); ////Console.WriteLine("Animal a1 's members :" + a1.i + " " + a1.d + " " + a1.b + a1.s[0] + a1.s[1] + "<br/>"); ////Animal a2; ////a2 = a1.Clone(); ////Console.WriteLine("Animal a2的Members:" + a2.i + a2.d + a2.b + a2.s[0] + a2.s[1] + "<br/>"); ////Console.WriteLine("do a1.i = 9;a1.s[0] = C" + "<br/>"); ////a1.i = 9; ////a1.s[0] = "C"; ////Console.WriteLine("Animal a1的Members:" + a1.i + a1.d + a1.b + a1.s[0] + a1.s[1] + "<br/>"); ////Console.WriteLine("Animal a2的Members:" + a2.i + a2.d + a2.b + a2.s[0] + a2.s[1] + "<br/>"); ////Console.WriteLine("do a2.i = 8;a2.s[1] =D" + "<br/>"); ////a2.i = 8; ////a2.s[1] = "D"; ////Console.WriteLine("Animal a1的Members:" + a1.i + a1.d + a1.b + a1.s[0] + a1.s[1] + "<br/>"); ////Console.WriteLine("Animal a2的Members:" + a2.i + a2.d + a2.b + a2.s[0] + a2.s[1] + "<br/>"); //#endregion #endregion #region//深克隆 ,自添加自写的深度克隆函数DeepClone //#region //Dog dog1 = new Dog(1, 2, 3, "A", "B"); //Console.WriteLine("Dog dog1 's members :" + dog1.i + " " + dog1.d + " " + dog1.b + dog1.s[0] + dog1.s[1] + "<br/>"); //Dog dog2 = dog1.DeepClone(); //Console.WriteLine("Dog dog2的Members:" + dog2.i + dog2.d + dog2.b + dog2.s[0] + dog2.s[1] + "<br/>"); //Console.WriteLine("===>>>Change dog1.i = 9;dog1.s[0] = C" + "<br/>"); //dog1.i = 9; //dog1.s[0] = "C"; //Console.WriteLine("Dog dog1 's members :" + dog1.i + " " + dog1.d + " " + dog1.b + dog1.s[0] + dog1.s[1] + "<br/>"); //Console.WriteLine("Dog dog2的Members:" + dog2.i + dog2.d + dog2.b + dog2.s[0] + dog2.s[1] + "<br/>"); //Console.WriteLine("===>>>Change dog2.i = 8;dog2.s[1] = D" + "<br/>"); //dog2.i = 8; //dog2.s[1] = "D"; //Console.WriteLine("Dog dog1 's members :" + dog1.i + " " + dog1.d + " " + dog1.b + dog1.s[0] + dog1.s[1] + "<br/>"); //Console.WriteLine("Dog dog2的Members:" + dog2.i + dog2.d + dog2.b + dog2.s[0] + dog2.s[1] + "<br/>"); //#endregion #endregion #region ICloneable接口下的 Clone()方法 ClassA ca = new ClassA(); ca.value = 88; ClassA ca2 = new ClassA(); ca2 = (ClassA)ca.Clone(); ca2.value = 99; Console.WriteLine(ca.value + "-----" + ca2.value);//88---99 ClassB cb = new ClassB(); cb.Member.value = 13; Console.WriteLine("===>>>cb.Member.value = 13;"); ClassB cb2 = (ClassB)cb.Clone(); cb2.Member.value = 7; Console.WriteLine(cb.Member.value.ToString() + "------" + cb2.Member.value.ToString());//浅拷贝:7---7 深拷贝:13----7 #endregion Console.ReadLine(); }
public static void Output <T>(ClassA <T> aClassA_WithOutputCapabilities) where T : IOForClassA.ICanOutput { aClassA_WithOutputCapabilities.Type1.OutputFunction(); }
protected override void InsertRow(bool goToEdit) { GridViewRow row = grid.FooterRow; Control[] txtControls = new Control[FIELDS.Length]; //TextBox[] txtInserts = new TextBox[FIELDS.Length]; List <String> selectedFields = new List <String>(); List <TextBox> selectedTextBoxes = new List <TextBox>(); selectedTextBoxes.Add(null); selectedFields.Add(FIELDS[0]); for (int i = 1; i < FIELDS.Length; i++) { txtControls[i] = row.FindControl(TEXT_BOX_IDS[i]); if (txtControls[i] == null) { return; } } connec = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source= " + GetDirectory() + userDir + MAIN_USER_DATABASE + ";"); //string command = GetCommandString(Command.INSERT, selectedFields.ToArray()); string command = GetCommandString(Command.INSERT); OleDbCommand cmd = new OleDbCommand(command, connec); { /*for (int i = 1; i < selectedFields.Count; i++) { * string value = selectedTextBoxes.ElementAt(i).Text; * cmd.Parameters.AddWithValue(selectedFields[i], value); * }*/ string prodDesc = ""; for (int i = 1; i < txtControls.Length; i++) { string value; if (mode.Equals("Advanced") || !ADVANCED_FIELDS[i]) { if (COMBOS[i]) { if (((AjaxControlToolkit.ComboBox)txtControls[i]).SelectedItem != null) { value = ((AjaxControlToolkit.ComboBox)txtControls[i]).SelectedValue; } else { value = MyUtilities.clean(((AjaxControlToolkit.ComboBox)txtControls[i]).Text); } } else if (CHECKBOXES[i]) { value = (((CheckBox)txtControls[i]).Checked) ? "1" : "0"; } else { value = MyUtilities.clean(((TextBox)txtControls[i]).Text); } if (FIELDS[i].Equals("LaborDesc") || FIELDS[i].Equals("EquipDesc") || FIELDS[i].Equals("ProdDesc") || FIELDS[i].Equals("OpNam")) { value = value.ToUpper(); } cmd.Parameters.AddWithValue(FIELDS[i], value); if (i == 1) { prodDesc = value; } } } try { connec.Open(); int result = cmd.ExecuteNonQuery(); connec.Close(); int prodId = int.Parse(GetId(prodDesc)); { ClassA classA = new ClassA(GetDirectory() + userDir); classA.addoper_1(prodId); classA.Close(); tableSync.UpdateEquipNames(); tableSync.UpdateOperNames(); } if (goToEdit) { SetData(); GoToEditMode(prodId); } } catch { try { connec.Close(); connec = null; } catch { } SaveInsertValues(grid.FooterRow, TEXT_BOX_IDS); Master.ShowErrorMessage(DbUse.INSERT_DATA_ERROR_MSG); } } }
public void ClassB(ClassA classAInstance) { _classAInstance = classAInstance; }
public ClassB(ClassA owner) { _owner = owner; }
private void SomeMethod() { form = new ClassB(); form.Show(); ClassA foo = new ClassA(this); }
static void Main(string[] args) { ClassA classA = new ClassA(); classA.method3(); // call the extra ClassA method you wrote }
public ClassB(ClassA a) { }
public static void PrimaryMain() { object[] objArray = new object[6]; objArray[0] = new ClassA(); objArray[1] = new ClassB(); objArray[2] = "hello"; objArray[3] = 123; objArray[4] = 123.4; objArray[5] = null; object[] objArray2 = new object[6]; objArray2[0] = "Name0"; objArray2[1] = "Name1"; objArray2[2] = "Name2"; objArray2[3] = "Name3"; objArray2[4] = "Name4"; objArray2[5] = "Name5"; /* Using 'as' versus 'casting' * 'as' - you need to check for Null * - Use the 'as' operator when you are uncertain of the compatibility of the source and target. * - You should use the 'as' operator in conjuction with the null check. * 'cast' - requires you to know the type, if the type is not correct an exception will be thrown * - Use the cast type whenever you know the source and target types are compatible. Also use * - 'cast' when you want an exception to occur to let you know about incompatible types. */ Console.WriteLine("Example of using as instead of casting"); Console.WriteLine("As does not raise an exception for different typess"); for (int i = 0; i < objArray.Length; ++i) { string s = objArray[i] as string; Console.Write("{0}:", i); if (s != null) { Console.WriteLine("'" + s + "'"); } else { Console.WriteLine("not a string"); } } Console.WriteLine("casting requires the type to be correct or for you to know type"); Console.WriteLine("If the type is not correct, casting will throw an exception"); //use objArray if you want an exception to be thrown. for (int i = 0; i < objArray2.Length; ++i) { string s = (string)objArray2[i]; Console.Write("{0}:", i); if (s != null) { Console.WriteLine("'" + s + "'"); } else { Console.WriteLine("not a string"); } } Console.ReadKey(); }
public void MethodClassC() { ClassA classA = new ClassA(); classA.MethodClassA(); }
public ClassB(ClassA a) => ClsA = a;
public void TestMethod() { //creates Database DatabaseContext context = new DatabaseContext(path); if (context.DatabaseExists()) //Delete if exists { context.DeleteDatabase(); } context.CreateDatabase(); ClassB b1 = new ClassB(); b1.Name = "name 1"; ClassB b2 = new ClassB(); b2.Name = "name 2"; ClassB b3 = new ClassB(); b3.Name = "name 3"; ClassA a = new ClassA(); //now the references will be added to the object a //in 1-n references a.addLink(b1); a.addLink(b2); a.addLink(b3); context.ClassATable.InsertOnSubmit(a); context.SubmitChanges(); //store in database //now the database will be reloaded context = new DatabaseContext(path); //Check if all ClassB objects were correctly stored and reloaded foreach (ClassB x in context.ClassBTable) { Console.WriteLine(x.ID + "; " + x.Name); /* * -> expected output: * 1; name 1 * 2; name 2 * 3; name 3 * -> real output * 1; name 1 * 2; name 2 * 3; name 3 * -> check! */ } //check if all ClassA objects were correctly stored and reloaded foreach (ClassA x in context.ClassATable) //context.ClassATable has only one entry { Console.WriteLine("check of entitys set"); //check of 1-n references foreach (ClassB b in x.getLinks()) { Console.WriteLine(b.ID + " has a link to " + b.ID + ", " + b.Name); /* * -> expected output: * 1 has a link to 1, name 1 * 1 has a link to 2, name 2 * 1 has a link to 3, name 3 * -> real output * 1 has a link to 1, name 1 * 1 has a link to 2, name 2 * 1 has a link to 3, name 3 * -> check! */ } } }