Skip to content

Instantly share code, notes, and snippets.

@cerebrate
Last active August 29, 2015 14:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cerebrate/8e635c7f2d791d1f8027 to your computer and use it in GitHub Desktop.
Save cerebrate/8e635c7f2d791d1f8027 to your computer and use it in GitHub Desktop.
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