public ValueInfoItem(object obj, MemberInfo member, ValueInfoItemAttribute attribute)
            : base(attribute)
        {
            id = this.GetType().Name.Replace("InfoItem", "") + ":" + obj.GetType().Name.Replace("MechJebModule", "") + "." + member.Name;

            units             = attribute.units;
            format            = attribute.format;
            siSigFigs         = attribute.siSigFigs;
            siMaxPrecision    = attribute.siMaxPrecision;
            timeDecimalPlaces = attribute.timeDecimalPlaces;

            // This ugly stuff compiles a small function to grab the value of member, so that we don't
            // have to use reflection to get it every frame.
            ParameterExpression objExpr     = Expression.Parameter(typeof(object), "");   // obj
            Expression          castObjExpr = Expression.Convert(objExpr, obj.GetType()); // (T)obj
            Expression          memberExpr;

            if (member is MethodInfo)
            {
                memberExpr = Expression.Call(castObjExpr, (MethodInfo)member);
            }
            else
            {
                memberExpr = Expression.MakeMemberAccess(castObjExpr, member);                     // ((T)obj).member
            }
            Expression            castMemberExpr = Expression.Convert(memberExpr, typeof(object)); // (object)(((T)obj).member);
            Func <object, object> getFromObj     = Expression.Lambda <Func <object, object> >(castMemberExpr, new[] { objExpr }).Compile();

            getValue = () => getFromObj(obj);
        }
Пример #2
0
        public ValueInfoItem(object obj, MemberInfo member, ValueInfoItemAttribute attribute)
            : base(attribute)
        {
            id = this.GetType().Name.Replace("InfoItem", "") + ":" + obj.GetType().Name.Replace("MechJebModule", "") + "." + member.Name;

            this.obj    = obj;
            this.member = member;
            units       = attribute.units;
            time        = attribute.time;
            format      = attribute.format;
        }
Пример #3
0
        int timeDecimalPlaces; //only used with the "TIME" format

        public ValueInfoItem(object obj, MemberInfo member, ValueInfoItemAttribute attribute)
            : base(attribute)
        {
            id = this.GetType().Name.Replace("InfoItem", "") + ":" + obj.GetType().Name.Replace("MechJebModule", "") + "." + member.Name;

            this.obj          = obj;
            this.member       = member;
            units             = attribute.units;
            format            = attribute.format;
            siSigFigs         = attribute.siSigFigs;
            siMaxPrecision    = attribute.siMaxPrecision;
            timeDecimalPlaces = attribute.timeDecimalPlaces;
        }
        public ValueInfoItem(object obj, MemberInfo member, ValueInfoItemAttribute attribute)
            : base(attribute)
        {
            id = this.GetType().Name.Replace("InfoItem", "") + ":" + obj.GetType().Name.Replace("MechJebModule", "") + "." + member.Name;

            this.obj = obj;
            this.member = member;
            units = attribute.units;
            format = attribute.format;
            siSigFigs = attribute.siSigFigs;
            siMaxPrecision = attribute.siMaxPrecision;
            timeDecimalPlaces = attribute.timeDecimalPlaces;
        }
        public ValueInfoItem(object obj, MemberInfo member, ValueInfoItemAttribute attribute)
            : base(attribute)
        {
            id = this.GetType().Name.Replace("InfoItem", "") + ":" + obj.GetType().Name.Replace("MechJebModule", "") + "." + member.Name;

            units = attribute.units;
            format = attribute.format;
            siSigFigs = attribute.siSigFigs;
            siMaxPrecision = attribute.siMaxPrecision;
            timeDecimalPlaces = attribute.timeDecimalPlaces;

            // This ugly stuff compiles a small function to grab the value of member, so that we don't
            // have to use reflection to get it every frame.
            ParameterExpression objExpr = Expression.Parameter(typeof(object), ""); // obj
            Expression castObjExpr = Expression.Convert(objExpr, obj.GetType()); // (T)obj
            Expression memberExpr;
            if (member is MethodInfo) memberExpr = Expression.Call(castObjExpr, (MethodInfo)member);
            else memberExpr = Expression.MakeMemberAccess(castObjExpr, member); // ((T)obj).member
            Expression castMemberExpr = Expression.Convert(memberExpr, typeof(object)); // (object)(((T)obj).member);
            Func<object, object> getFromObj = Expression.Lambda<Func<object, object>>(castMemberExpr, new[] { objExpr }).Compile();
            getValue = () => getFromObj(obj);
        }
        public ValueInfoItem(object obj, MemberInfo member, ValueInfoItemAttribute attribute)
            : base(attribute)
        {
            id = this.GetType().Name.Replace("InfoItem", "") + ":" + obj.GetType().Name.Replace("MechJebModule", "") + "." + member.Name;

            this.obj = obj;
            this.member = member;
            units = attribute.units;
            time = attribute.time;
            format = attribute.format;
        }