Last active
August 29, 2015 14:04
-
-
Save cerebrate/8e635c7f2d791d1f8027 to your computer and use it in GitHub Desktop.
Reflecting differently
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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