Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C#4.0
Hi,
I have 2 projects Namely Accounts and Info
 
One of the class in Accounts Project(Account after public is a column in a table)
 
using System.ComponentModel.Composition;
.......
 
namespace Accounts
{
     [export(typeof(IAccount))]
      public class Account : IAccount
      {
             public Account GetAccountByEmail(string Ema)
             {
              ..........  
             }
       }
}
 
This is my interface(this is another project)
 
namespace Interfaces
{
    public interface IAccount
    {
    }
}
 
this is my code in Info project
 
using System.Componentmodel.Composition;
using Interfaces;
 
public class AccountSer
{
   [Import]
   public IAccount _account;
   {
     public bool bhjyhf(string user)
     { 
          Account account = _account.GetAccountByEmail(user);
          if(account != null)
            return true;
          return false;
     }
    }
}
 
There is an error that IAccount has no extension method(GetAccountByEmail)
What is wrong should i type something in my interface.. or should i do something else??
 
please help me!!
When i Use
private Account _account ;
and proceed... with the rest of the code in the same way i get the required output
 
Please let me know what to do..
 
Thank you.
Posted 16-May-12 4:59am
Sipherz431
Comments
Member 8753169 at 17-May-12 1:48am
   
Thank you Guys!!
But i found out another way
Besides your posts were also equally helpfull
Thanx
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

Your specific error is that you have to define a method in your IAccount interface so that you can use it:
 
namespace Interfaces
{
    public interface IAccount
    {
        Account GetAccountByEmail(string Ema);
    }
}
 
That means that when you attempt to use the method when you have defined an object as IAccount, you can access the method.
 
You can also cast IAccount as Account to do the same.
 
acct = ((Account)iAcct).GetAccountByEmail(ema);
  Permalink  
Comments
losmac at 16-May-12 15:52pm
   
+5!
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

Your question has nothing specific to interfaces. Forget about interfaces for a minute and focus on just inheritance and run-time vs. compile-time types.
 
Consider this:
class Base { / *...* / }
 
class Derived {
    internal DerivedSpecific() { / *...* / }
}
 
//...

// compile-time type: Base, actual run-time type: Derived
Base instance = new Derived();
 
// even though the instance is Derived and Derived.DerivedSpecific can be called,
// instance "does not know" about it during compile time.
// this will fail to compile:
instance.DerivedSpecific(); // compilation failure
Now, Base could be a class or in interface, the nature of your bug is the same. You need to move the method to the base type, in your case, to the interface. The methods specific to the derived class should be called in this class or via its instance, not the instance of the interface (or base class) type. One more thing: you can down-case the instance and still call the method. Don't even think about it — it would be possible but means a bad design and defeat of the purpose of inheritance and encapsulation. You code sample shows that you don't feel these purposes, just yet. You need to review your understanding of OOP from the very beginning, not just the interfaces.
 
—SA
  Permalink  
v2
Comments
VJ Reddy at 16-May-12 12:29pm
   
Good explanation and advice. 5!
SAKryukov at 16-May-12 12:46pm
   
Thank you, VJ.
--SA
losmac at 16-May-12 15:49pm
   
I agree with you, VJ.
+5
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Start with this: Interfaces in C# (For Beginners)[^]
Interfaces - Programming guide[^]
 
If you want more, use Google with phrase: "C# interface"
  Permalink  
Comments
Member 8753169 at 16-May-12 11:12am
   
Ok friend but before that is there some other thing that i should in my interface
SAKryukov at 16-May-12 12:05pm
   
I voted 4. The manual will certainly be helpful, but it's good to note that the problem is more general and related to inheritance and run-time vs. compile-time types, the bases of OOP (even before late binding and dynamic dispatch via virtual methods or interfaces).
Please see my answer.
--SA
losmac at 16-May-12 15:49pm
   
OP doesn't used "General" tag, so my answer is as is ;)
4 is OK ;) Thank you

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 Nirav Prabtani 268
1 OriginalGriff 267
2 _Amy 170
3 Mika Wendelius 165
4 Sergey Alexandrovich Kryukov 162
0 Nirav Prabtani 284
1 OriginalGriff 207
2 _Amy 170
3 Mika Wendelius 165
4 Sergey Alexandrovich Kryukov 119


Advertise | Privacy | Mobile
Web02 | 2.8.140721.1 | Last Updated 16 May 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100