internal PythonEnvironment(Grasshopper.Kernel.GH_Component component, PythonScript script) { Component = component; Script = script; if (script != null) { Type scriptType = script.GetType(); var scopeField = scriptType.GetField("m_scope"); if (scopeField != null) { LocalScope = scopeField.GetValue(script); } var baseType = scriptType.BaseType; if (baseType != null && baseType != typeof (object)) { var hostType = baseType.Assembly.GetType("RhinoPython.Host"); if (hostType != null) { var engineInfo = hostType.GetProperty("Engine"); if (engineInfo != null) Engine = engineInfo.GetValue(null, null); var scopeInfo = hostType.GetProperty("Scope", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.GetProperty | System.Reflection.BindingFlags.Static); if (scopeInfo != null) ScriptScope = scopeInfo.GetValue(null, null); } } } }
internal PythonEnvironment(GH_Component component, PythonScript script) { Component = component; Script = script; if (script != null) { Type scriptType = script.GetType(); var scopeField = scriptType.GetField("m_scope"); if (scopeField != null) { LocalScope = scopeField.GetValue(script); } var intellisenseField = scriptType.GetField("m_intellisense", BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.GetField); if (intellisenseField != null) { Intellisense = intellisenseField.GetValue(script); if (Intellisense != null) { var intellisenseType = Intellisense.GetType(); var scopeProperty = intellisenseType.GetProperty("Scope"); IntellisenseScope = scopeProperty.GetValue(Intellisense, null); } } var baseType = scriptType.BaseType; if (baseType != null && baseType != typeof(object)) { var hostType = baseType.Assembly.GetType("RhinoPython.Host"); if (hostType != null) { var engineInfo = hostType.GetProperty("Engine"); if (engineInfo != null) { Engine = engineInfo.GetValue(null, null); if (Engine != null) { var runtimeInfo = Engine.GetType().GetProperty("Runtime"); Runtime = runtimeInfo.GetValue(Engine, null); } } var scopeInfo = hostType.GetProperty("Scope", BindingFlags.NonPublic | BindingFlags.GetProperty | BindingFlags.Static); if (scopeInfo != null) ScriptScope = scopeInfo.GetValue(null, null); } } } }