Ejemplo n.º 1
0
 public DNMetaObject(Context c, Type t) : base(c, true)
 {
     targetType   = t;
     staticInfo   = GetStaticClassInfo(c, t);
     backingStore = CreateStaticDict(c, t);
     AllocClassObject();
 }
Ejemplo n.º 2
0
        public bool sgsSetPropertyByName(Variable key, Context ctx, bool isprop, int valueOnStack)
        {
            SGSClassInfo cinfo = GetClassInfo();
            SGSPropInfo  propinfo;

            if (!cinfo.props.TryGetValue(key, out propinfo) || !propinfo.canWrite)
            {
                if (backingStore != null)
                {
                    return(backingStore.SetSubItem(key, ctx.StackItem(valueOnStack), isprop));
                }
                return(false);
            }
            if (propinfo.parseVarMethod == null)
            {
                throw new SGSException(RC.ENOTFND, string.Format(
                                           "Property cannot be set - no Context.ParseVar method exists that supports this type ({0})", propinfo.propType));
            }

            object[] args = new object[] { null, ctx.StackItem(valueOnStack) };
            propinfo.parseVarMethod.Invoke(ctx, args);
            if (propinfo.info is FieldInfo)
            {
                (propinfo.info as FieldInfo).SetValue(this, args[0]);
            }
            else             // PropertyInfo
            {
                (propinfo.info as PropertyInfo).SetValue(this, args[0], null);
            }
            return(true);
        }
Ejemplo n.º 3
0
        // callback implementation helpers
        public Variable sgsGetPropertyByName(Variable key, bool isprop)
        {
            SGSClassInfo cinfo = GetClassInfo();
            SGSPropInfo  propinfo;

            if (!cinfo.props.TryGetValue(key, out propinfo) || !propinfo.canRead)
            {
                if (backingStore != null)
                {
                    return(backingStore.GetSubItem(key, isprop));
                }
                return(null);
            }

            object obj;

            if (propinfo.info is FieldInfo)
            {
                obj = (propinfo.info as FieldInfo).GetValue(this);
            }
            else             // PropertyInfo
            {
                obj = (propinfo.info as PropertyInfo).GetValue(this, null);
            }
            return(_sgsEngine.ObjVar(obj));
        }
Ejemplo n.º 4
0
        public static SGSClassInfo GetStaticClassInfo(Context ctx, Type type)
        {
            SGSClassInfo cinfo;

            if (ctx.GetEngine()._sgsStaticClassInfo.TryGetValue(type, out cinfo))
            {
                return(cinfo);
            }

            NI.OC_Self      d_destruct, d_getindex, d_setindex;
            NI.ObjInterface oi = new NI.ObjInterface()
            {
                destruct = d_destruct = new NI.OC_Self(_sgsDestruct),
                getindex = d_getindex = new NI.OC_Self(_sgsGetIndex),
                setindex = d_setindex = new NI.OC_Self(_sgsSetIndex),
            };

            cinfo = new SGSClassInfo()
            {
                iface      = AllocInterface(oi, type.Name + "[static]"),
                props      = _ReadClassProps(ctx, type, true),
                d_destruct = d_destruct,
                d_getindex = d_getindex,
                d_setindex = d_setindex,
            };
            ctx.GetEngine()._sgsStaticClassInfo.Add(type, cinfo);
            return(cinfo);
        }
Ejemplo n.º 5
0
 public DNMetaObject( Context c, Type t )
     : base(c, true)
 {
     targetType = t;
     staticInfo = GetStaticClassInfo( c, t );
     backingStore = CreateStaticDict( c, t );
     AllocClassObject();
 }
