Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Interfaces
Message
De
18/01/2010 21:15:34
 
 
Information générale
Forum:
ASP.NET
Catégorie:
Autre
Titre:
Versions des environnements
Environment:
C# 2.0
Divers
Thread ID:
01444635
Message ID:
01444671
Vues:
52
>>>Hi,
>>>
>>>I ran into the following issue with Interfaces:
>>>
>>>Some form class implements an interface, e.g. IMyInterface.
>>>
>>>The textboxes on the form are based on textboxes in a class library like this:
>>>
>>>
>>>namespace MyCompany
>>>{
>>>
>>>    public class MyTextBox : System.Windows.Forms.TextBox
>>>    {
>>>        protected override void OnTextChanged(EventArgs e)
>>>        {
>>>            Control o = this.parent;
>>>            if (o != null && (o is IMyInterface))
>>>            {
>>>                ((IMyInterface)o).MyMethod(false);
>>>            }
>>>            base.OnTextChanged(e);
>>>        }
>>>    }
>>>
>>>}
>>>
>>>
>>>Compiler complaints that IMyInterface "The type of namespace 'IMyInterface' could not be found..." Do I need to declare the Interface in this library too? What else am I missing?
>>>
>>>TIA.
>>
>>What is the namespace of IMyInterface? It seems like you might need to add an import statement or fully qualify it.
>
>This is what I am not sure about. The Namespace of the IMyInterface in the class where the interface belongs. This code (above) is a base class of Textbox used by many other classes. And since this class library is "generic" adding import to it does not make sense to me (or maybe I don't see something simple).

The compiler has to know what IMyInterface is inorder to be able to compile your code.

So the project you are in needs to reference the project where the interface is defined and the name space needs to either be in a using statement or included in the reference to IMyInterface. Otherwise it has no clue as to what IMyInterface is.

1. Add a reference to the project with IMyInterface to your current project
2. Add: using MyNamespce; at the start of the file.

It should then be able to compile your code.
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform