.NET Forum / Languages / C# / March 2008
Making Definitions
|
|
Thread rating:  |
Devon-S - 10 Mar 2008 00:50 GMT Greetings,
I am trying to make a definition like FormView.Insert. I have figured out how to make an eNum, but they seem to be attached to a subclass in VS2005.
I have a class that displays three images of three size and I am hoping to make an ImageSize.Small, ImageSize.Medium, ImageSize.Right.
I tried making a class with static members but the result was not the same Internal List.
Anyhelp would be appreciated.
Devon
Peter Duniho - 10 Mar 2008 01:04 GMT > I am trying to make a definition like FormView.Insert. I have figured out > how to make an eNum, but they seem to be attached to a subclass in > VS2005. What do you mean, "attached to a subclass"?
> I have a class that displays three images of three size and I am hoping > to > make an ImageSize.Small, ImageSize.Medium, ImageSize.Right. You may find this page, documenting the "enum" keyword in C#, useful for your cause: http://msdn2.microsoft.com/en-us/library/sbbt4032.aspx
If after reading the documentation and following its example you have some specific questions, please feel free to post those specific questions here.
Pete
Devon-S - 10 Mar 2008 15:01 GMT Pete,
I wasn't asking how enum works it doesn't produce the result I wanted.
I wondered what kind of thing is FormView.Insert. It is not an enum as both items are colored Cyan and it appears like a proper type.
Do you know how to created a FormView.Insert type thing?
Devon
> > I am trying to make a definition like FormView.Insert. I have figured out > > how to make an eNum, but they seem to be attached to a subclass in [quoted text clipped - 14 lines] > > Pete Jon Skeet [C# MVP] - 10 Mar 2008 15:13 GMT > I wasn't asking how enum works it doesn't produce the result I wanted. Well, you previously said that enums "seem to be attached to a subclass in VS2005" which suggests that you don't understand them. That in turn means that it's possible that they *could* produce the result you want, if you understood them better...
> I wondered what kind of thing is FormView.Insert. It is not an enum as both > items are colored Cyan and it appears like a proper type. > > Do you know how to created a FormView.Insert type thing? I can't see FormView.Insert at all. (I can see FormView.InsertItem, but that's just a method.) What exact member are you talking about? Do you have an MSDN link for it?
 Signature Jon Skeet - <skeet@pobox.com> http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet World class .NET training in the UK: http://iterativetraining.co.uk
Devon-S - 10 Mar 2008 15:33 GMT John,
There is a great chance that I don't truely understand the enum. But since the only examples at the link work exactly as I said in a class, sending me back to how I didn't want them to work wasn't helpful to my lack of understanding.
But back to the problem...
There is a (something could be a type or a class) called FormViewMode. When you want to change the mode of the form you do.
FormView1.ChangeMode(FormViewMode.Insert)
The great thing about the FormViewMode is it appears as a type so you can make it a property of another class
public partial class ImageStore
protected FormViewMode _fvmCurrentMode;
public FormViewMode CurrentMode { get { return _fvmCurrentMode ; } set { _fvmCurrentMode = value ; } }
}
I would like to create a (whatever form view mode is) for ImageSize and have three properties. Small Medium Large. I know I can do it sorta with an eNum. But when I went to use it to access it, I had to do <Class>.EnumType.Property
With ImageSize it is actually going to be in lots of different places like FormViewMode.
Appreciating the C# enlightenment...
devon
> > I wasn't asking how enum works it doesn't produce the result I wanted. > [quoted text clipped - 11 lines] > that's just a method.) What exact member are you talking about? Do you > have an MSDN link for it? Jon Skeet [C# MVP] - 10 Mar 2008 15:54 GMT > There is a great chance that I don't truely understand the enum. But since > the only examples at the link work exactly as I said in a class, sending me > back to how I didn't want them to work wasn't helpful to my lack of > understanding. Peter didn't send you *back* to them - he sent you *to* them. You gave no indication that you'd already looked at that page.
Furthermore, although the Days example is indeed a nested type (not a subclass, by the way), the CarOptions one isn't.
> But back to the problem... > > There is a (something could be a type or a class) called FormViewMode. When > you want to change the mode of the form you do. > > FormView1.ChangeMode(FormViewMode.Insert) Ah, FormViewMode. Not FormView, which is a class. Yes, FormViewMode is an enum, and Insert is a member of that enum.
<snip>
> I would like to create a (whatever form view mode is) for ImageSize and have > three properties. Small Medium Large. I know I can do it sorta with an eNum. > But when I went to use it to access it, I had to do <Class>.EnumType.Property Only if you make it a nested type.
> With ImageSize it is actually going to be in lots of different places like > FormViewMode. > > Appreciating the C# enlightenment... Just declare the enum outside any other type.
 Signature Jon Skeet - <skeet@pobox.com> http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet World class .NET training in the UK: http://iterativetraining.co.uk
Devon-S - 10 Mar 2008 18:37 GMT Jon,
>> Just declare the enum outside any other type. Thanks, I do appreciate the help. This nearly has it for me, but I don't see how I use the declaration in other assemblies then. I know I should go back and read a c# manual, but most of the time I get it (at least somewhat).
The ImageDisplaySize is used in a WebControl and in the top of the file that declares the web control, I put
public enum ImageDisplaySize { Small, Medium, Large }
I would expect to be able to use it where I had dragged the WebUC onto the page. But it doesnt appear when I go to set the property type.
I am sure this is very easy on the "Easy Button" scale. Appreciate the help.
regards:jamie
> > There is a great chance that I don't truely understand the enum. But since > > the only examples at the link work exactly as I said in a class, sending me [quoted text clipped - 31 lines] > > Just declare the enum outside any other type. Peter Duniho - 10 Mar 2008 18:49 GMT > Jon, > [quoted text clipped - 5 lines] > back > and read a c# manual, but most of the time I get it (at least somewhat). Yes, but when you don't "get it", reading the documentation is a great place to start.
That said, you use your enum from other assemblies the same way you'd use any type in that assembly from another assembly. An enum is just another type. If you have learned how to use in some assembly any type you've declared in another assembly, then you already know how to do the same with an enum.
If you don't know that, then your question isn't really about enums per se.
Pete
Devon-S - 10 Mar 2008 19:11 GMT Peter,
I agree I am not getting it, because normally when I want to use a WEb Control in another assembly, I just drag in the webcontrol and it is registered, and you can use the things in that assembly. But the enum values don't appear.
When i put it inside the class it works, when it is not in the class it does not work.
Maybe my question isn't about enums maybe it is about how some parts of some namespaces are automatically registered when other parts are not.
But if I knew what my question was about I would not have been so vague. This is my very first time ever using an enum.
This is my very first time in 2 years of C# where the value I was trying to pass was a tri-state and not just a bool or a string. So today is the day I have to figure it out.
Any help would be appreciated. Once I read through the manual on types, enums, static declarations, I decided I didn't know which is commonly used and decided to ask for help.
Devon
> > Jon, > > [quoted text clipped - 18 lines] > > Pete Peter Duniho - 11 Mar 2008 02:16 GMT > I agree I am not getting it, because normally when I want to use a WEb > Control in another assembly, I just drag in the webcontrol and it is > registered, and you can use the things in that assembly. But the enum > values > don't appear. Well, when you "drag in the webcontrol" (from where do you drag it?), obviously something happens that allows the class defining the web control to be used. The class is a type, just like an enum is a type.
So even if the Designer is doing something automatic, you should be able to look at the source code it generates that allows you to use the web control type, and replicate that so that you can use the enum type. If the two types are declared in the same source file and namespace, I would expect the enum to practically "just work", but if not, it can't be that hard.
Unfortunately, I don't have any direct experience with the web control part of .NET. Your question has a straightforward answer for a regular C# application, but if you get HTML and a web server involved, it goes outside my realm of experience. I suspect the answer is as straightforward as it is for a regular C# application, but I can't tell you for sure.
> When i put it inside the class it works, when it is not in the class it > does [quoted text clipped - 3 lines] > some > namespaces are automatically registered when other parts are not. Maybe. But I doubt it. That's certainly not an issue with respect to non-web applications. If you have access to anything declared in a given assembly under a given namespace, you have access to everything in that assembly under that namespace. You don't get "parts" of a namespace if all the parts are in the same assembly.
I think that the advice Jon's offered is useful. Another thing you might do is actually create two different projects in two different solutions, one in which you declare the enum, and another in which you use it. The first project will be built as a library, and the second as an application. It complicates things a little, but it has the advantage of clearly showing the relationship between a namespace, an assembly in which things in that namespace are defined, and a different assembly that uses the first one.
If the example Jon suggest clears things up, great. If not, consider breaking it apart a little more as I describe above.
Finally, if none of that works, you may simply want to post a concise-but-complete example of code that reliably demonstrates what you're trying to do. Since it's apparently a web-based project, you may want to provide a little extra detail about how the code is actually used. For someone who already knows about using the web controls stuff, that shouldn't be necessary, but if your question is really about C#, posting a web control-based example without some information as to how to use it will unnecessarily restrict the people who might otherwise be able to answer the question (excluding, for example, me :) ).
Pete
Jon Skeet [C# MVP] - 10 Mar 2008 19:28 GMT > >> Just declare the enum outside any other type. > > Thanks, I do appreciate the help. This nearly has it for me, but I don't see > how I use the declaration in other assemblies then. I know I should go back > and read a c# manual, but most of the time I get it (at least somewhat). Well, I'd certainly recommend learning C# "properly" rather just taking a sort of "hit and hope" approach. It may work for a while, but sooner or later you're bound to run up against problems due to a lack of knowledge of the theory behind it all.
> The ImageDisplaySize is used in a WebControl and in the top of the file that > declares the web control, I put [quoted text clipped - 6 lines] > I am sure this is very easy on the "Easy Button" scale. Appreciate > the help. When you saying you're trying to set the property type, do you mean you're trying to set the property *value* in the designer, or you're trying to set the property *type* in the web control class itself?
If you're in code, but in a different class, do you have the appropriate "using" directive for the namespace containing the enum?
 Signature Jon Skeet - <skeet@pobox.com> http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet World class .NET training in the UK: http://iterativetraining.co.uk
Devon-S - 10 Mar 2008 19:53 GMT > Well, I'd certainly recommend learning C# "properly" rather just taking > a sort of "hit and hope" approach. It may work for a while, but sooner > or later you're bound to run up against problems due to a lack of > knowledge of the theory behind it all. I am not really sure the best way to achieve that result. Their are no MS C# classes withing 1000 miles of where I live, and most of the practical on-line stuff is sometimes good and bad. Since C# is about my 10th language (Assembler, Basic, Fortran, dbase, clipper, FoxPro, delphi, c, c++, LotusScript), to learn it is sometimes the nuances that I don't get at first, but as I use them, I study them.
And when I don't understand I post a question.
> When you saying you're trying to set the property type, do you mean > you're trying to set the property *value* in the designer, or you're > trying to set the property *type* in the web control class itself? Point 2 the property type in the web control class itself.
> If you're in code, but in a different class, do you have the > appropriate "using" directive for the namespace containing the enum? This is a part I know I am a bit weak on, as it is now outside the class in the same file that in the .ascx file is register src="../WebUCs/<thefile.ascx>.
Normally this lets me see the properties and methods in the file via the WebControl ID. But it doesn't see the enum unless I put it back in the class.
And do try and get the tone of my posting, I do appreciate your help,
Devon
Jon Skeet [C# MVP] - 10 Mar 2008 20:26 GMT > > Well, I'd certainly recommend learning C# "properly" rather just taking > > a sort of "hit and hope" approach. It may work for a while, but sooner [quoted text clipped - 9 lines] > > And when I don't understand I post a question. I woud suggest getting a book. Now of course *which* book is the next question... I rather like Essential C# by Mark Michaelis. Others will no doubt have other recommendations.
> > When you saying you're trying to set the property type, do you mean > > you're trying to set the property *value* in the designer, or you're > > trying to set the property *type* in the web control class itself? > > Point 2 the property type in the web control class itself. You should just be able to declare it to be the appropriate type:
public ImageDisplaySize DisplaySize { get { ... } set { ... } }
> > If you're in code, but in a different class, do you have the > > appropriate "using" directive for the namespace containing the enum? > > This is a part I know I am a bit weak on, as it is now outside the class in > the same file that in the .ascx file is register > src="../WebUCs/<thefile.ascx>. I would strongly advise putting it in its own file, which should make it obvious which namespace it's in.
> Normally this lets me see the properties and methods in the file via the > WebControl ID. But it doesn't see the enum unless I put it back in the class. I'm a bit lost as to what exactly you're describing at this point.
Here's an idea: put the web control itself to one side for a minute, and write a completely separate test app, just for the sake of understanding a bit more about enums. Create another enum, and a class that uses it for a property; then create an instance of that class from yet *another* class, and set the property. Something like:
ImageDisplaySize.cs: enum (no reason to change it to a different name really)
FakeWebControl.cs: not a real web control, just an ordinary class with a property of type ImageDisplaySize
Program.cs: Entry point which creates an instance of FakeWebControl and sets its property
 Signature Jon Skeet - <skeet@pobox.com> http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet World class .NET training in the UK: http://iterativetraining.co.uk
Devon-S - 10 Mar 2008 20:52 GMT Jon,
> I woud suggest getting a book. Now of course *which* book is the next > question... I rather like Essential C# by Mark Michaelis. Others will > no doubt have other recommendations. Great Idea. I will try this one, as I have gone through a couple that were really, how to use DataGrid with about 5 pages on C#. I used to work with a Mark Michaelis I wonder if it is the same one.
> I would strongly advise putting it in its own file, which should make > it obvious which namespace it's in. Great Idea, going to do just that... Thanks for they great amount of help.
The problem must be me and the namespace.
Many thanks for all of your help;
Devon
Mufaka - 10 Mar 2008 20:27 GMT <snip>
> This is a part I know I am a bit weak on, as it is now outside the class in > the same file that in the .ascx file is register [quoted text clipped - 6 lines] > > Devon Have a read about the App_Code folder in ASP.NET. You will need to put your enum there if you want to share it throughout the application.
Devon-S - 10 Mar 2008 20:53 GMT Mufaka,
Thanks thats another good idea.
All the best,
> <snip> > > [quoted text clipped - 10 lines] > Have a read about the App_Code folder in ASP.NET. You will need to put > your enum there if you want to share it throughout the application.
Free MagazinesGet these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...
|
|
|