Hello,
I have the following class:
public class Google : ConfigurationElement, IKeyProvider {
[ConfigurationProperty("Key", IsRequired = true)]
public string Key {
get { return this["Key"] as string; }
} // Key
[ConfigurationProperty("Type", IsRequired = true)]
public string Type {
get { return this["Type"] as string; }
} // Type
} // Google
I have many classes similar to this where the common factor is the Key
so I created:
interface IKeyProvider {
string Key { get; set; }
} // IKeyProvider
However, on my Google class I get an error:
'MyApp.Configuration.Google' does not implement interface member
'MyApp.Configuration.IKeyProvider.Key.set'
How can I fix this?
Thanks,
Miguel 6 1318
shapper wrote:
Hello,
I have the following class:
public class Google : ConfigurationElement, IKeyProvider {
[ConfigurationProperty("Key", IsRequired = true)]
public string Key {
get { return this["Key"] as string; }
} // Key
[ConfigurationProperty("Type", IsRequired = true)]
public string Type {
get { return this["Type"] as string; }
} // Type
} // Google
I have many classes similar to this where the common factor is the Key
so I created:
interface IKeyProvider {
string Key { get; set; }
} // IKeyProvider
However, on my Google class I get an error:
'MyApp.Configuration.Google' does not implement interface member
'MyApp.Configuration.IKeyProvider.Key.set'
How can I fix this?
Thanks,
Miguel
You are not implementing IKeyProvider.Key.set! So, if you really don't
want that, still add it and throw some exception from it. Like this
public class Google : ConfigurationElement, IKeyProvider {
[ConfigurationProperty("Key", IsRequired = true)]
public string Key {
get { return this["Key"] as string; }
set{ throw new Exception("Method not impl");}
} // Key
[ConfigurationProperty("Type", IsRequired = true)]
public string Type {
get { return this["Type"] as string; }
} // Type
} // Google
On Nov 6, 6:55*pm, Ashutosh Bhawasinka <discuss...@ashutosh.inwrote:
shapper wrote:
Hello,
I have the following class:
* public class Google : ConfigurationElement, IKeyProvider {
* * [ConfigurationProperty("Key", IsRequired = true)]
* * public string Key {
* * * get { return this["Key"] as string; }
* * } // Key
* * [ConfigurationProperty("Type", IsRequired = true)]
* * public string Type {
* * * get { return this["Type"] as string; }
* * } // Type
* } // Google
I have many classes similar to this where the common factor is the Key
so I created:
* interface IKeyProvider {
* * string Key { get; set; }
* } // IKeyProvider
However, on my Google class I get an error:
'MyApp.Configuration.Google' does not implement interface member
'MyApp.Configuration.IKeyProvider.Key.set'
How can I fix this?
Thanks,
Miguel
You are not implementing IKeyProvider.Key.set! So, if you really don't
want that, still add it and throw some exception from it. Like this
* public class Google : ConfigurationElement, IKeyProvider {
* * [ConfigurationProperty("Key", IsRequired = true)]
* * public string Key {
* * * get { return this["Key"] as string; }
* * * * set{ throw new Exception("Method not impl");}
* * } // Key
* * [ConfigurationProperty("Type", IsRequired = true)]
* * public string Type {
* * * get { return this["Type"] as string; }
* * } // Type
* } // Google
I am not sure if I want or not ... :-)
Basically, I have various classes of this type and I need a generic
way to filter an instance of one of these classes as follows:
foreach (IKeyProvider element in child) {
if (element.Key == providedKey) return element;
}
So basically I am looking for an element which key is equal to
providedKey.
Element can be an instance of Google, Mail, Site, ... All these
classes inherit from ConfigurationElement and have a common property:
Key.
Do I need a set?
And can you tell me how it would look?
I am moving from VB.NET to C# and sometimes I get shucked in this
things.
Thanks,
Miguel
shapper wrote:
On Nov 6, 6:55 pm, Ashutosh Bhawasinka <discuss...@ashutosh.inwrote:
>shapper wrote:
>>Hello,
I have the following class:
public class Google : ConfigurationElement, IKeyProvider { [ConfigurationProperty("Key", IsRequired = true)] public string Key { get { return this["Key"] as string; } } // Key [ConfigurationProperty("Type", IsRequired = true)] public string Type { get { return this["Type"] as string; } } // Type } // Google
I have many classes similar to this where the common factor is the Key so I created: interface IKeyProvider { string Key { get; set; } } // IKeyProvider
However, on my Google class I get an error: 'MyApp.Configuration.Google' does not implement interface member 'MyApp.Configuration.IKeyProvider.Key.set'
How can I fix this?
Thanks, Miguel
You are not implementing IKeyProvider.Key.set! So, if you really don't want that, still add it and throw some exception from it. Like this
public class Google : ConfigurationElement, IKeyProvider { [ConfigurationProperty("Key", IsRequired = true)] public string Key { get { return this["Key"] as string; } set{ throw new Exception("Method not impl");} } // Key [ConfigurationProperty("Type", IsRequired = true)] public string Type { get { return this["Type"] as string; } } // Type } // Google
I am not sure if I want or not ... :-)
Basically, I have various classes of this type and I need a generic
way to filter an instance of one of these classes as follows:
foreach (IKeyProvider element in child) {
if (element.Key == providedKey) return element;
}
So basically I am looking for an element which key is equal to
providedKey.
Element can be an instance of Google, Mail, Site, ... All these
classes inherit from ConfigurationElement and have a common property:
Key.
Do I need a set?
And can you tell me how it would look?
I am moving from VB.NET to C# and sometimes I get shucked in this
things.
Thanks,
Miguel
If you have an interface, then you need to implement all it's method. If
any method of the interface doesn't make sense to your class, you still
need to implement it and throw an exception from it.
The code you just posted (foreach) will work perfectly fine.
I added the code for the "set"...just check it!
On Thu, 06 Nov 2008 11:19:00 -0800, shapper <md*****@gmail.comwrote:
[...]
So basically I am looking for an element which key is equal to
providedKey.
Element can be an instance of Google, Mail, Site, ... All these
classes inherit from ConfigurationElement and have a common property:
Key.
Do I need a set?
Only you can say.
But, if you're only ever _getting_ the property, then no, you don't need a
setter. And if that's the case, just remove the "set;" from the interface
declaration.
Pete
On Nov 6, 7:35*pm, Ashutosh Bhawasinka <discuss...@ashutosh.inwrote:
shapper wrote:
On Nov 6, 6:55 pm, Ashutosh Bhawasinka <discuss...@ashutosh.inwrote:
shapper wrote:
>Hello,
>I have the following class:
>* public class Google : ConfigurationElement, IKeyProvider { * * [ConfigurationProperty("Key", IsRequired = true)] * * public string Key { * * * get { return this["Key"] as string; } * * } // Key * * [ConfigurationProperty("Type", IsRequired = true)] * * public string Type { * * * get { return this["Type"] as string; } * * } // Type * } // Google
>I have many classes similar to this where the common factor is the Key so I created: * interface IKeyProvider { * * string Key { get; set; } * } // IKeyProvider
>However, on my Google class I get an error: 'MyApp.Configuration.Google' does not implement interface member 'MyApp.Configuration.IKeyProvider.Key.set'
>How can I fix this?
>Thanks, Miguel
You are not implementing IKeyProvider.Key.set! So, if you really don't
want that, still add it and throw some exception from it. Like this
* public class Google : ConfigurationElement, IKeyProvider {
* * [ConfigurationProperty("Key", IsRequired = true)]
* * public string Key {
* * * get { return this["Key"] as string; }
* * * * set{ throw new Exception("Method not impl");}
* * } // Key
* * [ConfigurationProperty("Type", IsRequired = true)]
* * public string Type {
* * * get { return this["Type"] as string; }
* * } // Type
* } // Google
I am not sure if I want or not ... :-)
Basically, I have various classes of this type and I need a generic
way to filter an instance of one of these classes as follows:
* foreach (IKeyProvider element in child) {
* * if (element.Key == providedKey) return element;
* }
So basically I am looking for an element which key is equal to
providedKey.
Element can be an instance of Google, Mail, Site, ... All these
classes inherit from ConfigurationElement and have a common property:
Key.
Do I need a set?
And can you tell me how it would look?
I am moving from VB.NET to C# and sometimes I get shucked in this
things.
Thanks,
Miguel
If you have an interface, then you need to implement all it's method. If
any method of the interface doesn't make sense to your class, you still
need to implement it and throw an exception from it.
The code you just posted (foreach) will work perfectly fine.
I added the code for the "set"...just check it!
Thanks! Sorry that I didn't see it ... I am used to ReadyOnly VB
properties ...
On Nov 6, 7:39*pm, "Peter Duniho" <NpOeStPe...@nnowslpianmk.com>
wrote:
On Thu, 06 Nov 2008 11:19:00 -0800, shapper <mdmo...@gmail.comwrote:
[...]
So basically I am looking for an element which key is equal to
providedKey.
Element can be an instance of Google, Mail, Site, ... All these
classes inherit from ConfigurationElement and have a common property:
Key.
Do I need a set?
Only you can say.
But, if you're only ever _getting_ the property, then no, you don't need a *
setter. *And if that's the case, just remove the "set;" from the interface *
declaration.
Pete
Thanks. It is working now ... finally. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Christof Warlich |
last post by:
Hi,
I'm looking for a more concise way than below to extend an existing
interface.
Just imagine that class Interface would have 1000 other members and class
DerivedInterface only needs to add...
|
by: zlst |
last post by:
Many technological innovations rely upon User Interface Design to elevate
their technical complexity to a usable product. Technology alone may not win
user acceptance and subsequent marketability....
|
by: Laurent Vigne |
last post by:
Hello, I would like to know how to make the methods of an interface
inaccessible from outside
Example:
----------------------------------------------
internal Interface ImyInterface
{
void...
|
by: Alex Sedow |
last post by:
Why interface-event-declaration does not support multiple declarators like
event-declaration?
Grammar from C# spec:
variable-declarators:
variable-declarator
variable-declarators ","...
|
by: Sohum |
last post by:
Hi
I'm reasonably new to this group, and to programming in general.
I'd like to know, can you selectively scope within an interface?
For example:
Public Interface MyInterface
Friend...
|
by: Jordan |
last post by:
In OOP literature we read frequently about "interface" - a term which is
apparently used to mean different things depending on context and possibly
language.
..NET however provides for the...
|
by: Raja Chandrasekaran |
last post by:
Hai friends,
I really wonder, If the interface does not have any
definition, Y do we need to use interface. You can then only we can use
Multiple inheritance. I really cant understand, Just for...
|
by: Oleg Subachev |
last post by:
I have one interface "Intf1" with read-write property "Prop" (with "get" and
"set" accessors).
Then I declare derived interface "Intf2" with the same property "Prop"
declared as read-only...
|
by: Rich |
last post by:
Hello,
my project (vb2005) contains several classes that each produce lists of data
which get stored/displayed in ado.net tables that have the same structure for
each of the lists produced by...
|
by: greenxiar |
last post by:
How to get the function from "rewrited interface implement"?
interface I {
int Value { get; }
}
class A : I {
int I.Value { get { return 1; } }
}
class B : I {
int I.Value { get { return 2;...
|
by: DolphinDB |
last post by:
Tired of spending countless mintues downsampling your data? Look no further!
In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
|
by: ryjfgjl |
last post by:
ExcelToDatabase: batch import excel into database automatically...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: Vimpel783 |
last post by:
Hello!
Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
|
by: CloudSolutions |
last post by:
Introduction:
For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
|
by: Defcon1945 |
last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
|
by: Shællîpôpï 09 |
last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
|
by: Faith0G |
last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome former...
| |