|
PIEBALDconsult wrote: That still sounds like they did something wrong
Often times that's true, but usually when it is that developer isn't around anymore to explain themselves and I get to fix it for them.
PIEBALDconsult wrote: Ideally, within the organization, there is someone with a view of the larger picture
and therein lies one of the problems with our organization
|
|
|
|
|
That's much of why I enjoyed being a team of one on my last job.
|
|
|
|
|
Jimmanuel wrote: Adding it can't break any other code,
I don't want to bother to delve into it now, but as I recall, in C# changing the virtual-ness of a base class' method in either direction will mean you have to alter the override-ness or hide-ness of an overriding or hiding method of a derived class.
Yeach , I should have bothered to delve; nothing to see here, move along.
modified on Tuesday, December 8, 2009 10:52 PM
|
|
|
|
|
So if you have a non virtual method in a base and a "new" method in a child that hides it, you have to change the hiding child method to an override if you change the base method to be virtual?
If that's true then that's one more reason that I don't like hiding methods with "new". Following along the same lines as before, if a child has the need to hide a method in a base class I'd call that grounds to make the thing virtual in the first place instead of just hiding it.
|
|
|
|
|
Jimmanuel wrote: you have to change the hiding child method
Dang, I thought that was the case, but a little experiment seems to have proved me wrong (again).
I know some time in the last few weeks a thread dealing with something like that came up, in which you had to use new with either override or virtual. I'll try to find the thread.
Edit: I didn't find it.
Jimmanuel wrote: I don't like hiding methods with "new".
Absolutely.
modified on Tuesday, December 8, 2009 10:43 PM
|
|
|
|
|
A class needs to be designed for inheritance. If you just make stuff virtual, you end up with the fragile base class problem[^].
Composition (and encapsulation) is way better than inheritance.
If the base class calls any of its own virtual methods, this must be documented! And any future change to these internal calls must be considered a breaking API change. See http://www.javaworld.com/javaworld/jw-08-2003/jw-0801-toolbox.html?page=3[^] for an example.
Usually, I just make my classes sealed . Extensibility is hard work, just slapping a few virtual modifiers on your methods without thinking will only cause trouble in the long run.
|
|
|
|
|
Daniel Grunwald wrote: A class needs to be designed for inheritance
That means the methods should be virtual. Without virtual methods there's no polymorphism. Without polymorphism there's very little reason for inheritance.
Daniel Grunwald wrote: Composition (and encapsulation) is way better than inheritance.
Not in all cases, but it should be considered before inheritance.
Daniel Grunwald wrote: without thinking
Doing anything (even sealing) without thinking will cause trouble in the long run.
|
|
|
|
|
Can you directly store the CheckState.Checked / Unchecked value in a class property?
If so how would you store it, or do I have to examine it and store a bool?
Thanks.
|
|
|
|
|
I don't think so, but you can attach a handler for the ItemCheck event.
|
|
|
|
|
If you need to track the checked items in the control, you can make use of CheckedIndices property.
50-50-90 rule: Anytime I have a 50-50 chance of getting something right, there's a 90% probability I'll get it wrong...!!
|
|
|
|
|
So you cannot store the e.CheckState value in the ItemCheck event?
I have many collections to display/redisplay in the same checkedlistbox. I would rather push a value to the object in the list when it is checked then cycle through all of them before changing the collection being displayed. I have
if (e.NewValue == CheckState.Checked)
dv.checkedInLB = true;
else
dv.checkedInLB = false;
which works fine, but adds a step.
|
|
|
|
|
I haven't tried it, but I would expect something like:
((SomeType)checkedListBox1.SelectedItem).checkedInLB = e.NewValue == CheckState.Checked ;
|
|
|
|
|
If you keep the checked state in some other property, you will be checking that then. So any ways you will have to check by some mean or the another that check box is checked or not.
Am I understanding your problem correct or not? I assume you want to store checkedstate in a boolean property. Like:
if (checkedListBox.Items[index].checked){
}
else{
}
50-50-90 rule: Anytime I have a 50-50 chance of getting something right, there's a 90% probability I'll get it wrong...!!
|
|
|
|
|
hi all
i am currently using C# vs.net 2005 window form to program an application which would make use of data from a database to write on an excel sheet with (Microsoft.Office.Interop.Excel) it worked fine till i notice some disadvantages of it:
1. when the data is being writen into the excel and user click it always bugs out with an error Error: Exception from Hresult: 0x800AC472 line: mscorlib
2.the excel file must always be open to write the data
as such i was wondering if there is other better way of doing writing data into the excel file which offers the same functions and more. e.g writing without opening the file and etc.
i understand that the ms office 2007 is using xml languash and should be able to do this but how exactly should i start?
please advice
|
|
|
|
|
You can do it by Ole db provider for Excel.
|
|
|
|
|
hi
thanks for your answer but i would like to check with your if Ole db provider for Excel have the ability to change the cell border and such?
e.g add new sheet, change cell border and font size etc
because most of the articles i read on the net only shows the method of read and writing for it
|
|
|
|
|
You cannot do that with ole db provider. You will need to use excel com object model for that.
|
|
|
|
|
Hi
I am dynamically declaring types (using ModuleBuilder.DefineType[^] which are used to allow for strongly typed data sets from a CSV file.
However when the user adds or alters a column definition I'd like to remove and rebuild the data type. Any ideas how I drop and recreate a type - do I have to unload the whole assembly or how is it done?
public static Type MakeTypeForColumns(string typeName, MarketRecObjects.ImportFileFormatColumnDefinitionCollection columns)
{
Type columnType = null;
TypeBuilder columnTypeBuilder = GetTypeBuilder(typeName);
if (null != columnTypeBuilder)
{
foreach (ImportFileFormatColumnDefinition col in columns)
{
FieldBuilder colFieldBuilder = columnTypeBuilder.DefineField(MakeValidObjectCodeName(@"_" + col.ColumnName),
col.GetTypeForContentType(), FieldAttributes.Private);
PropertyBuilder colPropertyBuilder = columnTypeBuilder.DefineProperty(MakeValidObjectCodeName(col.ColumnName),
PropertyAttributes.None, col.GetTypeForContentType(),
Type.EmptyTypes);
MethodBuilder colGetMethodBuilder = columnTypeBuilder.DefineMethod(@"get_" + colPropertyBuilder.Name, MethodAttributes.Public | MethodAttributes.HideBySig | MethodAttributes.SpecialName, colFieldBuilder.FieldType, Type.EmptyTypes);
ILGenerator colGetMethodGenerator = colGetMethodBuilder.GetILGenerator();
colGetMethodGenerator.Emit(OpCodes.Ldarg_0);
colGetMethodGenerator.Emit(OpCodes.Ldfld, colFieldBuilder);
colGetMethodGenerator.Emit(OpCodes.Ret);
MethodBuilder colSetMethodBuilder = columnTypeBuilder.DefineMethod(@"set_" + colPropertyBuilder.Name, MethodAttributes.Public | MethodAttributes.HideBySig | MethodAttributes.SpecialName, typeof(void), new Type[] { colFieldBuilder.FieldType });
ILGenerator colSetMethodGenerator = colSetMethodBuilder.GetILGenerator();
colSetMethodGenerator.Emit(OpCodes.Ldarg_0);
colSetMethodGenerator.Emit(OpCodes.Ldarg_1);
colSetMethodGenerator.Emit(OpCodes.Stfld, colFieldBuilder);
colSetMethodGenerator.Emit(OpCodes.Ret);
colPropertyBuilder.SetGetMethod(colGetMethodBuilder);
colPropertyBuilder.SetSetMethod(colSetMethodBuilder);
}
ConstructorBuilder columnConstructorBuilder = columnTypeBuilder.DefineConstructor(MethodAttributes.Public,
CallingConventions.Standard,
Type.EmptyTypes);
ILGenerator constructorGenerator = columnConstructorBuilder.GetILGenerator();
constructorGenerator.Emit(OpCodes.Ret);
columnType = columnTypeBuilder.CreateType();
}
else
{
columnType = ModuleBuilder.GetType(MakeValidObjectCodeName(typeName), false , false ) ;
}
return columnType;
}
where the type is defined by
private static TypeBuilder GetTypeBuilder(string newTypeName)
{
if (ModuleBuilder.GetType(MakeValidObjectCodeName(newTypeName), false, true) == null)
{
try
{
TypeBuilder ret = ModuleBuilder.DefineType(MakeValidObjectCodeName(newTypeName), TypeAttributes.Public | TypeAttributes.Sealed);
return ret;
}
catch (System.ArgumentException argEx)
{
System.Diagnostics.Trace.TraceError(argEx.ToString());
return null;
}
}
else
{
return null;
}
}
|
|
|
|
|
AFAIK you can't drop code without dropping the entire AppDomain.
You can add code to an existing class, not replace it.
|
|
|
|
|
OK thanks - I'll just have to add a version number to the typename and keep track of the type(s) internally...
|
|
|
|
|
you're welcome.
|
|
|
|
|
Hello,
i have a .NET 2 Application (Class Library) and want to interact with a .NET 3 Application (WPF), how is this possible?
Of course i could reference from the WPF-App to the Class-Library (thats the normal way) but i'm must be able to initiate the .NET 3 App from the .NET 2 Application.
And of course they need to be able to communicate with each other... how can i do that?
Why do i want to do that? Because i want to let my logic in the .NET 2 App and create a GUI-Layer in .NET 3.5 and one in .NET 2 (if the user doesn't have 3.5 or doesn't want it or want to use mono)
|
|
|
|
|
How about a three-part approach:
- a 2.0 EXE with GUI
- a 3.5 EXE with WPF-based GUI
- a 2.0 DLL with all the logic, used by both EXEs.
You can stuff these three projects in a single VS2008/10 solution, and set the target for each project separately.
|
|
|
|
|
Yes, as i wrote that's the "normal" way.
But i need to initiate the GUIs from the logic. Because the logic is used by a host as a "plugin" you can say. So i need to go that way.
<br />
<br />
Logic (2.0)---> WPF GUI (3.5)<br />
|<br />
|<br />
V<br />
WinForms GUI (2.0)<br />
<br />
So how can i do this the easiest way?
|
|
|
|
|
You mean the logic must be the .exe file? Why?
If you are just talking about callbacks, simply make the GUIs implement an interface defined in the logic assembly.
|
|
|
|