473,395 Members | 1,977 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

IDataErrorInfo Interface

I really want to use the IDataErrorInfo interface. I'm using it now in
combination with an ErrorProvider and this seems really good.

But the downside: IDataErrorInfo wants to use a string indexer on my
class. No big deal, but now I have a class where I want to use my own
string indexer. This is frustrating.

Do I have to do something funky like add an extra argument to my
indexer? Is there a better way?

Help...

--Brian

Expand|Select|Wrap|Line Numbers
  1.  
  2.  
  3. class MyClass
  4. {
  5. //Here is the indexer for IDataErrorInfo:
  6. public string this[string name]
  7. {
  8. get { ... }
  9. }
  10.  
  11. //Here is my indexer:
  12. public string this[string name, bool x]
  13. {
  14. get { ... }
  15. }
  16. }
  17.  
  18.  
Jun 22 '06 #1
4 7518
Brian <no@email.com> wrote:
I really want to use the IDataErrorInfo interface. I'm using it now in
combination with an ErrorProvider and this seems really good.

But the downside: IDataErrorInfo wants to use a string indexer on my
class. No big deal, but now I have a class where I want to use my own
string indexer. This is frustrating.

Do I have to do something funky like add an extra argument to my
indexer? Is there a better way?
Yes. Use explicit interface implementation.
class MyClass class MyClass : IDataErrorInfo {
//Here is the indexer for IDataErrorInfo:
public string this[string name] string IDataErrorInfo.this[string name] {
get { ... }
}

//Here is my indexer:
public string this[string name, bool x] public string this[string name] {
get { ... }
}
}


-- Barry

--
http://barrkel.blogspot.com/
Jun 23 '06 #2
Brian wrote:
I really want to use the IDataErrorInfo interface. I'm using it now in
combination with an ErrorProvider and this seems really good.

But the downside: IDataErrorInfo wants to use a string indexer on my
class. No big deal, but now I have a class where I want to use my own
string indexer. This is frustrating.

Do I have to do something funky like add an extra argument to my
indexer? Is there a better way?

Help...

--Brian

Expand|Select|Wrap|Line Numbers
  1.       class MyClass
  2.       {
  3.           //Here is the indexer for IDataErrorInfo:
  4.           public string this[string name]
  5.           {
  6.               get { ... }
  7.           }
  8.           //Here is my indexer:
  9.           public string this[string name, bool x]
  10.           {
  11.               get { ... }
  12.           }
  13.       }
  14.  


Hi Brian, just explicitly implement the IDataErrorInfo interface:

class MyClass
{
public IDataErrorInfo.this[string columnName]
{
get { ... }
}

public string this[string name]
{
get { ... }
}
}

This does however introduce some implications when you want to access the
IDataErrorInfo implementation of the indexer, that is, the instance of
MyClass will need to be explicitly cast to IDataErrorInfo in order to
access the implementation of the indexer:

((IDataErrorInfo)MyClassInstance)["foobar"]

Hope this helps,
-- Tom Spink
Jun 23 '06 #3
Brian wrote:
I really want to use the IDataErrorInfo interface. I'm using it now
in combination with an ErrorProvider and this seems really good.

But the downside: IDataErrorInfo wants to use a string indexer on my
class. No big deal, but now I have a class where I want to use my
own string indexer. This is frustrating.

Do I have to do something funky like add an extra argument to my
indexer? Is there a better way?


The IDataErrorInfo interface is used for runtime databinding info
reporting, it's not used for error info reporting for your own usage.
This means that the bound controls know what to pass to IDataErrorInfo
to retrieve an error message. If you want to use the IDataErrorInfo
interface for something else, you're using it for a different purpose
and then it might well be that it pretty lacks a lot. So for those
purposes, implement your own interface.

FB

--
------------------------------------------------------------------------
Lead developer of LLBLGen Pro, the productive O/R mapper for .NET
LLBLGen Pro website: http://www.llblgen.com
My .NET blog: http://weblogs.asp.net/fbouma
Microsoft MVP (C#)
------------------------------------------------------------------------
Jun 23 '06 #4
Tom Spink wrote:
Brian wrote:
I really want to use the IDataErrorInfo interface. I'm using it now in
combination with an ErrorProvider and this seems really good.

But the downside: IDataErrorInfo wants to use a string indexer on my
class. No big deal, but now I have a class where I want to use my own
string indexer. This is frustrating.

Do I have to do something funky like add an extra argument to my
indexer? Is there a better way?

Help...

--Brian

Expand|Select|Wrap|Line Numbers
  1.       class MyClass
  2.       {
  3.           //Here is the indexer for IDataErrorInfo:
  4.           public string this[string name]
  5.           {
  6.               get { ... }
  7.           }
  8.           //Here is my indexer:
  9.           public string this[string name, bool x]
  10.           {
  11.               get { ... }
  12.           }
  13.       }
  14.  


Hi Brian, just explicitly implement the IDataErrorInfo interface:

class MyClass
{
public IDataErrorInfo.this[string columnName]
{
get { ... }
}

public string this[string name]
{
get { ... }
}
}

This does however introduce some implications when you want to access the
IDataErrorInfo implementation of the indexer, that is, the instance of
MyClass will need to be explicitly cast to IDataErrorInfo in order to
access the implementation of the indexer:

((IDataErrorInfo)MyClassInstance)["foobar"]

Hope this helps,
-- Tom Spink


That is AWESOME!!!

Oh this is too cool. Thank you guys so much!

--Brian
Jun 23 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Roy Pereira | last post by:
I have an application that is composed of a set of "Content" dlls and a viewer application. The viewer calls a standard set of functions that are present in all the dlls. I maintain this by...
9
by: Anon Email | last post by:
Hi people, I'm learning about header files in C++. The following is code from Bartosz Milewski: // Code const int maxStack = 16; class IStack
4
by: Doug | last post by:
I am working on an existing .NET (C Sharp) component that had a com interface that was used by a VB component. When it was originally written, it had the SSEAssemblyCom class below - minus the two...
3
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....
6
by: Alex Sedow | last post by:
Example 1 interface I { string ToString(); } public class C : I { public void f() {
20
by: Ole Hanson | last post by:
I am accessing my database through an interface, to allow future substitution of the physical datastore - hence I would like to declare in my Interface that my DAL-objects implementing the...
2
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 ","...
0
by: YellowFin Announcements | last post by:
Introduction Usability and relevance have been identified as the major factors preventing mass adoption of Business Intelligence applications. What we have today are traditional BI tools that...
15
by: Xah Lee | last post by:
On Java's Interface Xah Lee, 20050223 In Java the language, there's this a keyword “interface”. In a functional language, a function can be specified by its name and parameter specs....
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
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...
0
BarryA
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...
1
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...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
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,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development projectplanning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.