|
|
I have a class like the following. The DataClass2 type is also derived from ASuperObject.
public class DataClass1 : ASuperObject<br />
{<br />
private DataClass2 dataClass2;<br />
<br />
public DataClass1(){}<br />
<br />
public DataClass2 MyDataClass2<br />
{<br />
get<br />
{<br />
if(this.dataClass2 == null)<br />
this.dataClass2 = DataClass2Holder.Instance.Dummy;<br />
return this.dataClass2;<br />
}<br />
set{this.dataClass2 = value;}<br />
} <br />
}
From a function I fool around with an instance of DataClass1 and at some time I use the MyDataClass2 property, to get the dataClass2 value.
The dataClass2 has not been instantiated yet, so the 'if' clause sets the value.
Now the function that called the property would like to know, if the 'if' clause was invoked or not (see code below)- can this be done?
int localCount = 1;<br />
PropertyInfo[] properties = this.GetType().GetProperties();<br />
foreach(PropertyInfo property in properties)<br />
{<br />
if(property.PropertyType.BaseType == typeof(ASuperObject))<br />
{<br />
((ASuperObject)property.GetValue(this,null)).nameAddition += localCount+"_"; <br />
((ASuperObject)property.GetValue(this,null)).InitializeHierarchy();<br />
localCount++;<br />
}<br />
}
(it must be general and not just a bool being set in DataClass1)
|
|
|
|
|
spif2001 wrote:
it must be general and not just a bool being set in DataClass1
No - you have encapsulated the dataClass2 member variable and only permit access throught the MyDataClass2 property (which could do anything it liked). As the MyDataClass2 property is designed to always return a DataClass2 object (or one derived from it) then you can never know by what the state of the member variable was before.
My: Blog | Photos
WDevs.com - Open Source Code Hosting, Blogs, FTP, Mail and More
|
|
|
|
|
1. Solution:
Dont return a DataClass2 object but a structure with a DataClass2 and a boolean value (would require to change the type of the property).
2. Solution:
Instead of making a property make a method like:
<br />
public DataClass2 GetMyDataClass2(out bool tookedDummyObject) {<br />
if(this.dataClass2 == null) {<br />
this.dataClass2 = DataClass2Holder.Instance.Dummy;<br />
tookedDummyObject = true;<br />
} else {<br />
tookedDummyObject = false;<br />
}<br />
return this.dataClass2;<br />
}<br />
If you still want the property to be present (for other callers who do not need the extra info) it could be implemented like:
<br />
get<br />
{<br />
bool notNeeded;<br />
return GetMyDataClass2(out notNeeded)<br />
}<br />
|
|
|
|
|
Good solutions there, but I have to minimize the code added to the ASuperObject sub-classes.
Ended up with a boolean solution after all, namely adding a bool isDummy to the ASuperObject abstract class. Then in my DataClass2Holder(Singleton) i set the bool after the Dummy DataClass2 has been instantiated.
Then I don't need to alter the property impl. in DataClass1 and the Dummy becomes semi-invisible.
Hope I find a better solution along the way, but for now it will have to do.
Thanks for the help you both.
-spif2001
|
|
|
|
|
hi,
i downloaded the latest aticle/project published in this site regarding REFLECTION.Its working fine for "mscorlib.dll".If we replaced the existing dll with some other dll, its throwing exception as "file is invalid format".
Any prerequisties are there?
which type of dll's i have to give?
I want to give dynamically.
Thanks,
Naveen.
|
|
|
|
|
You should ask questions like this on the article's page, not here in the general forum.
mav
|
|
|
|
|
hi there,
i'm trying to write to xml doc. from a string which is assigned to parsed information from the web by using(regex):
string myString, myString2;
XmlTextWriter writer = new XmlTextWriter("data.xml", null);
writer.WriteStartDocument();
//Use automatic indentation for readability.
writer.Formatting = Formatting.Indented;
//Write the root element
writer.WriteStartElement("Schedule");
foreach(Match m3 in Regex.Matches(getPage, tm.ToString()))
{
Group g3 = m3.Groups[1];
Console.WriteLine(g3.ToString());
myString = g3.ToString();
//add sub-elements
writer.WriteElementString("Time", myString);
foreach(Match m3a in Regex.Matches(getPage, prog.ToString()))
{
Group g3a = m3a.Groups[1];
Console.WriteLine(g3a.ToString());
myString2 = g3a.ToString();
// //End the item element
// writer.WriteEndElement(); // end Rate
//add sub-elements
writer.WriteElementString("Programme", myString2);
//End the item element
writer.WriteEndElement(); // end Rate
}
}
// end the root element
//writer.WriteFullEndElement();
//Write the XML to file and close the writer
writer.Flush();
writer.Close();
}
i get this :05:00
Morning Reports
Wake Up to Money
Unhandled Exception: System.InvalidOperationException: Token StartElement in sta
te Epilog would result in an invalid XML document.
at System.Xml.XmlTextWriter.AutoComplete(Token token)
at System.Xml.XmlTextWriter.WriteStartElement(String prefix, String localName
, String ns)
at System.Xml.XmlWriter.WriteElementString(String localName, String ns, Strin
g value)
at System.Xml.XmlWriter.WriteElementString(String localName, String value)
at Scrape2.Scrape2.Main(String[] args) in c:\uni stuff\project stuff\scrape2\
scrape2.cs:line 83
any help plzz....
|
|
|
|
|
i actually need to alternate between the two foreach loops, i.e.
time
programme
time
programme
.
.
.
etc
|
|
|
|
|
How can I create the Thumbnail view from the form?
In the following approach we tried but we are facing some limitations to get the thumbnail image of the form alone.
Can anuy one please help how to creat the thumbnail of the form alone.
thanks!
Approach - I - Bitmap (screen capture method)
=============================================
Can able to create the thumbnail image using Bitmap and BitBlt.
Code Sample:
Graphics g1 = this.CreateGraphics();
Image MyImage = new Bitmap(this.ClientRectangle.Width,this.ClientRectangle.Height, g1);
Graphics g2 = Graphics.FromImage(MyImage);
IntPtr dc1 = g1.GetHdc();
IntPtr dc2 = g2.GetHdc();
BitBlt(dc2, 0, 0, this.ClientRectangle.Width, this.ClientRectangle.Height, dc1, 0, 0, 13369376);
g1.ReleaseHdc(dc1);
g2.ReleaseHdc(dc2);
MyImage.Save(@"c:\BaluCaptured.jpg", ImageFormat.Jpeg);
MessageBox.Show("Finished Saving Image");
Limitations Facing:
1) Not able to capture the non visible portion of the form.
2) If the specified region size is beyond the visible portion in the screen, then remaining portions are in black color.
Approach - II - Metafile
Can able create the image using Metafile approach. How can we create the metafile for user controls drawn objects (Example: Graphs, Gauges).
Graphics grph = this.CreateGraphics();
IntPtr ipHDC = grph.GetHdc();
Metafile mf = new Metafile(@"d:\TestBalu.emf", ipHDC, EmfType.EmfPlusDual);
//grph.ReleaseHdc(ipHDC);
//grph.Dispose();
grph = Graphics.FromImage(mf);
grph.DrawRectangle(Pens.Blue, 10, 10, 100, 120);
Point p1 =new Point(20,60);
Point p2 =new Point(40,80);
Point p3 =new Point(100,120);
Point p4 =new Point(120,260);
Rectangle re=new Rectangle(30,20,60,90);
grph.DrawBezier(Pens.Gold, p1,p4,p3,p2);
grph.DrawBezier(Pens.Gold, p2,p4,p3,p2);
grph.Dispose();
Limitations Facing:
1) This can be possible for regular Graphics objects like creating Rectangle, Ellipse... using System.Drawing class.
2) It is not supporting for 3rd Party controls like Dundas gauge controls.
When we try to create the metafile (emf) the file size shows 0KB. It is not writing the data in to the file.
Approach – III – Scale down the Form
How to clone the form which contains the graphics objects like rectangle, user controls?
When we are trying to clone, it is only referring the memory; it is not actually cloning the object.
Code Sample:
Form2 obj = new Form2();
obj.Width = 640;
obj.Height = 480;
obj.BackColor = Color.Green;
obj.Show();
Form obj1 = new Form2();
obj1 = obj;
obj1.MaximizeBox = false;
obj1.MinimizeBox = false;
obj1.ControlBox = false;
obj1.FormBorderStyle = FormBorderStyle.None;
obj1.Scale(0.2f, 0.2f);
obj1.Show();
Limitations Facing:
==================
In .net we don’t have direct clone method to clone the form object. How can we clone the form object?
Even we tried with IClonable Interface's clone method also. Can any body please explain the clone() implementation in detail?
Thanks,
With Regards,
Balu Ramachandran
|
|
|
|
|
Hi all
Does any one know? how can we dynamically design a Tree (Data Structure) by using two or more label’s to hold the corresponding node information.
For example Display should look like this
Label A (root node)
|
----------------------------------------------
| |
Label B (child node) Label C (child node)
|
|
(so on............)
Please help me how can I draw an Tree Data Structure in C# .net
For a web application. The Label’s are dynamically created programmatically.
Thank you
|
|
|
|
|
Hi..,
Does any body have know about querys of take backup and restore of db with paraments like user name, password, connection?
Does any body no how export and import data to Access or any other db format with the same paraments as above?
Please help i am using C#.Net in programming.
|
|
|
|
|
Hi All,
From the application we are waiting, Process.WaitForExit() , for the installation to get over and once over with the installation, does some actions. But in some installations the parent/main process just instantiate the child process and get kill. And child process does the installation and get kill once installation is over. So in my appliation's code.
* I start the installation
* Store the main process id and wait for exit.
* Once parent/main process get kill.
* From the task manager list I check all the process whose parent id is equivalent to the one I stored.
* If any child process exist then again wait for exit.
* Once all the child process get kill then contiune with some actions.
But with some installations the child process still remain active even though the installation is over. So in this case I won't be able to continue..
If anyone has solutions to the above problem then please let me know.
Thanks & Regards,
Shiby Chacko.
|
|
|
|
|
What kind of installations is this? Installations of other programs that are out of your control?
Is it certain installation packages that doesn't work, or is the success depending on something else?
|
|
|
|
|
First thanks for your response.
From my application, I install some other package that are out of my control. Every installers behaviour is not the same. e.g
Case I with editplus installer
1 From my application I start the editplus installation
2 Store the main process id and wait for exit.
3 Once parent/main process get kill.
4 From the task manager list I check all the process whose parent id is equivalent to the one I stored.
5 If any child process exist then again wait for exit. (Now in this case there is no child process created. Goto step 7. )
6 Once all the child process get kill then contiune with some actions.
7 Continue with rest of the action
Case II with Photoshop
1 From my application I start the Photoshop installation
2 Store the main process id and wait for exit.
3 Once parent/main process get kill.
4 From the task manager list I check all the process whose parent id is equivalent to the one I stored.
5 If any child process exist then again wait for exit. (Now in this case there are two child processes get created. Goto step 6. )
6 Once all the child process get kill then contiune with some actions.
7 Continue with rest of the action
Case III with winamp lite
1 From my application I start the winamp lite installation
2 Store the main process id and wait for exit.
3 Once parent/main process get kill.
4 From the task manager list I check all the process whose parent id is equivalent to the one I stored.
5 If any child process exist then again wait for exit. (Now in this case there are two child processes get created. Goto 6.)
6 Once all the child process get kill then contiune with some actions.(but in this case, one process remains active, so could not goto step 7.)
7 Continue with rest of the action
In the above case I could not go to step 7 because one installer process remains active. How do I know/get notify that the installation is done/complete.
Regards,
Shiby
|
|
|
|
|
Is it always the same installation(s) that goes wrong?
|
|
|
|
|
Yes, it is always the same installation(s) that goes wrong. But there could be some other installation(s) which can behave the same.
|
|
|
|
|
Hi all,
Anyone knows how to use Microsoft Office Pivot Table 9.0 component in asp.net(c#).
Help me
Prabhakar.A
Software Engineer
|
|
|
|
|
Hi,
I am in need of some help.I want to Use tree view in C# so that in can use it to show the various hard drives on my computer ( i.e. traverse my drives as in case of explorer ).So I ran across this software called
My Explorer In C# developed By Paul Li to be found at url:
http://www.codeproject.com/csharp/my_explorer.asp
I was trying to use it but could not much help about it. I would really appreciate if any one can help me out to figure it out how to make use of it or put as similar feature on my form.
Thanks.
Salman.
|
|
|
|
|
is it possible to get the name of the function that a delegate contains during runtime?
|
|
|
|
|
|
Hi,
I'm scanning some documents in using the example ".NET TWAIN image scanner" posted here in Code Project by NetMaster. I was able to get it working for what I needed, but there are times where I need to scan a blank page (i.e. scanning duplex and the last page is blank).
Since the TWAIN DLL is returning the document as a hbitmap, I'm converting this to an Image so I can save it off to different file types.
Is there a way for me to determine if the Image is a blank page (i.e. all one color or something)?
Thanks,
Robert Wandell
|
|
|
|
|
i think there is somemethod like this in the Color. structure
ByMindOnlyYouCanDoIt
|
|
|
|
|
A scanned image is seldom ever "blank" with a single color. There are always variations in the image, such as dust and smudges that won't be "blank". Try scanning a completely blank piece of paper and look at the image magnified. You'll find that a blank "white" page, even though it's completely clean, is not consistantly one color from pixel to pixel in the image.
Your going to have to come up with an algorithm to evaluate the scanned image and come up with an "overall" color value for the page. Then you compare that value to a "threashold" value that signifies that the page is blank, or just doesn't have enough ink on it to consider it "not blank".
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
Hi, I'm totally new on this.
I have an ArrayList with several values
ArrayList itemList = new ArrayList();
itemList.Add("Blue hat", "2");
itemList.Add("White hat", "4");
itemList.Add("Red hat", "1");
I'd like:
1) convert it to a string that look like this:
Blue hat - 2
White hat - 4
Red hat - 1
so I can load it to a mail message
2) insert it in to a data table in my database with 2 fields: Item & Quantity
Can it be done using ArrayList or I have to use 2 dimensional array?
Greatly appreciate!!!!
|
|
|
|
|