Ejemplo n.º 1
0
        internal ClassMember SetItem(RuntimeContexts.RuntimeContext context, bool isStatic)
        {
            var         members = isStatic ? StaticMembers : InstanceMembers;
            ClassMember value;
            string      rename;
            string      idxget = ClassHelper.RenameIndexerGetter;
            string      idxset = ClassHelper.RenameIndexerSetter;
            var         cls    = context.Class as ClassObject;

            if (cls != null)
            {
                rename = ClassHelper.RenamePrivate(idxset, cls.Name);
                if (members.TryGetValue(rename, out value) && value is IndexerSetter)
                {
                    return(value);
                }
                rename = ClassHelper.RenamePrivate(idxget, cls.Name);
                if (members.TryGetValue(rename, out value) && value is IndexerGetter)
                {
                    return(ClassHelper.ThrowIndexerIsReadonly());
                }
            }
            {
                rename = idxset;
                if (members.TryGetValue(rename, out value) && value is IndexerSetter)
                {
                    return(value);
                }
                rename = idxget;
                if (members.TryGetValue(rename, out value) && value is IndexerGetter)
                {
                    return(ClassHelper.ThrowIndexerIsReadonly());
                }
            }
            if (cls == this || ClassHelper.IsExtendedFrom(this, cls) || ClassHelper.IsExtendedFrom(cls, this))
            {
                rename = ClassHelper.RenameProtected(idxset);
                if (members.TryGetValue(rename, out value) && value is IndexerSetter)
                {
                    return(value);
                }
                rename = ClassHelper.RenameProtected(idxget);
                if (members.TryGetValue(rename, out value) && value is IndexerGetter)
                {
                    return(ClassHelper.ThrowIndexerIsReadonly());
                }
            }
            if (Super != null)
            {
                return(Super.SetItem(context, isStatic));
            }
            return(ClassHelper.ThrowIndexerNotSupported());
        }
Ejemplo n.º 2
0
 private string RenameModifier(Modifier modifier, string name)
 {
     if (modifier == Modifier.Private)
     {
         return(ClassHelper.RenamePrivate(name, Class.Name));
     }
     else if (modifier == Modifier.Protected)
     {
         return(ClassHelper.RenameProtected(name));
     }
     else
     {
         return(name);
     }
 }
Ejemplo n.º 3
0
        /// <summary>
        /// Returns the value of the member of the specified name.
        /// </summary>
        /// <param name="context">The runtime context.</param>
        /// <param name="name">The name of the member.</param>
        /// <returns>The value of the member <paramref name="name"/>.</returns>
        IScriptObject IMemberObject.GetMember(RuntimeContexts.RuntimeContext context, string name)
        {
            IScriptObject value;
            string        rename;
            var           cls = context.Class as ClassObject;

            if (cls != null)
            {
                rename = ClassHelper.RenamePrivate(name, cls.Name);
                if (Fields.TryGetValue(rename, out value))
                {
                    return(value);
                }
            }
            {
                rename = name;
                if (Fields.TryGetValue(rename, out value))
                {
                    return(value);
                }
            }
            if (cls == this.Class || ClassHelper.IsExtendedFrom(this.Class, cls) || ClassHelper.IsExtendedFrom(cls, this.Class))
            {
                rename = ClassHelper.RenameProtected(name);
                if (Fields.TryGetValue(rename, out value))
                {
                    return(value);
                }
            }
            {
                var member = Class.GetMember(context, name, false);
                var mtd    = member as ClassMethod;
                if (mtd != null)
                {
                    return(new BoundMethod(this, mtd));
                }
                var proget = member as PropertyGetter;
                if (proget != null)
                {
                    return(proget.GetProperty(this));
                }
            }
            throw new InvalidOperationException(
                      string.Format(ExceptionResource.MemberNotFound, name));
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Sets the value of the member of the specified name to the specified value.
        /// </summary>
        /// <param name="context">The runtime context.</param>
        /// <param name="name">The name of the member.</param>
        /// <param name="value">The value to set.</param>
        void IMemberObject.SetMember(RuntimeContexts.RuntimeContext context, string name, IScriptObject value)
        {
            string rename;
            var    cls = context.Class as ClassObject;

            if (cls != null)
            {
                rename = ClassHelper.RenamePrivate(name, cls.Name);
                if (Fields.ContainsKey(rename))
                {
                    Fields[rename] = value;
                    return;
                }
            }
            {
                rename = name;
                if (Fields.ContainsKey(rename))
                {
                    Fields[rename] = value;
                    return;
                }
            }
            if (cls == this.Class || ClassHelper.IsExtendedFrom(this.Class, cls) || ClassHelper.IsExtendedFrom(cls, this.Class))
            {
                rename = ClassHelper.RenameProtected(name);
                if (Fields.ContainsKey(rename))
                {
                    Fields[rename] = value;
                    return;
                }
            }
            {
                var member = Class.SetMember(context, name, false);
                var proset = member as PropertySetter;
                if (proset != null)
                {
                    proset.SetProperty(this, value);
                    return;
                }
            }
            throw new InvalidOperationException(
                      string.Format(ExceptionResource.MemberNotFound, name));
        }
Ejemplo n.º 5
0
        internal ClassMember SetMember(RuntimeContexts.RuntimeContext context, string name, bool isStatic)
        {
            var         members = isStatic ? StaticMembers : InstanceMembers;
            ClassMember value;
            string      rename;
            string      propget = ClassHelper.RenamePropertyGetter(name);
            string      propset = ClassHelper.RenamePropertySetter(name);
            var         cls     = context.Class as ClassObject;

            if (cls != null)
            {
                rename = ClassHelper.RenamePrivate(name, cls.Name);
                if (members.TryGetValue(rename, out value) && value is ClassMethod)
                {
                    return(ClassHelper.ThrowCannotAssignMethod(name));
                }
                rename = ClassHelper.RenamePrivate(propset, cls.Name);
                if (members.TryGetValue(rename, out value) && value is PropertySetter)
                {
                    return(value);
                }
                rename = ClassHelper.RenamePrivate(propget, cls.Name);
                if (members.TryGetValue(rename, out value) && value is PropertyGetter)
                {
                    return(ClassHelper.ThrowPropertyIsReadonly(name));
                }
            }
            {
                rename = name;
                if (members.TryGetValue(rename, out value) && value is ClassMethod)
                {
                    return(ClassHelper.ThrowCannotAssignMethod(name));
                }
                rename = propset;
                if (members.TryGetValue(rename, out value) && value is PropertySetter)
                {
                    return(value);
                }
                rename = propget;
                if (members.TryGetValue(rename, out value) && value is PropertyGetter)
                {
                    return(ClassHelper.ThrowPropertyIsReadonly(name));
                }
            }
            if (cls == this || ClassHelper.IsExtendedFrom(this, cls) || ClassHelper.IsExtendedFrom(cls, this))
            {
                rename = ClassHelper.RenameProtected(name);
                if (members.TryGetValue(rename, out value) && value is ClassMethod)
                {
                    return(value);
                }
                rename = ClassHelper.RenameProtected(propset);
                if (members.TryGetValue(rename, out value) && value is PropertySetter)
                {
                    return(value);
                }
                rename = ClassHelper.RenameProtected(propget);
                if (members.TryGetValue(rename, out value) && value is PropertyGetter)
                {
                    return(ClassHelper.ThrowPropertyIsReadonly(name));
                }
            }
            if (Super != null)
            {
                return(Super.SetMember(context, name, isStatic));
            }
            return(ClassHelper.ThrowMemberNotFound(name));
        }