public IParameterInfo[] GetParameters() { if (_params == null) { RemoteInterpreterProxy ri = _remote; bool isInstanceExtensionMethod = ri != null?ri.IsInstanceExtensionMethod(_overload, _declaringType.Value) : false; ObjectIdentityHandle[] parameters = ri != null?ri.GetParametersNoCodeContext(_overload) : new ObjectIdentityHandle[0]; var res = new List <IParameterInfo>(parameters.Length + 1); res.Add(new IronPythonNewClsParameterInfo(_declaringType)); foreach (ObjectIdentityHandle param in parameters) { if (res.Count == 0 && isInstanceExtensionMethod) { // skip instance parameter isInstanceExtensionMethod = false; continue; } else { res.Add(new IronPythonParameterInfo(_interpreter, param)); } } _params = res.ToArray(); } return(_params); }
public PythonObject(IronPythonInterpreter interpreter, ObjectIdentityHandle obj) { _interpreter = interpreter; _interpreter.UnloadingDomain += Interpreter_UnloadingDomain; _remote = _interpreter.Remote; _obj = obj; }
private void CreateNonClrAttrs() { if (!_checkedClrAttrs) { RemoteInterpreterProxy ri = RemoteInterpreter; foreach (var name in ri != null ? ri.DirHelper(_obj, false) : Enumerable.Empty <string>()) { if (!_attrs.ContainsKey(name)) { _attrs[name] = new MemberInfo(IsClrOnly.No); } else { _attrs[name] = new MemberInfo(_attrs[name].Member, IsClrOnly.No); } } foreach (var attr in _attrs.ToArray()) { if (attr.Value.ClrOnly == IsClrOnly.NotChecked) { _attrs[attr.Key] = new MemberInfo(attr.Value.Member, IsClrOnly.Yes); } } _checkedClrAttrs = true; } }
public IronPythonConstructorFunction(IronPythonInterpreter interpreter, ObjectIdentityHandle[] infos, IPythonType type) { _interpreter = interpreter; _interpreter.UnloadingDomain += Interpreter_UnloadingDomain; _remote = _interpreter.Remote; _infos = infos; _type = type; }
private static readonly string _noDefaultValue = "<No Default Value>"; // sentinel value to mark when an object doesn't have a default value public IronPythonParameterInfo(IronPythonInterpreter interpreter, ObjectIdentityHandle parameterInfo) { _interpreter = interpreter; _interpreter.UnloadingDomain += Interpreter_UnloadingDomain; _remote = _interpreter.Remote; _parameterInfo = parameterInfo; }
public IronPythonConstructorFunctionTarget(IronPythonInterpreter interpreter, ObjectIdentityHandle overload, IronPythonType declType) { Debug.Assert(interpreter.Remote.TypeIs<MethodBase>(overload)); _interpreter = interpreter; _interpreter.UnloadingDomain += Interpreter_UnloadingDomain; _remote = _interpreter.Remote; _overload = overload; _declaringType = declType; }
private void AddWpfReferences() { RemoteInterpreterProxy ri = RemoteInterpreter; if (ri != null && ri.LoadWpf()) { Interpreter.RaiseModuleNamesChanged(); } }
public IronPythonConstructorFunctionTarget(IronPythonInterpreter interpreter, ObjectIdentityHandle overload, IronPythonType declType) { Debug.Assert(interpreter.Remote.TypeIs <MethodBase>(overload)); _interpreter = interpreter; _interpreter.UnloadingDomain += Interpreter_UnloadingDomain; _remote = _interpreter.Remote; _overload = overload; _declaringType = declType; }
/// <summary> /// Returns the overloads for a normal .NET type /// </summary> private IPythonFunction GetClrOverloads() { RemoteInterpreterProxy ri = RemoteInterpreter; ObjectIdentityHandle[] ctors = ri != null?ri.GetPythonTypeConstructors(Value) : null; if (ctors != null) { return(new IronPythonConstructorFunction(Interpreter, ctors, this)); } return(null); }
public IPythonType MakeGenericType(IPythonType[] indexTypes) { // Should we hash on the types here? ObjectIdentityHandle[] types = new ObjectIdentityHandle[indexTypes.Length]; for (int i = 0; i < types.Length; i++) { types[i] = ((IronPythonType)indexTypes[i]).Value; } RemoteInterpreterProxy ri = RemoteInterpreter; return(ri != null?Interpreter.GetTypeFromType(ri.PythonTypeMakeGenericType(Value, types)) : null); }
private AppDomain CreateDomain(out RemoteInterpreterProxy remoteInterpreter) { // We create a sacrificial domain for loading all of our assemblies into. var ironPythonAssemblyPath = Path.GetDirectoryName(_factory.Configuration.GetWindowsInterpreterPath()); AppDomainSetup setup = new AppDomainSetup { ShadowCopyFiles = "true", // We are in ...\Extensions\Microsoft\IronPython Interpreter\2.0 // We need to be able to load assemblies from: // Python Tools for Visual Studio\2.0 // IronPython Interpreter\2.0 // // So setup the application base to be Extensions\Microsoft\, and then add the other 2 dirs to the private bin path. ApplicationBase = Path.GetDirectoryName(Path.GetDirectoryName(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location))), PrivateBinPath = Path.GetDirectoryName(typeof(IronPythonInterpreter).Assembly.Location) + ";" + Path.GetDirectoryName(typeof(IPythonFunction).Assembly.Location) + ";" + Path.Combine(ironPythonAssemblyPath, "DLLs") + ";" + ironPythonAssemblyPath, PrivateBinPathProbe = "" }; if (Directory.Exists(_factory.Configuration.GetPrefixPath())) { setup.AppDomainInitializer = IronPythonResolver.Initialize; setup.AppDomainInitializerArguments = new[] { _factory.Configuration.GetPrefixPath() }; } var domain = AppDomain.CreateDomain("IronPythonAnalysisDomain", null, setup); using (new RemoteAssemblyResolver(domain, ironPythonAssemblyPath)) { remoteInterpreter = (RemoteInterpreterProxy)domain.CreateInstanceAndUnwrap( typeof(RemoteInterpreterProxy).Assembly.FullName, typeof(RemoteInterpreterProxy).FullName); } #if DEBUG var assertListener = Debug.Listeners["Microsoft.PythonTools.AssertListener"]; if (assertListener != null) { var init = (AssertListenerInitializer)domain.CreateInstanceAndUnwrap( typeof(AssertListenerInitializer).Assembly.FullName, typeof(AssertListenerInitializer).FullName ); init.Initialize(assertListener); } #endif return(domain); }
/// <summary> /// Returns the overloads for a normal .NET type /// </summary> private IPythonFunction GetClrOverloads() { ObjectIdentityHandle declType = default(ObjectIdentityHandle); RemoteInterpreterProxy ri = RemoteInterpreter; ObjectIdentityHandle[] ctors = ri != null?ri.GetTypeGroupConstructors(Value, out declType) : null; if (ctors != null) { return(new IronPythonConstructorFunction(Interpreter, ctors, Interpreter.GetTypeFromType(declType))); } return(null); }
private IPythonType[] GetEventInvokeArgs() { RemoteInterpreterProxy ri = RemoteInterpreter; ObjectIdentityHandle[] types = ri != null?ri.GetEventInvokeArgs(Value) : new ObjectIdentityHandle[0]; IPythonType[] args = new IPythonType[types.Length]; for (int i = 0; i < types.Length; i++) { args[i] = Interpreter.GetTypeFromType(types[i]); } return(args); }
public IList <IPythonType> GetTypesPropagatedOnCall() { if (_propagateOnCall == null) { RemoteInterpreterProxy ri = RemoteInterpreter; if (ri != null && ri.IsDelegateType(Value)) { _propagateOnCall = GetEventInvokeArgs(); } else { _propagateOnCall = EmptyTypes; } } return(_propagateOnCall == EmptyTypes ? null : _propagateOnCall); }
public IList <IPythonType> GetEventParameterTypes() { if (_parameterTypes == null) { RemoteInterpreterProxy ri = RemoteInterpreter; ObjectIdentityHandle[] types = ri != null?ri.GetEventParameterPythonTypes(Value) : new ObjectIdentityHandle[0]; IPythonType[] paramTypes = new IPythonType[types.Length]; for (int i = 0; i < paramTypes.Length; i++) { paramTypes[i] = Interpreter.GetTypeFromType(types[i]); } _parameterTypes = paramTypes; } return(_parameterTypes); }
public IPythonFunction GetConstructors() { if (_ctors == null) { RemoteInterpreterProxy ri = RemoteInterpreter; if (ri != null && !ri.TypeGroupHasNewOrInitMethods(Value)) { _ctors = GetClrOverloads(); } if (_ctors == null) { _ctors = GetMember(null, "__new__") as IPythonFunction; } } return(_ctors); }
public IMember GetMember(IModuleContext context, string name) { if (_attrs == null) { Interlocked.CompareExchange(ref _attrs, new Dictionary <string, MemberInfo>(), null); } bool showClr = context == null || ((IronPythonModuleContext)context).ShowClr; if (!_attrs.TryGetValue(name, out MemberInfo member) || member.Member == null) { RemoteInterpreterProxy ri = RemoteInterpreter; ObjectIdentityHandle res = ri != null?ri.GetMember(Value, name) : default(ObjectIdentityHandle); if (!res.Equals(Value)) { _attrs[name] = member = new MemberInfo(_interpreter.MakeObject(res)); } } if (!showClr) { if (!(this is IronPythonNamespace)) { // namespaces always show all of their members... switch (member.ClrOnly) { case IsClrOnly.NotChecked: CreateNonClrAttrs(); if (_attrs.ContainsKey(name) && _attrs[name].ClrOnly == IsClrOnly.Yes) { return(null); } break; case IsClrOnly.No: break; case IsClrOnly.Yes: return(null); } } } return(member.Member); }
public IList <IPythonType> GetTypesPropagatedOnCall() { if (_eventInvokeArgs == null) { RemoteInterpreterProxy ri = RemoteInterpreter; ObjectIdentityHandle[] types = ri != null?ri.GetTypeGroupEventInvokeArgs(Value) : null; if (types == null) { _eventInvokeArgs = IronPythonType.EmptyTypes; } else { IPythonType[] args = new IPythonType[types.Length]; for (int i = 0; i < types.Length; i++) { args[i] = Interpreter.GetTypeFromType(types[i]); } _eventInvokeArgs = args; } } return(_eventInvokeArgs == IronPythonType.EmptyTypes ? null : _eventInvokeArgs); }
private void Interpreter_UnloadingDomain(object sender, EventArgs e) { _remote = null; _interpreter.UnloadingDomain -= Interpreter_UnloadingDomain; }
public IPythonType GetElementType() { RemoteInterpreterProxy ri = RemoteInterpreter; return(ri != null?Interpreter.GetTypeFromType(ri.GetPythonTypeElementType(Value)) : null); }
public IEnumerable <string> GetMemberNames(IModuleContext moduleContext) { RemoteInterpreterProxy ri = RemoteInterpreter; return(ri != null?ri.DirHelper(Value, ((IronPythonModuleContext)moduleContext).ShowClr) : Enumerable.Empty <string>()); }
private AppDomain CreateDomain(out RemoteInterpreterProxy remoteInterpreter) { // We create a sacrificial domain for loading all of our assemblies into. AppDomainSetup setup = new AppDomainSetup(); setup.ShadowCopyFiles = "true"; // We are in ...\Extensions\Microsoft\IronPython Interpreter\2.0 // We need to be able to load assemblies from: // Python Tools for Visual Studio\2.0 // IronPython Interpreter\2.0 // // So setup the application base to be Extensions\Microsoft\, and then add the other 2 dirs to the private bin path. setup.ApplicationBase = Path.GetDirectoryName(Path.GetDirectoryName(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location))); setup.PrivateBinPath = Path.GetDirectoryName(typeof(IronPythonInterpreter).Assembly.Location) + ";" + Path.GetDirectoryName(typeof(IPythonFunction).Assembly.Location); setup.PrivateBinPathProbe = ""; var domain = AppDomain.CreateDomain("IronPythonAnalysisDomain", null, setup); domain.AssemblyResolve += IronPythonResolver.domain_AssemblyResolve; remoteInterpreter = (RemoteInterpreterProxy)domain.CreateInstanceAndUnwrap( typeof(RemoteInterpreterProxy).Assembly.FullName, typeof(RemoteInterpreterProxy).FullName); #if DEBUG var assertListener = Debug.Listeners["Microsoft.PythonTools.AssertListener"]; if (assertListener != null) { domain.DoCallBack(new AssertListenerInitializer(assertListener).Initialize); } #endif return domain; }
public IEnumerable <string> GetChildrenModules() { RemoteInterpreterProxy ri = RemoteInterpreter; return(ri != null?ri.GetNamespaceChildren(Value) : Enumerable.Empty <string>()); }