Inconsistent accessibility In base class and derived class

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • EvilProject
    New Member
    • Nov 2007
    • 16

    Inconsistent accessibility In base class and derived class

    While working on a scripting engine I Encountered the following problem.
    First I Created an abstract base class EPType that represent a variable type in the script.

    Code:
        internal abstract class EPType
        {
            private String m_Name;
            public String Name
            {
                get { return m_Name; }
            }
            public EPType(String Name)
            {
                m_Name = Name;
            }
            public abstract Object ParseValue(String str);
        }
    second I Add the two following classes

    Code:
       public abstract class EPValueType : EPType
        {
            private EPReferenceType m_RefType;
            public EPValueType(String strName)
                : base(strName)
            {
                m_RefType = new EPRefernceType(strName + "Ref", this);
            }
            internal EPReferenceType ReferenceType
            {
                get { return m_RefType; }
            }   
        }
        internal class EPReferenceType : EPType
        {
            private EPValueType m_Type;
            public EPReferenceType(String strName, EPValueType vType)
                : base(strName)
            {
                m_Type = vType;
            }
            public EPValueType Type
            {
                get { return m_Type; }
            }
            public override object ParseValue(string str)
            {
                return str;
            }    
        }
    the problem is that i want EPValueType to be "seen" outside the current assembly so that anyone using this engine will be able to inherit from it and add new types, but I dont want it's base class EPType to be seen since there are only two categories of types, reference type and value type.But if I set EPType as an internal class and EPValueType as a public class i get an Inconsistent accessibility error. is there a way to do what i want without changing the entire design of the scripting engine?

    hope I was clear...i got the the feeling that i wasn't :X

    thanks in advance
  • skipbr
    New Member
    • Jul 2007
    • 13

    #2
    Code:
    [System.ComponentModel.Browsable(false)]
    [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)]
    public abstract class EPType
    {
            private String m_Name;
            public String Name
            {
                get { return m_Name; }
            }
            public EPType(String Name)
            {
                m_Name = Name;
            }
            public abstract Object ParseValue(String str);
    }
    This will hide the class, even it being public.

    Comment

    • EvilProject
      New Member
      • Nov 2007
      • 16

      #3
      Originally posted by skipbr
      Code:
      [System.ComponentModel.Browsable(false)]
      [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)]
      public abstract class EPType
      {
              private String m_Name;
              public String Name
              {
                  get { return m_Name; }
              }
              public EPType(String Name)
              {
                  m_Name = Name;
              }
              public abstract Object ParseValue(String str);
      }
      This will hide the class, even it being public.
      it hides the class partialy(only from the intellisense menu). I can still inherit from it in a diffrent assembly if I know it's name. what i'm looking for is a way to make EPType completly inaccessible.

      Comment

      • jjvainav
        New Member
        • Feb 2008
        • 25

        #4
        Code:
        internal abstract class EPType
            {
                private String m_Name;
                public String Name
                {
                    get { return m_Name; }
                }
                public EPType(String Name)
                {
                    m_Name = Name;
                }
                public abstract Object ParseValue(String str);
            }
        You will have to make EPType public. However, you can prevent assemblies outside of that one from inheriting your base type, by making an internal constructor.

        Code:
        public abstract class EPType
            {
                private String m_Name;
                public String Name
                {
                    get { return m_Name; }
                }
                internal EPType(String Name)
                {
                    m_Name = Name;
                }
                public abstract Object ParseValue(String str);
            }
        This way, any classes outside of EPType's assembly that tries to inherit it, will recieve an error of: The type EPType has no constructor defined.

        Comment

        Working...