Microsoft.JScript.JSMemberField.IsAccessibleFrom C# (CSharp) Method

IsAccessibleFrom() private method

private IsAccessibleFrom ( ScriptObject scope ) : bool
scope ScriptObject
return bool
      internal bool IsAccessibleFrom(ScriptObject scope){ //Never call this if the member is public
        while (scope != null && !(scope is ClassScope))
          scope = scope.GetParent();
        ClassScope objType = null;
        if (this.obj is ClassScope)
          objType = (ClassScope)this.obj;
        else
          objType = (ClassScope)((ScriptObject)this.obj).GetParent();
        if (this.IsPrivate)
          if (scope == null)
            return false;
          else
            return scope == objType || ((ClassScope)scope).IsNestedIn(objType, this.IsStatic);
        else if (this.IsFamily)
          if (scope == null)
            return false;
          else
            return ((ClassScope)scope).IsSameOrDerivedFrom(objType) || ((ClassScope)scope).IsNestedIn(objType, this.IsStatic);
        else { //if (this.IsAssembly || this.IsFamilyOrAssembly)
          if (this.IsFamilyOrAssembly && scope != null &&
              (((ClassScope)scope).IsSameOrDerivedFrom(objType) || ((ClassScope)scope).IsNestedIn(objType, this.IsStatic)))
            return true;
          else if (scope == null) //Code is not in a class and hence it is in the default package
            return objType.GetPackage() == null; //null indicates default package
          else
            return objType.GetPackage() == ((ClassScope)scope).GetPackage();
        }
      }

Usage Example

        internal Object EvaluateAsType()
        {
            WrappedNamespace ns     = this.rootObject.EvaluateAsWrappedNamespace(false);
            Object           result = ns.GetMemberValue(this.name);

            if (result != null && !(result is Missing))
            {
                return(result);
            }
            Object ob   = null;
            Member root = this.rootObject as Member;

            if (root == null)
            {
                Lookup lookup = this.rootObject as Lookup;
                if (lookup == null)
                {
                    return(null);
                }
                ob = lookup.PartiallyEvaluate();
                ConstantWrapper cw = ob as ConstantWrapper;
                if (cw != null)
                {
                    ob = cw.value;
                }
                else
                {
                    JSGlobalField f = lookup.member as JSGlobalField;
                    if (f != null && f.IsLiteral)
                    {
                        ob = f.value;
                    }
                    else
                    {
                        return(null);
                    }
                }
            }
            else
            {
                ob = root.EvaluateAsType();
            }
            ClassScope csc = ob as ClassScope;

            if (csc != null)
            {
                MemberInfo[] members = csc.GetMember(this.name, BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.Instance);
                if (members.Length == 0)
                {
                    return(null);
                }
                JSMemberField field = members[0] as JSMemberField;
                if (field == null || !field.IsLiteral || !(field.value is ClassScope) || !field.IsPublic && !field.IsAccessibleFrom(this.Engine.ScriptObjectStackTop()))
                {
                    return(null);
                }
                return(field.value);
            }
            Type t = ob as Type;

            if (t != null)
            {
                return(t.GetNestedType(this.name));
            }
            return(null);
        }
All Usage Examples Of Microsoft.JScript.JSMemberField::IsAccessibleFrom