Skip to content

Instantly share code, notes, and snippets.

@cerebrate
Last active Aug 29, 2015
Embed
What would you like to do?
Reflecting differently
public class FARAdapter : Adapter
{
private PropertyInfo instanceProp;
private FieldInfo machNumberField;
private FieldInfo qField;
public override void Plugin()
{
Type type = GetType("ferram4.FARControlSys");
if (type != null)
{
instanceProp = type.GetProperty ("ActiveControlSys", BindingFlags.Static | BindingFlags.Public);
machNumberField = type.GetField ("MachNumber", BindingFlags.Instance | BindingFlags.Public);
qField = type.GetField ("q", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
// non-public now, but going to be public in next release, per conversation with ferram.
SetInstalled (true);
}
}
public double GetMachNumber()
{
if(IsInstalled())
{
object farControlSys = instanceProp.GetValue (null, null);
if (farControlSys != null)
return (double) machNumberField.GetValue (farControlSys);
}
return 0.0;
}
public double GetQ ()
{
if (IsInstalled ())
{
object farControlSys = instanceProp.GetValue (null, null);
if (farControlSys != null)
return (double)qField.GetValue (farControlSys);
}
return 0.0;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment