Reputation: 11
I am going to aplogize in advance because I am really at the limits of my understanding on this so if I do not explain this well....well sorry...
Anyway I am trying to create an asp.net server control that has complex properties which can be set using intellisense. So as an example I will use cars, so the server control might be called car and when I actually implement the control on a webform I want to set complex, hierarchical properties so for example:
<Control:Car Color="Paint.Metalic.CandyRed"
Wheels="Forged.Aluminun.FiveSpoke.GunMetal" />
or
<Control:Car Color="Paint.Matte.Yellow"
Wheels="Forged.Steel.SevenSpoke.BareMetal" />
I have tried creating public properties in the server control that are just types/classes that point to the base class but intellisense doesn't come up with anything. I can use a straight forward enum and that will show up but I can't do anything hierarchical that way. I've been looking for examples but I can't seem to find anything. Any help would be greatly appreciated!!!!
Thank you!
How about a different example as it seems the relationship between items or their intended value, although completely unimportant, seems to be an issue.
Let's take the relationships between continent/ country / state / city / etc.... By this example, if my custom server control is called "Location" then I would like to be able to ...
<Control:Location CurrentLocation="UnitedStates.Nebraska.Lincoln" />
or
<Control:Location CurrentLocation="Europe.Italy.Napoli" />
Upvotes: 1
Views: 1380
Reputation: 161831
Your problem is worse than the previous two answers suggest: you don't know what you're doing.
Sorry to sound so harsh, but where did you ever see something like "Paint.Metalic.CandyRed", and what did it mean there? Or "Forged.Aluminun.FiveSpoke.GunMetal"? What do you even want that to mean?
First, figure out what you want to represent. Then, create a class that can represent it. Then, add a property of that class to the server control. You may have to add a TypeConverter or other designer support in order for ASP.NET to convert your preferred textual representation into an instance of the class. Otherwise, you'll be able to get something like the properties of a Font.
I'm going to make a guess about what some of these values represent, and try to show you how to deal with them in a control. My guess could be far off, though.
I'll work with "Paint.Metalic.CandyRed". I'll assume this applies to the domain of automobile customization, and that the Color property is meant to represent the finish given to the car as a whole. In that case, "Paint" would probably be an enum
referring to the type of finish (though I don't know what other sorts of finish apply to a car!). I know from building model cars when I was a kid that paints may be metallic, or gloss, or flat, so those three would be enum values of one enum. "CandyRed" would be one of many colors. This would give something like this:
public enum FinishType
{
Paint,
NotPaint // _I_ don't know!
}
public enum PaintFinish
{
Metallic,
Gloss,
Flat
}
public enum CarColor
{
CandyRed,
SilverMist,
DesertSandMica,
MagneticGray,
// etc.
}
public class CarFinish
{
public FinishType FinishType {get;set;}
public PaintFinish PaintFinish {get;set;}
public CarColor CarColor {get;set;}
}
public class Car : WebControl
{
public CarFinish Color {get;set;}
}
This would allow for something like this:
<Control:Car Color-FinishType="Paint"
Color-PaintFinish="Metallic"
Color-CarColor="CandyRed" .../>
or this:
<Control:Car ...>
<Color FinishType="Paint" PaintFinish="Metallic" CarColor="CandyRed"/>
</Control:Car>
Upvotes: 9
Reputation: 10837
As Mitchel Sellers posted, they will need to be either Enum or Constants/Statics.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing;
namespace Paint
{
public class Metallic
{
public static Color CandyRed
{
get { return Color.Red; }
}
public static Color CandyGreen
{
get { return Color.Green; }
}
}
public class Matte
{
public static Color Red
{
get { return Color.Red; }
}
public static Color Green
{
get { return Color.Green; }
}
}
}
Upvotes: 0
Reputation: 63136
These items would need to be enums as that is the only way that it is supported at least in everything I have seen. now, you can accomplish what you want with a few enums.
namespace Paint
{
public enum Metalic
{
CandyRed
}
public enum Matte
{
Yellow
}
}
Granted, not perfect, but easy to document and understand!
Upvotes: 0