expresso na

expresso na

  • NA
  • 3
  • 0

Not able to access method from abstract class

Oct 11 2007 11:15 PM

Ok, here's what I did.

I created a new class (copied the same code basically in the Enterprise Library 3.1 Security Block) so that I could create a custom AuthorizationProvider.cs.  So I did that.  And I also created a new Interface much like the one that's already in that project from MS.  I just created a different type of abstract method in my Interface is all and used that new method in my new class that I created.

Anyway, now is time to actually test my class's method.  So I created a new console app in order to allow me to test calling that method to make sure it's working.  So I created a new console app in VS 2005.  I then added a new class in the colsole app and added binary references to it that I thought I needed by looking at the class in the project I was working in.  I also had this console class implement my Interface.  Here's most of the code to give you this picture:

Project A

1    using System.Security.Principal;
2    using Microsoft.Practices.EnterpriseLibrary.Security.Configuration;
3    using Microsoft.Practices.EnterpriseLibrary.Common.Configuration.ObjectBuilder;
4    using System.Collections.Generic;
5    
6    namespace Microsoft.Practices.EnterpriseLibrary.Security
7    {
8        public interface IVAuthorizationProvider
9        {
10           bool Authorize(IPrincipal principal, List<string> right);
11       }
12   }



My new class in Project A:

1    
2    using System.Security.Principal;
3    using Microsoft.Practices.EnterpriseLibrary.Common;
4    using Microsoft.Practices.EnterpriseLibrary.Common.Configuration;
5    using Microsoft.Practices.EnterpriseLibrary.Common.Configuration.ObjectBuilder;
6    using Microsoft.Practices.EnterpriseLibrary.Security.Configuration;
7    using Microsoft.Practices.EnterpriseLibrary.Security.Instrumentation;
8    using Microsoft.Practices.EnterpriseLibrary.Common.Instrumentation;
9    using System.Collections.Generic;
10   
11   namespace Microsoft.Practices.EnterpriseLibrary.Security
12   {
13       public abstract class VAuthorizationProvider : IVAuthorizationProvider, IInstrumentationEventProvider
14       {
15           AuthorizationProviderInstrumentationProvider instrumentationProvider;
16           private IDictionary<string, List<string>> dicRights  = null;
17   
18           protected VAuthorizationProvider(IPrincipal principal, List<string> rightsRequested)
19               {
20               if (rightsRequested == null) throw new System.ArgumentNullException("rightsRequested list was null");
21   
22                     this.instrumentationProvider = new AuthorizationProviderInstrumentationProvider();
23   
24               }
25           public bool Authorize(IPrincipal principal, List<string> rightsRequested)
26           {
27               bool result = false;
28   
29               if (principal == null) throw new System.ArgumentNullException("IPrincipal is null");
30               if (rightsRequested.Count < 1) throw new System.ArgumentNullException("rightsRequested generic string is null");
31   
32               if (rightsRequested.Count == 1)
33               {
34                   dicRights[principal.Identity.Name].Contains(rightsRequested[0]);
35               }
36   
37               return result;
38           }
39   
40     ... rest of class
41       }
42   }
43   

Console Project B
My Console class in order to try to test the Authorize method:

1    namespace TestSandBox
2    {
3        class VAuthorizationProviderTesting : VAuthorizationProvider
4        {
5            static void Main(string[] args)
6            {
7                List<string> rightToCheck = null;
8    
9                rightToCheck.Add("Delete");
10               
11               VAuthorizationProvider.  <--  I'm not seeing my Authorize method show in Intellisense
12           }
13       }
14   }

Problem is, Intellisense isn't showing me my Authorize method and I'm not sure why.  I'm sure it's a simple syntax issue but I'm still learning about Interfaces, abstract classes, etc.  I do have the includes and references in my project for ProjectA so not sure what the deal is. Even if I'm in PRoject A and go to an existing class and try it out, it also doesn't give me the method in Intellisense when trying to access the Authorize method even in Project A in other classes for my custom class I created


Answers (1)