|
S. Senthil Kumar wrote:
Brush foreBrush = null;
try
{
foreBrush = new SolidBrush(this.ForeColor);
...
}
finally
{
if (foreBrush != null)
((IDisposable)foreBrush).Dispose();
}
which begs a question, what if foreBush does not implement IDisposable ? It will simply crash ( throw exception) ?
David
|
|
|
|
|
Hence why only those objects which implement IDisposible can be used within a using block.
In this case foreBrush is an instance of SolidBrush and that implements IDisposible
|
|
|
|
|
I know. I just thought that it could be like
finally
{
IDisposable thing;
if ((thing = foreBrush as IDisposable) != null)
thing.Dispose();
}
OK, it's better how it is.
David
|
|
|
|
|
The code wouldn't compile if Brush didn't implement IDisposable. The compiler would complain that the type used in the "using" statement cannot be disposed, or something similar to that. So there's no question of a runtime crash.
Regards
Senthil
_____________________________
My Blog | My Articles | WinMacro
|
|
|
|
|
S. Senthil Kumar wrote:
The code wouldn't compile
That's exactly the answer I was looking for. Thanks.
David
|
|
|
|
|
Hi , Senthil , does that mean, after foreBrush is disposed, if following code gona use it , then it will be constucted again ??
|
|
|
|
|
No, it means that foreBrush will be disposed only at the end of its block. So
using (Brush foreBrush = new Brush())
using (Brush backBrush = new Brush())
{
}
Regards
Senthil
_____________________________
My Blog | My Articles | WinMacro
|
|
|
|
|
there is no ";" after the using( Brush foreBrush = new SolidBrush(this.ForeColor) ) .
it behaves like the if clause. you can use it like this:
if (x == true)
if (y==true)
{
... code in block ...
}
or like this:
if (x == true)
{
if (y==true)
{
... code in block ...
}
}
if there would be a semicolon right after the using statement your assumption that the foreBrush should be disposed would be true.
/cadi
|
|
|
|
|
How can I execute some command from my C# programm, as though I execute it from cmd.exe?
And how can I get the result of it?
So, I need execute "net view \\hostname" and get its output into a string variable..
Help, please..
--
Digitally yours, Bounz
|
|
|
|
|
Look at the System.Diagnostics.Process class. You can start a process and intercept its output to your own stream. You pass the name of the app into a ProcessStartInfo object just like you would pass the name of the app in the command window.
Tech, life, family, faith: Give me a visit.
I'm currently blogging about: The Secular Left, the Religious Right, and Prejudice
Judah Himango
|
|
|
|
|
thanks, I'll try
--
Digitally yours, Bounz
|
|
|
|
|
hi ,
in my application i have so many file . and i have to make these files as Gzip file . is there anyone can help me by sending me the source code .
How to GZip many files including files ...
i use ICSharpCode.SharpZipLib.GZip;
Thanks
|
|
|
|
|
|
I have a method, for ex:
<br />
public void test()<br />
{<br />
string MethodName = ???? <br />
MessageBox.Show(MethodName);<br />
}<br />
Is it possible to get method name information ?
|
|
|
|
|
This piece of code
string methodName = MethodBase.GetCurrentMethod().Name;
does the trick. MethodBase is in the System.Reflection namespace.
Regards
Senthil
_____________________________
My Blog | My Articles | WinMacro
|
|
|
|
|
How to check if object is NULL:
object Location;<br />
Location = Reader.GetValue(0);<br />
I need an assert that object is not null here.
thanks
|
|
|
|
|
george ivanov wrote:
I need an assert that object is not null here.
You mean, like:
Trace.Assert(Location != null, "Location is null.");
found in the System.Diagnostics namespace?
Marc
My website
Latest Articles:
Undo/Redo Buffer
Memento Design Pattern
|
|
|
|
|
|
how can i append this code to be able to export report to TXT file.
"ExportFormatType"
// Set the Export type, this can be:
// PDF, Excel, Word Doc, RTF Doc,
// HTML 3.2, HTML 4.0 or CrystalReport
but not txt ????
string exportFilePath = "c:\\Report1.txt";
// Create an instance of the untyped report object
ReportDocument oRpt = new ReportDocument();
// Load the report from disk
oRpt.Load(@"C:\Aloha\RPTFOH\Report_1.rpt");
// Set the options for saving the exported file to disk DiskFileDestinationOptions oDest = new DiskFileDestinationOptions();
oDest.DiskFileName = exportFilePath;
// Set the exporting information
ExportOptions oExport = oRpt.ExportOptions;
// Set the destination options
oExport.DestinationOptions = oDest;
// Set the location, this can be:
// DiskFile, ExchangeFolder, MicrosoftMail or NoDestination
oExport.ExportDestinationType = ExportDestinationType.DiskFile;
oExport.ExportFormatType = ExportFormatType.WordForWindows;
// Call the Export method to export the report
oRpt.Export();
|
|
|
|
|
Hi All
Export to excel data from ultrawebgrid rows, Each data row contain one worksheet in excel sheet like as
row1 data contain sheet1
row2 data contain sheet2
row3 data contain sheet3
this opertaion getting at a time on pressing one button.
we have pressing one button ultrawebgrid rows data to export excel sheet, In excel sheet each worksheet contain one grid row deatails, for example grid have 10 rows ,pressing any button, In excel sheet 10 worksheets will occure and each worksheet contain 1 row data of grid pls send me a solution for this example
|
|
|
|
|
Hi
I want to fetch Current ruuning Dial up connection and LAN connection into Listbox
I am able to populate into LAN connection in Listbox and i am not able to fetch dial up connection.
Second question is to get directory path of
Network and Dial-up Connections
Any clue for this
regards
sanjeev
|
|
|
|
|
I've implemented a custom UITypeEditor for a collection-based property (PropertyInfoCollection). In the GetEditStyle and EditValue methods, I check the type of the value passed (using ITypeDescriptorContext.PropertyDescriptor and value.GetType() in GetEditStyle and EditValue, respectively) and compare them against typeof( PropertyInfoCollection ) using Type.Equals to ensure that only the correct types are edited. Although the two sides of the comparison should be the same type (they do have the same names, versions, assemblies, public key tokens etc. but not the same hash codes...) the test for equality fails if I close the solution, reopen it and try to edit the property. Forcibly casting the property value in EditValue from object to PropertyInfoCollection also results in an InvalidCastException. The test succeeds again (and the cast works) if I rebuild the solution.
Should I be checking types differently? The different hash codes reported for (ostensibly) the same type suggest that the type is perhaps getting loaded twice, and the two different Type instances are not equated. Is this even possible?
|
|
|
|
|
Since this is a UITypeEditor related question i guess you are doing some sort of vs.net designtime support?
if so , have in mind that when you recompile , vs.net does not always (never?) unload the previously version of your assemblies.
I had a very similair problem when dealing with a designtime collectioneditor that cached types.
After a few recompiles , there was equally many different versions of the same classes in mem at the same time.. very annoying..
so maybe you can try to get the assembly from the type and check if the assemblys hashcodes differ aswell and maybe check verion numbers.
To make things a bit worse , I also never found a solution for this
//Roger
|
|
|
|
|
Hi Roger
Thanks for the response - you got it in one. A little reflection quickly established that the respective assemblies have different codebases Hopefully this won't be a problem when the component is being used, as it shouldn't be getting rebuilt under those circumstances...
shambulator
|
|
|
|
|
When I xml serialize a file, I want all the empty node should not appear. e.g.
Please ignore the format of the sample xml serialized file.
The below mentioned xml serialized file has empty region node.
[Application]
[Name]abc[/Name]
[Region/]
[/Application]
I want empty node should not appear in xml serialized file.
[Application]
[Name]abc[/Name]
[/Application]
I appreciate, if anyone has any solutions or suggestions to this, please share their knowledge.
Regards,
Shiby
|
|
|
|