|
OK - i understand what attributes are, and what they allow you to do, but i cant think of a situation in which they would be benifitial.
Email: theeclypse@hotmail.com URL: http://www.onyeyiri.co.uk "All programmers are playwrights and all computers are lousy actors."
|
|
|
|
|
Attributes allow you to specify extra information about a class or its members without making that stuff part of the interface.
The PropertyGrid control, for example, uses attributes to know what Category to place each property in, by examining the CategoryAttribute on the property.
The usage is wide open... and it's just up to you to come up with new and interesting ways to make it benefit you.
|
|
|
|
|
OK the code below is puzzling me. i have this nice little static member that loads pluggins based on a Type object. It does all of this fine, gets everything I want, yada yada... then i get to using the object. I'm looking at the autos in the debugger right now and they say that pluggin, by itself, is of type SourceControl.SourceSafe, which DOES implement ISourceControlPluggin (these are my classes/interfaces) though it won't let me do the cast - keeps yelling at me. Anyone have anything - i'm sure i'm just being blinded by the weekend...
object[] pluggins = System.Pluggins.Pluggins.LoadPluggins( plugginsDir, typeof(ISourceControlPluggin) );
foreach(object pluggin in pluggins)
{
MessageBox.Show( this, ((ISourceControlPluggin)pluggin).Name );
}
|
|
|
|
|
I think that we are going to need more details on what the "LoadPluggings" function is doing, maybe then we can help...
|
|
|
|
|
This is the load pluggins static member. It is really the same thing as in the MYrc example that leppie mentions.
public static object[] LoadPluggins( string Directory, Type Interface )
foreach( file found, load the assembly)...
{
if( asm != null )
{
Type[] types = asm.GetTypes();
foreach(Type type in types)
{
Type[] interfaces = type.GetInterfaces();
if( type.GetInterface(Interface.FullName) != null)
{
lstPluggins.Add( Activator.CreateInstance(type) );
}
}
}
}
}
return lstPluggins.ToArray();
|
|
|
|
|
I've noticed that same type of behavior, but mostly when working in design-time mode (as part of a custom designer). The problem seems to stem from having the two objects be created from non-identical assemblies.
Say you have a class MyClass that is compiled into MyAsm.dll. You compile code linked against v1.0.0.1 of MyAsm.dll, and this code loads code via Reflection that links to MyAsm.dll v1.0.0.2. Then you call into the code you loaded and it creates an instance of MyClass v1.0.0.2. Your code is compiled as referring to MyClass v1.0.0.1. When you try and set your reference variable (of type MyClass v1.0.0.1) to the instance of MyClass v1.0.0.2, you'll get an 'invalid cast exception'.
If indeed you are getting an "Invalid cast exception", modify the code a little bit to get a Type object for the object instance you loaded. Compare this in the debugger with
'typeof(ISourceControlPluggin)' to see if there are any minute differences.
--
Russell Morris
"Have you gone mad Frink? Put down that science pole!"
|
|
|
|
|
Huh, you might have it. I've actually changed the output directory for the Build of the class that implements the interface to be a sub directory of the class using it. This is so that loading the pluggin assemblies involves moving them to the subdirectory of the app. I'll take a look, but that is great point.
|
|
|
|
|
Hi,
How to catch the WM_ACTIVATEAPP message in C# application with GUI? I am looking for .Net framework equivalent of CWnd::OnActivateApp function in MFC.
Thanks!
|
|
|
|
|
I just did it 5 minutes back (what a coincidence). There is no equivalent of this in C#. Here is a code snippet from my class:-
const int WM_ACTIVATEAPP = 0x001C;
protected override void WndProc(ref Message m)
{
if ((m.Msg == WM_ACTIVATEAPP) && (m.WParam == IntPtr.Zero))
{
//OnDeactivateApp(EventArgs.Empty);
}
else
base.WndProc(ref m);
}
Step back, rub your eyes, take a deep breath, stretch a bit, and reflect on the relative importance of CP, CG, the age / travel time sustained by supposedly 'fresh' cheese curds, and Life in General. - Shog9
|
|
|
|
|
Is there any place in .NET where there is a Enum of the Windows Commands that can be sent? Instead of having to go through and print out their values and defining them as constants( as above)?
Jared
jparsons@jparsons.org
www.prism.gatech.edu/~gte477n
|
|
|
|
|
No unfortunately no. I developed a small macro to declare the constants for me.
Step back, rub your eyes, take a deep breath, stretch a bit, and reflect on the relative importance of CP, CG, the age / travel time sustained by supposedly 'fresh' cheese curds, and Life in General. - Shog9
|
|
|
|
|
Would you be willing to publish the macro? It would be nice that have available...
|
|
|
|
|
I have a Web User Control (.ascx) that can use either a SqlDataAdapter or a OleDbDataAdapter if I change the type of 1 of my members and 1 property
I'd like to be able to do this via some sort of typing - rtti
is this possible in c# - I'd hate to have 2 or more copies of what is essentially the same control.
PS yes I did look to see if they shared a base class - which they do but the properties I need to access aren't in the base class but have identical names in SqlDataAdapter and OleDbDataAdapter eg InsertCommand , UpdateCommand
Stupidity dies.
The end of future offspring.
Evolution wins.
- A Darwin Awards Haiku
|
|
|
|
|
my mistake - I found it in an interface - I did think it was odd
Stupidity dies.
The end of future offspring.
Evolution wins.
- A Darwin Awards Haiku
|
|
|
|
|
Although you can use an interface in this case, I agree, I how that Microsoft chooses to incorporate templates in the next revision of the .NET environment.
This would be especially useful when you want to make strongly typed collections classes.
Check out this .NET collection generator: http://www.sellsbrothers.com/tools/#collectionGen
Also the MagicLibrary has a nice Collection Base that supports events: http://www.dotnetmagic.com
Sorry about ranting about collections....
|
|
|
|
|
Hello,
I have the following proglem: I would like to unload the control from the form. After it's removal from Controls collection I cannot close the form - it simply does not work. The Dispose method does not get to be called. Just as there was no proper cleanup done. However, the Dispose call on the control does not help. Does anyone an idea how to manage this, to my surprise not easy, task?
All it is done in .NET using Windows forms.
Thanks in advice
Vasek
Vasek
VB6, C#, MS DNA, MS .NET software developer
|
|
|
|
|
Are you doing something 'fancy' before. If I create a form add a button and have that button remove itself from the controls collection it removes the button as expected. Also it will let me close the form without any problems
Regards
Rutger
|
|
|
|
|
The problem is somewhere else than in unloading the control. It works OK.
The problem is somewhere else. Luckily I found the way how to mitigate it!
Vasek
VB6, C#, MS DNA, MS .NET software developer
|
|
|
|
|
Here is a problem description and a work around; don't know if this is the same work around you're using though.
http://www.jelovic.com/weblog/e41.htm[^]
James
"Java is free - and worth every penny." - Christian Graus
|
|
|
|
|
Yes, it is like my problem. From within an control I want to remove i catch the event for removal request. That event is handled in the form and the control is removed upon this request.
I thought there could be problem with code sequence. Because after I handle the event in which I remove the control from ControlCollection, the flow of control returns to the control which was intended for removal (because it is demanding to be removed).
I will try you workaround and see.
Thank you very much.
Vasek
VB6, C#, MS DNA, MS .NET software developer
|
|
|
|
|
How do I know which row in the rich text box has the focus now?
Say I am overriding WndProc and checking for WM_KEYDOWN I'd like to figure out which row in the rich text box the cursor is curently located.
I dont mean the screen row [if it has scrolled down quite a bit, the 3rd visible row on screen might actually be the 44th row] I want the actual row here because I want to get that line of text using the Lines property but for that I need to know the index of the row
Nish
Author of the romantic comedy
Summer Love and Some more Cricket [New Win]
Review by Shog9
Click here for review[NW]
|
|
|
|
|
Try counting the newlines (ie "\r\n")?
I think that should work...
Later,
Nathan
---------------------------
Hmmm... what's a signature?
|
|
|
|
|
|
Nishant S wrote:
But till where do I count them? I have to know where the current pointer is right?
Use the selectionstart property.
----------------
Quote from MSDN:
Gets or sets the starting point of text selected in the text box.
[C#]
public int SelectionStart {get; set;}
.
.
.
Remarks
If no text is selected in the control, this property indicates the insertion point for new text. If you set this property to a location beyond the length of the text in the control, the selection start position will be placed after the last character. When text is selected in the text box control, changing this property may decrease the value of the SelectionLength property. If the remaining text in the control after the position indicated by the SelectionStart property is less than the value of the SelectionLength property, the value of the SelectionLength property is automatically decreased. The value of the SelectionStart property never causes an increase in the SelectionLength property.
Note You can programmatically move the caret within the text box by setting the SelectionStart to the position within the text box where you want the caret to move to and set the SelectionLength property to a value of zero (0). The text box must have focus in order for the caret to be moved.
--------
The SelectionStart property should return the current position in the RichEditBox.
Hope this helps,
Nathan
---------------------------
Hmmm... what's a signature?
|
|
|
|
|
I have a class derived from the System.Windows.Forms.TextBox .
I have overridden TextBoxBase.OnModifiedChanged but it never gets called even when I change the text in the text control
Has anyone else experienced the same problem?
Nish
Author of the romantic comedy
Summer Love and Some more Cricket [New Win]
Review by Shog9
Click here for review[NW]
|
|
|
|