Ejemplo n.º 6
0
        // returns the cached interface for any supporting (IObject-based) class
        public static SGSClassInfo GetClassInfo(Context ctx, Type type)
        {
            SGSClassInfo cinfo;

            if (ctx.GetEngine()._sgsClassInfo.TryGetValue(type, out cinfo))
            {
                return(cinfo);
            }

            NI.OC_Self      d_destruct, d_gcmark, d_getindex, d_setindex, d_serialize, d_call, d_expr;
            NI.OC_SlPr      d_convert, d_dump, d_getnext;
            NI.ObjInterface oi = new NI.ObjInterface()
            {
                destruct = d_destruct = new NI.OC_Self(_sgsDestruct),
                gcmark   = d_gcmark = new NI.OC_Self(_sgsGCMark),

                getindex = d_getindex = new NI.OC_Self(_sgsGetIndex),
                setindex = d_setindex = new NI.OC_Self(_sgsSetIndex),

                convert   = d_convert = new NI.OC_SlPr(_sgsConvert),
                serialize = d_serialize = new NI.OC_Self(_sgsSerialize),
                dump      = d_dump = new NI.OC_SlPr(_sgsDump),
                getnext   = d_getnext = new NI.OC_SlPr(_sgsGetNext),

                call = d_call = new NI.OC_Self(_sgsCall),
                expr = d_expr = new NI.OC_Self(_sgsExpr),
            };

            cinfo = new SGSClassInfo()
            {
                iface       = AllocInterface(oi, type.Name),
                props       = _ReadClassProps(ctx, type, false),
                d_destruct  = d_destruct,
                d_gcmark    = d_gcmark,
                d_getindex  = d_getindex,
                d_setindex  = d_setindex,
                d_convert   = d_convert,
                d_serialize = d_serialize,
                d_dump      = d_dump,
                d_call      = d_call,
            };
            ctx.GetEngine()._sgsClassInfo.Add(type, cinfo);
            return(cinfo);
        }
Ejemplo n.º 7
0
        public static SGSClassInfo GetStaticClassInfo( Context ctx, Type type )
        {
            SGSClassInfo cinfo;
            if( ctx.GetEngine()._sgsStaticClassInfo.TryGetValue( type, out cinfo ) )
                return cinfo;

            NI.OC_Self d_destruct, d_getindex, d_setindex;
            NI.ObjInterface oi = new NI.ObjInterface()
            {
                destruct = d_destruct = new NI.OC_Self( _sgsDestruct ),
                getindex = d_getindex = new NI.OC_Self( _sgsGetIndex ),
                setindex = d_setindex = new NI.OC_Self( _sgsSetIndex ),
            };

            cinfo = new SGSClassInfo()
            {
                iface = AllocInterface( oi, type.Name + "[static]" ),
                props = _ReadClassProps( ctx, type, true ),
                d_destruct = d_destruct,
                d_getindex = d_getindex,
                d_setindex = d_setindex,
            };
            ctx.GetEngine()._sgsStaticClassInfo.Add( type, cinfo );
            return cinfo;
        }
Ejemplo n.º 8
0
        // returns the cached interface for any supporting (IObject-based) class
        public static SGSClassInfo GetClassInfo( Context ctx, Type type )
        {
            SGSClassInfo cinfo;
            if( ctx.GetEngine()._sgsClassInfo.TryGetValue( type, out cinfo ) )
                return cinfo;

            NI.OC_Self d_destruct, d_gcmark, d_getindex, d_setindex, d_serialize, d_call, d_expr;
            NI.OC_SlPr d_convert, d_dump, d_getnext;
            NI.ObjInterface oi = new NI.ObjInterface()
            {
                destruct = d_destruct = new NI.OC_Self( _sgsDestruct ),
                gcmark = d_gcmark = new NI.OC_Self( _sgsGCMark ),

                getindex = d_getindex = new NI.OC_Self( _sgsGetIndex ),
                setindex = d_setindex = new NI.OC_Self( _sgsSetIndex ),

                convert = d_convert = new NI.OC_SlPr( _sgsConvert ),
                serialize = d_serialize = new NI.OC_Self( _sgsSerialize ),
                dump = d_dump = new NI.OC_SlPr( _sgsDump ),
                getnext = d_getnext = new NI.OC_SlPr( _sgsGetNext ),

                call = d_call = new NI.OC_Self( _sgsCall ),
                expr = d_expr = new NI.OC_Self( _sgsExpr ),
            };

            cinfo = new SGSClassInfo()
            {
                iface = AllocInterface( oi, type.Name ),
                props = _ReadClassProps( ctx, type, false ),
                d_destruct = d_destruct,
                d_gcmark = d_gcmark,
                d_getindex = d_getindex,
                d_setindex = d_setindex,
                d_convert = d_convert,
                d_serialize = d_serialize,
                d_dump = d_dump,
                d_call = d_call,
            };
            ctx.GetEngine()._sgsClassInfo.Add( type, cinfo );
            return cinfo;
        }