|
Guffa wrote: It's possible to do that using reflection, but I doubt that you really need that.
Why don't you explain what you are trying to accomplish, instead of asking how to do it the way that you think it's done?
well.. i'm trying to do is, i have one xml file which maintains which modules user has choosen to use. then my app. will load those module detail in menu(this far i've completed). when user clicks one menu that particular module's entry function will be called. now menu click event passing me the 'SENDER', from which i can extract the menu name which i've to use as identifier(nothing else i've got better than this after having many suggestion from people). after clicking the menu i'll run the entry function of that particular module. the important thing is, one user may have choosen completely different modules than other.
|
|
|
|
|
Make a base class or an interface for the modules, so that you can call the method without caring which of the modules it is. To get the right module you can do a lookup-table, like putting references to the modules in a hash-table.
---
b { font-weight: normal; }
|
|
|
|
|
thanks for your reply i've fixed the problem with the help of reflection
|
|
|
|
|
Yes it is possible but i thing U need to create atleast atleast one Object for the class name that ur specifying in the string and u can use
Type t=typeof(ClassName)
t.InvokeMember("FunctionName", BindingFlags, null, obj, new FunctionArgsobj[]);
Hope it will help
Regards,
Thanks and Regards,
Srini
|
|
|
|
|
i did, and finally nothing happens, not even any exception.
|
|
|
|
|
Hello,
How can I wire the default clipboard events (Cut/Copy/Paste) to my menu items. The thing is, when you enter the edit mode for a treenode, and right click that node, the default context menu pops up, with the cut, copy, and paste events. However, I have same events in the main menu, so I want them to perform the same tasks on the treenode objects.
Thank you.
|
|
|
|
|
zaboboa wrote: How can I wire the default clipboard events (Cut/Copy/Paste) to my menu items.
You need to add code in your menu handler which uses the Clipboard object, e.g.
private void mnuEditCopy_Click(object sender, EventArgs e)
{
Clipboard.SetText(this.treeView.SelectedNode.Text);
}
What you get and put from the clipboard is up to you. What the right-click options are doing at the moment for the TreeView is cutting, copying and pasting the text for the TreeNode, not the actual TreeNode itself.
If you actually want to copy a TreeNode then you may be able to use the
Clipboard.SetDataObject
method (or something namely similarly to it).
Ed
|
|
|
|
|
Hi
I am struggling over getting the enum items name using reflection
say this the enum
/ Enum for Art Mode <br />
public enum tenumArtMode<br />
{<br />
artModeAuto=0,<br />
artModeManual,<br />
artModeInvalid<br />
} ;
Note:: this enum is in dll which is developed in VC++ .NET, I have added reference to access this enum in C#
I want to display this enum items using C#
I have tried the function Enum.GetName
tenumArtMode tenumMode;<br />
Type t=tenumMode.GetType();<br />
<br />
Enum.GetName(t.FieldType,t.GetValue(tenumMode));
But this throws me an ArgumentException
TIA
Srini
|
|
|
|
|
You can also simply do a ToString(). For example:
string s = tenumArtMode.arModeManual.ToString();
Would yield the string "artModeManual"
Good Luck
Mike Luster
CTI/IVR/Telephony SME
|
|
|
|
|
Thanks For your reply Mike,
No, This can't be applicable, b'cas i getting this enum at runtime so i would not know the enum item names.
Do understand my question. I want to iterate the enum using reflections
Regards,
Srini
|
|
|
|
|
You don't need reflection. The Enum class provides you with methods to get all information you nead about the enum.
Use the GetNames method to get an array of all the names. If you need their values, use the GetValues method to get an array with all the values.
---
b { font-weight: normal; }
|
|
|
|
|
If it is One Enum then your suggestions is OK. I can use Enum.GetNames(enum), But My situation is likes a structure which will contain lot of enums(say 100) as it member) so i can't write 100's lines of code to display every member
ie.
enum1<br />
{<br />
a=0,<br />
b,<br />
c<br />
}<br />
..<br />
enum100<br />
{<br />
x=0,<br />
y,<br />
z<br />
}<br />
<br />
Struct st<br />
{<br />
enum1 e1;<br />
enum2 e2;<br />
..<br />
enum100 e100;<br />
};<br />
<br />
Enum.GetNames(st.e1);<br />
..<br />
Enum.GetNames(st.e100);
Instead Puting like the above
I am thinking of reflection to reduce the line of code
Like this
Type ty = st.GetType();<br />
FieldInfo[] fin= ty.GetFields();<br />
foreach (FieldInfo fino in fin)<br />
{<br />
fino.GetValue(st).ToString();<br />
}
But This print the enum1..enum100 values like 0 0 0 0 ..
but I want to print the enum member names like a b c ...
Hope I Explained my question Clearyly
Regards,
Srini
|
|
|
|
|
I see. Try this, then:
Enum.GetName(fino.FieldType, fino.GetValue(st))
---
b { font-weight: normal; }
|
|
|
|
|
Exactly thats what i want, i have used the same code but it throws me me ArgumentException, i think since the enum is developed in VC++ .net fino.FieldType doesn't match with System.Enum Type in C#(since we are using Enum.GetName).. I think so.
Try it out and if anything works please share with me.
Regards,
Srini
|
|
|
|
|
Have you tried it out? It's not the same code as you showed in your first post.
---
b { font-weight: normal; }
|
|
|
|
|
Yes I tried out. it throws me the ArgumentException.
ArgumentException - Description given in the MSDN help
enumType is not an Enum.
-or-
value is neither of type enumType nor does it have the same underlying type as enumType.
Enum in VC++ .net and VC# .net are they different?
|
|
|
|
|
Even That is code i have mentioned in my initial Conversation.
|
|
|
|
|
No, it's not. There you used a Type object instead of a FieldInfo object.
---
b { font-weight: normal; }
|
|
|
|
|
Have you tried using the Enum struct? Once you have the type of enum you can use the static methods of the Enum struct to obtain information about the enum type.
chriswa
|
|
|
|
|
I got it!!!!
Thanks Chriswa its working as per your suggestion. i have declared the enum as enum class (ie enum struct) in VC++ dll. then i can able to get the enum member names.
If i declare the enum using enum in VC++, then i am not able to retrieve the names.
What is the difference between enum and enum struct
I extend my thanks to Guffa.
Regards,
Srini
|
|
|
|
|
How does one get the current date and time in C#. Is there any readymade class.
|
|
|
|
|
deepscyberpulse wrote: How does one get the current date and time in C#. Is there any readymade class.
DateTime.Now
Share and enjoy.
Sean
|
|
|
|
|
I think that this is what u want.
DateTime d = new DateTime();
MessageBox.Show(d.ToShortDateString());
|
|
|
|
|
Hi, you can use this:
label1.Text = DateTime.Now.ToLongDateString(); //date
label2.Text = DateTime.Now.ToLongTimeString(); //time
Regards,
Alberto Martinez
|
|
|
|
|
Hello
I am working on an application in c# i want to develop a sofware that block the any address that is contain in the database of my appliction. i.e if i have www.yahoo.com in my database and user enter www.yahoo.com in the address bar of the Internet Explorer this site should not be open.
If any one has worked on it or have idea about it plz le me know.
|
|
|
|