I have this parameter:
public string Title
{
get{return m_sTitle;}
set{m_sTitle = value;}
}
I want to do this:
Object foo = new Object;
foo.Title.IsRequired(); 5 1525
NewGuy <a@a.com> wrote: I have this parameter: public string Title { get{return m_sTitle;} set{m_sTitle = value;} }
I want to do this: Object foo = new Object; foo.Title.IsRequired();
You can't do that for two reasons:
1) The Object type doesn't have a Title property
2) The String type doesn't have an IsRequired method
You could create your own type which encapsulates a string and whether
or not it's required to get round 2) if you wanted, but we'd really
need to know more information to know whether or not it was really
appropriate.
--
Jon Skeet - <sk***@pobox.com> http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Hi NewGuy,
First of all, I would like to confirm my understanding of your issue. From
your description, I understand that you need to extend a property with
required checking. If there is any misunderstanding, please feel free to
let me know.
If you need to extend the property, you need to make m_sTitle another type.
Currently, it is a string type, which does not support IsRequired method.
You have to define your own method in a user defined class. It can be a
subclass inherited from String class. Or just contains string member. Here
is an example:
class title
{
public title()
{
}
public string m_title;
public bool IsRequired()
{
return true;
}
}
class FOO
{
public FOO()
{
}
private title m_sTitle = new title();
public title Title
{
get{return m_sTitle;}
set{m_sTitle = value;}
}
}
HTH.
Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."
Kevin Yu [MSFT] <v-****@online.microsoft.com> wrote: First of all, I would like to confirm my understanding of your issue. From your description, I understand that you need to extend a property with required checking. If there is any misunderstanding, please feel free to let me know.
If you need to extend the property, you need to make m_sTitle another type. Currently, it is a string type, which does not support IsRequired method. You have to define your own method in a user defined class. It can be a subclass inherited from String class.
No, String is sealed - you can't subclass it. Composition is required
instead.
--
Jon Skeet - <sk***@pobox.com> http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Thanks Jon, for pointing me out. Didn't check it before posting.
Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."
Here a sample of the code I would like to write.
public class User
{
private string m_sFoo;
public string Foo
{
get{return m_sFoo;}
set{m_sFoo = value;}
}
}
private class Editor
{
User user = new User();
if (user.Foo.IsRequired())
{ user.Foo = "My Value"; }
else
{ 'do something else' }
}
I have tried adding a new class as Kevin pointed out, the problem is that I
now have a new object and I can't get or set it like a normal string.
"Kevin Yu [MSFT]" <v-****@online.microsoft.com> wrote in message
news:yJ*************@cpmsftngxa06.phx.gbl... Hi NewGuy,
First of all, I would like to confirm my understanding of your issue. From your description, I understand that you need to extend a property with required checking. If there is any misunderstanding, please feel free to let me know.
If you need to extend the property, you need to make m_sTitle another
type. Currently, it is a string type, which does not support IsRequired method. You have to define your own method in a user defined class. It can be a subclass inherited from String class. Or just contains string member. Here is an example:
class title { public title() { } public string m_title; public bool IsRequired() { return true; } }
class FOO { public FOO() {
} private title m_sTitle = new title(); public title Title { get{return m_sTitle;} set{m_sTitle = value;} }
}
HTH.
Kevin Yu ======= "This posting is provided "AS IS" with no warranties, and confers no rights." This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Raj |
last post by:
Hi,
I have a table in which two fields(FirstID, SecondID) together make the
primary key for the table. Let's look at the following example:
FirstID SecondID
******* ********
2 ...
|
by: Henri Sivonen |
last post by:
In order to keep subsequent code clear, I added a new method like this
HTMLDivElement.prototype.foo = function(arg) {
// foo for HTML div trees
}
Element.prototype.foo = function(arg) {
//...
|
by: cwdjrxyz |
last post by:
Javascript has a very small math function list. However there is no
reason that this list can not be extended greatly. Speed is not an
issue, unless you nest complicated calculations several levels...
|
by: Rob |
last post by:
In many articles related to VB.net the word "class" is used...
How many meanings are there to this word ?
"possible to derived a class from another"
"forms are full-fledged classes"
"base...
|
by: Brandon Miller |
last post by:
All,
I have an existing business object (VB.Net) which returns user IDs for our
locations in our regions.
One of the properties objReg.Manager returns the manager's user id (integer)
for a given...
|
by: eman1000 |
last post by:
I was recently looking at the prototype library
(http://prototype.conio.net/) and I noticed the author used the
following syntax:
Object.extend(MyObj.prototype, {
my_meth1: function(){},...
|
by: Christophe Peillet |
last post by:
I am trying to create a BasePage for use in a large asp.net application, that
will centrally provide certain extra properties and logic to the application.
(The web project makes use Master Pages...
|
by: Barry |
last post by:
A beginners question to someone that isn't a beginner ;) I've forgotton
a lot.
The code below isn't what I want to do but it demonstrates succinctly
my problem. I want to drop a "MyTextBox"...
|
by: Jeff |
last post by:
Hey
ASP.NET 2.0
I'm trying to extend the MembershipUser class, and have encounter a problem:
<< See in the middle of this post for info about why I do this >>
<< See below of this post for...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
| |