|
Ya.. BaseType is required. Thanks
|
|
|
|
|
How about:
enumType is Enum ...
You guys certainly like to do things the hard way!
|
|
|
|
|
leppie wrote: enumType is Enum
Looks simple, but I cannot make it working. AFAIK, BaseType checking is required. When you use is , it throws exception for enum types too.
|
|
|
|
|
N a v a n e e t h wrote: Looks simple, but I cannot make it working. AFAIK, BaseType checking is required. When you use is, it throws exception for enum types too.
Then you are doing something wrong!
The following prints 'Friday':
object f = DayOfWeek.Friday;
if (f is Enum)
{
Console.WriteLine(f);
}
else
{
Console.WriteLine("Not enum");
}
|
|
|
|
|
Does no one read my articles?
I use:
System.Type basetype = typeof(T) ;
if ( !basetype.IsEnum )
{
throw ( new System.ArgumentException ( "T must be an Enum" ) ) ;
}
I suspect that all that checking for null in your example is needless.
And please read this[^].
|
|
|
|
|
Haha ,this is the best way !
|
|
|
|
|
PIEBALDconsult wrote: Does no one read my articles?
Sorry, I just missed it.
PIEBALDconsult wrote: I suspect that all that checking for null in your example is needless.
I am not getting you fully. Are you saying that the methods I used to get "FieldInfo", attributes will never return NULL ?
|
|
|
|
|
Correct. GetType() won't and GetCustomAttributes won't, GetField won't because you're passing in a known field name (in this case).
modified on Tuesday, July 8, 2008 12:41 AM
|
|
|
|
|
Thanks. I will remove the NULL checking. Thanks
|
|
|
|
|
PIEBALDconsult wrote: Does no one read my articles?
Hmmm...I missed that one somehow. Interesting approach to things. Did you see my article[^]? I have a similar GetDescription method.
Scott Dorman Microsoft® MVP - Visual C# | MCPD
President - Tampa Bay IASA
[ Blog][ Articles][ Forum Guidelines] Hey, hey, hey. Don't be mean. We don't have to be mean because, remember, no matter where you go, there you are. - Buckaroo Banzai
|
|
|
|
|
I probably did, I definitely remember the picture of someone blocking the Green Monster.
|
|
|
|
|
You can't apply a generic constraint on an enum type. The best you can get is struct. Also, take a look at this article[^] for a way to work with enums and a description attribute.
Scott Dorman Microsoft® MVP - Visual C# | MCPD
President - Tampa Bay IASA
[ Blog][ Articles][ Forum Guidelines] Hey, hey, hey. Don't be mean. We don't have to be mean because, remember, no matter where you go, there you are. - Buckaroo Banzai
|
|
|
|
|
Scott,
Thanks. I figured it out. Great article though
|
|
|
|
|
N a v a n e e t h wrote: Thanks. I figured it out. Great article though
You're welcome. Glad you liked the article.
Scott Dorman Microsoft® MVP - Visual C# | MCPD
President - Tampa Bay IASA
[ Blog][ Articles][ Forum Guidelines] Hey, hey, hey. Don't be mean. We don't have to be mean because, remember, no matter where you go, there you are. - Buckaroo Banzai
|
|
|
|
|
Oh, and... a few months ago I asked about it on MSDN and Jon Skeet said he'd ask whether or not an enum constraint might be in the future, he later reported... "maybe". I suspect there are a lot more important things concerning them.
I think maybe we should start a letter campaign.
|
|
|
|
|
PIEBALDconsult wrote: I asked about it on MSDN and Jon Skeet said he'd ask whether or not an enum constraint might be in the future,
Ohh, so what could replace enums ?
Jon Skeet - I love that guy. He got indepth knowledge on the subject and very helping too. He has a book out "C# in Depth". I got a copy, it's worth reading.
|
|
|
|
|
I meant it's possible that a future C# compiler will allow where T : enum
I'm not holding my breath, but apparently the team who can make it happen know there's some demand for it.
|
|
|
|
|
PIEBALDconsult wrote: I meant it's possible that a future C# compiler will allow where T : enum
I misunderstood you, now it's clear.
PIEBALDconsult wrote: know there's some demand for it.
Yeah. Let's hope it would come in the future versions.
|
|
|
|
|
I had a third party dll on which COM interoperability was not built in. I wrote my own C# dll which provided the wrappers for the functions inside the third party dll and in my dll, I added COM interop. My C# dll works fine if I use it in a C# application but whenever I call it from C++ using COM pointers, then no statement in the function is executed if that function uses any component inside third party dll.
In the following code, not even the messagebox will pop up which means as if the function is not even called. But if I remove, the last two lines of code, then messagebox will properly pop up.
<br />
public void MyDllFunc()<br />
{<br />
MessageBox.Show("Inside MyDllfFunc");<br />
<br />
ThirdPartyDllClass service = new ThirdPartyDllClass ();<br />
service.DoSomething();<br />
}<br />
It seems that if I am using a main dll which internaly uses some other dll, then both dlls should support COM interop if i want to make the main dll COMVisible.
Any ideas/suggestion/advice?
For COM interop, I am generating a tlb using regasm and then importing that tlb in my C++ application. Is there any other way through which I can achieve calling the third party dll from my C++ application?
Thank you.
the fruits of your success will be in direct ratio to the honesty and sincerity of your own efforts in keeping your own records, doing your own thinking and, reaching your own conclusions.
..surviving in autumn..in love with spring..
|
|
|
|
|
Hi everybody
I developed a web application project in C# involving a method, named run(), being called when a button, named "Go", is clicked.
The "run()" method takes some time to be executed. So I want to use a "PLEASE WAIT" swf file, named "PleaseWait.swf" while processing.
It is binded by a flash control dll, named "flcontrol" The Code belonging "Go" button looks like this:
protected void Go_Click(object sender, EventArgs e)
{
flcontrol.play=true;
run();
}
The problem is there that flcontrol plays right after "run()" method gets completed.
I also used "response.flush()" method before "run()" but nothing happened.
What should I do???
Tnx in forward
|
|
|
|
|
Your problem is that you are trying to play an animation on a page that doesn't exist yet.
Flushing the response doesn't help either. When the button events are executed, the rendering of the page hasn't been done yet, so there is nothing to flush.
You have two options if you want to play the animation while the server code runs:
1. Start the animation before the postback, using client code.
2. Start a separate thread for the run method, so that the thread creating the page can complete and send the page to the client. This of course means that you can't put anything in the page from the run method, as the page has already been sent.
Despite everything, the person most likely to be fooling you next is yourself.
|
|
|
|
|
Hi All,
I am creating plugin for Visual stdio 2005. After performing steps for registering plugin for VS2005 and starting new instance of VS2005 , I got error message as problem in loading plugin. Invalid text is found in line 1.
thankns
A
|
|
|
|
|
I am consuming an XFire Java Web Service from c# using WCF.
It is all working fine for fields that are elements in the wsdl, however there is one field that is an attribute and this never gets set on the client side. The Reference.cs has fields mapped thus:-
/// this is an element and works fine
[System.Xml.Serialization.XmlElementAttribute(Order=14)]
public string type {
get {
return this.typeField;
}
set {
this.typeField = value;
this.RaisePropertyChanged("type");
}
}
/// this is an attribute and fails : (
[System.Xml.Serialization.XmlAttributeAttribute(Form = System.Xml.Schema.XmlSchemaForm.Qualified)]
public long id {
get {
return this.idField;
}
set {
this.idField = value;
this.RaisePropertyChanged("id");
}
}
I know that the attribute is being set by the server as the method works fine in our java app, returning xml like this
<soap:Envelope>
<soap:Body>
<ns1:getFolderStructureResponse>
<ns1:result>
<folders>
<folder id="1">
<children>
<folder id="427">
<children/>
<copyId>18904</copyId>
<createdBy>203</createdBy>
<type>user</type>..... etc.
Any idea what might be going wrong?
|
|
|
|
|
OK this seems to be working now : )
I changed this
[System.Xml.Serialization.XmlAttributeAttribute(Form = System.Xml.Schema.XmlSchemaForm.Qualified)]
to this
[System.Xml.Serialization.XmlAttributeAttribute(Form = System.Xml.Schema.XmlSchemaForm.Unqualified)]
So it seems that Qualified is referring to explicitly setting the namespace on an attribute.
|
|
|
|
|
How to write the SQL DB connection string in namespace file.Then i wanna add that connection string like "using DBconn;" <<DbConn should be connection string>>
If you know that how to write DB Connection string using webconfig file also welcome.
BD is MSSQL 2005
Programing language : C#
Web development using ASP.Net
If some one know please reply me
Thank you..!!!
ReGRdZZZ
CheeN
|
|
|
|