예제 #1
0
        static Dictionary <Variable, SGSPropInfo> _ReadClassProps(Context ctx, Type type, bool needStatic)
        {
            Dictionary <Variable, SGSPropInfo> outprops = new Dictionary <Variable, SGSPropInfo>();

            BindingFlags placementFlag = needStatic ? BindingFlags.Static : BindingFlags.Instance;

            FieldInfo[] fields = type.GetFields(BindingFlags.Public | BindingFlags.NonPublic | placementFlag);
            foreach (FieldInfo field in fields)
            {
                SGSPropInfo info = _GetPropFieldInfo(field, field.FieldType);
                if (info != null)
                {
                    outprops.Add(ctx.Var(field.Name), info);
                }
            }

            PropertyInfo[] properties = type.GetProperties(BindingFlags.Public | BindingFlags.NonPublic | placementFlag);
            foreach (PropertyInfo prop in properties)
            {
                SGSPropInfo info = _GetPropFieldInfo(prop, prop.PropertyType);
                if (info != null)
                {
                    outprops.Add(ctx.Var(prop.Name), info);
                }
            }

            return(outprops);
        }
예제 #2
0
        static SGSPropInfo _GetPropFieldInfo(MemberInfo minfo, Type type)
        {
            SGSPropInfo info = new SGSPropInfo()
            {
                info = minfo, propType = type
            };

            foreach (object attr in minfo.GetCustomAttributes(false))
            {
                if (attr is HideProperty)
                {
                    info.canRead  = (attr as HideProperty).CanRead;
                    info.canWrite = (attr as HideProperty).CanWrite;
                    if (info.canRead == false && info.canWrite == false)
                    {
                        return(null);                        // no need to register the property, it is marked as inaccessible
                    }
                }
            }

            info.parseVarMethod = FindParserForType(type);

            return(info);
        }
예제 #3
0
파일: Variable.cs 프로젝트: snake5/sgscript
        static SGSPropInfo _GetPropFieldInfo( MemberInfo minfo, Type type )
        {
            SGSPropInfo info = new SGSPropInfo(){ info = minfo, propType = type };
            foreach( object attr in minfo.GetCustomAttributes( false ) )
            {
                if( attr is HideProperty )
                {
                    info.canRead = (attr as HideProperty).CanRead;
                    info.canWrite = (attr as HideProperty).CanWrite;
                    if( info.canRead == false && info.canWrite == false )
                        return null; // no need to register the property, it is marked as inaccessible
                }
            }

            info.parseVarMethod = FindParserForType( type );

            return info;
        }