Wrox Home  
Search P2P Archive for: Go

  Return to Index  

aspx_professional thread: Object oriented question.


Message #1 by "TWU-Luckett, Jeff" <JeffL@t...> on Mon, 20 May 2002 11:21:48 -0500
This message is in MIME format. Since your mail reader does not understand
this format, some or all of this message may not be legible.

------_=_NextPart_001_01C200C4.26735D80
Content-Type: text/plain

Oh yeah...
 
public enum DataType
{
    String = 0,
    Number = 1
}
 
huh?
 
- Chuck

-----Original Message-----
From: TWU-Luckett, Jeff [mailto:JeffL@t...]
Sent: Monday, May 20, 2002 6:30 PM
To: ASPX_Professional
Subject: [aspx_professional] RE: Object oriented question.


That works great!  All I had to put in was a enum property of which datatype
I was storing so I could figure out how to update the database.  Thanks a
million.
 
Jeff

-----Original Message-----
From: Feduke Cntr Charles R [mailto:FedukeCR@m...] 
Sent: Monday, May 20, 2002 12:21 PM
To: ASPX_Professional
Subject: [aspx_professional] RE: Object oriented question.


Jeff,
 
    I think what you are looking for is property overloading, which is
something .NET does not support.  However, there are clean ways of doing
your own property overloading - keep in mind the lowest common denominator
for variables in .NET is "object", not "variant" as used in VB6.  C#
pseudo-code follows:
 
public class Attribute
{
    private string _value = "";
    private string _field = "";
 
    /// database field name
    public string Field
    {
        get { return _field; }
        set { _field = value; }
     }
 
    /// the value
    public object Value
    {
        get { return _value; }
        set { _value = value; }
     }
 
    /* the method below does something with value, depending
       on the type
    */
    public override string ToString()
    {
                // yes there is a VB-equiv for typeof, you can always
                // use object.GetType().ToString() to get stuff like
                // "System.Integer", but try to use the typeof or equiv
                // for VB as it is faster (natively).
        switch (typeof(_value))
        {
            case System.Integer :
            {
                return _value.ToString();
            }
            case System.String :
            {
                return "'" + _value.Replace("'", "''") + "'";
            }
        }
    }   
}
 
    Now you might want to consider posting what you're trying to do.  From
the looks of this, there might already be classes within the .NET framework
to accomplish what you're trying to do, or there are people on the list who
have created similiar classes and might be able to lend you some best
practices.
 
HTH,
- Chuck

-----Original Message-----
From: TWU-Luckett, Jeff [mailto:JeffL@t...]
Sent: Monday, May 20, 2002 12:22 PM
To: ASPX_Professional
Subject: [aspx_professional] Object oriented question.


I have a object-oriented programming problem from a VB6 developer.
 
    I have an object that will have dynamic attributes set up by a user.
These attributes can be single-valued, or multi-valued.  I've worked that
part out, but now I'm wondering about data types.  Let's say I've got a SVA
that is decimal, and a SVA that is a string.  How can I make the object
differentiate between the two without having a property for each data type,
then having to figure out which property has a value when it comes time to
write to the db.  I guess I will have a DB column for each unless someone
knows of something better.  I need a real-world example of how to make the
object do the work of figuring out which data type is present.  I have books
on order for .Net finally, but I can't wait to figure this out.  Thanks for
your help.
 
Class Single_Valued_Attribute
    Property Attr_Value as String
        Get ...
        Let ...
    end property
    ...
End Class
 
Jeff Luckett
jeffl@t... <mailto:jeffl@t...> 
(xxx) xxx-xxxx
--- 

--- 

--- 



  Return to Index