NSObjectTypeInfo ConvertType(TypeSystemService.ProjectContentWrapper dom, ITypeDefinition type) { string objcName = null; bool isModel = false; bool registeredInDesigner = true; foreach (var att in type.Attributes) { var attType = att.AttributeType; if (attType.Equals(Resolve(dom, registerAttType))) { if (type.GetProjectContent() != null) { registeredInDesigner &= MonoDevelop.DesignerSupport.CodeBehind.IsDesignerFile(att.Region.FileName); } //type registered with an explicit type name are up to the user to provide a valid name var posArgs = att.PositionalArguments; if (posArgs.Count == 1 || posArgs.Count == 2) { objcName = posArgs [0].ConstantValue as string; } //non-nested types in the root namespace have names accessible from obj-c else if (string.IsNullOrEmpty(type.Namespace) && type.Name.IndexOf('.') < 0) { objcName = type.Name; } } if (attType.Equals(Resolve(dom, modelAttType))) { isModel = true; } } if (string.IsNullOrEmpty(objcName)) { return(null); } string baseType = type.DirectBaseTypes.First().ReflectionName; if (baseType == "System.Object") { baseType = null; } bool isUserType = !type.ParentAssembly.Equals(Resolve(dom, nsobjectType).ParentAssembly); var info = new NSObjectTypeInfo(objcName, type.ReflectionName, null, baseType, isModel, isUserType, registeredInDesigner); if (info.IsUserType) { UpdateTypeMembers(dom, info, type); info.DefinedIn = type.Parts.Select(p => (string)p.Region.FileName).ToArray(); } return(info); }
internal IEnumerable <NSObjectTypeInfo> GetRegisteredObjects(TypeSystemService.ProjectContentWrapper dom, IAssembly assembly) { var nso = Resolve(dom, nsobjectType); if (nso == null || nso.Kind == TypeKind.Unknown) { throw new Exception("Could not get NSObject from type database"); } //FIXME: only emit this for the wrapper NS // yield return new NSObjectTypeInfo ("NSObject", nso.GetDefinition ().FullName, null, null, false, false, false); int cnt = 0, infcnt = 0, models = 0; foreach (var contextType in assembly.GetAllTypeDefinitions()) { var importedType = dom.Compilation.Import(contextType); if (importedType.IsDerivedFrom(nso)) { var info = ConvertType(dom, importedType); if (info != null) { yield return(info); } } } }
public NSObjectProjectInfo (TypeSystemService.ProjectContentWrapper dom, NSObjectInfoService infoService, IAssembly lookinAssembly) { this.infoService = infoService; this.dom = dom; this.lookinAssembly = lookinAssembly; needsUpdating = true; }
public NSObjectProjectInfo(TypeSystemService.ProjectContentWrapper dom, NSObjectInfoService infoService, IAssembly lookinAssembly) { this.infoService = infoService; this.dom = dom; this.lookinAssembly = lookinAssembly; needsUpdating = true; }
void ListenToProjectLoad(Project project) { if (currentWrapper != null) { currentWrapper.Loaded -= HandleInLoadChanged; currentWrapper = null; } if (project != null) { var wrapper = TypeSystemService.GetProjectContentWrapper(project); wrapper.Loaded += HandleInLoadChanged; currentWrapper = wrapper; currentWrapper.RequestLoad(); } StartReparseThread(); }
public NSObjectProjectInfo GetProjectInfo(TypeSystemService.ProjectContentWrapper dom, IAssembly lookinAssembly = null) { NSObjectProjectInfo info; lock (infos) { if (infos.TryGetValue(dom, out info)) { return(info); } var nso = Resolve(dom, nsobjectType); //only include DOMs that can resolve NSObject if (nso == null || nso.Kind == TypeKind.Unknown) { return(null); } info = new NSObjectProjectInfo(dom, this, lookinAssembly); infos[dom] = info; } return(info); }
internal void SetProject(Project project) { if (Window.ViewContent.Project == project) { return; } DetachExtensionChain(); ISupportsProjectReload pr = GetContent <ISupportsProjectReload> (); if (pr != null) { // Unsubscribe project events if (Window.ViewContent.Project != null) { Window.ViewContent.Project.Modified -= HandleProjectModified; } Window.ViewContent.Project = project; pr.Update(project); } if (project != null) { project.Modified += HandleProjectModified; } InitializeExtensionChain(); StartReparseThread(); if (oldWrapper != null) { oldWrapper.InLoadChanged -= HandleInLoadChanged; oldWrapper = null; } if (project != null) { var wrapper = TypeSystemService.GetProjectContentWrapper(project); wrapper.InLoadChanged += HandleInLoadChanged; oldWrapper = wrapper; } }
ITypeDefinition Resolve(TypeSystemService.ProjectContentWrapper dom, ITypeReference reference) { return(reference.Resolve(dom.Compilation).GetDefinition()); }
void UpdateTypeMembers(TypeSystemService.ProjectContentWrapper dom, NSObjectTypeInfo info, ITypeDefinition type) { info.Actions.Clear(); info.Outlets.Clear(); foreach (var prop in type.Properties) { foreach (var att in prop.Attributes) { var attType = att.AttributeType; bool isIBOutlet = attType.Equals(Resolve(dom, iboutletAttType)); if (!isIBOutlet) { if (!attType.Equals(Resolve(dom, connectAttType))) { continue; } } string name = null; var posArgs = att.PositionalArguments; if (posArgs.Count == 1) { name = posArgs [0].ConstantValue as string; } if (string.IsNullOrEmpty(name)) { name = prop.Name; } // HACK: Work around bug #1586 in the least obtrusive way possible. Strip out any outlet // with the name 'view' on subclasses of MonoTouch.UIKit.UIViewController to avoid // conflicts with the view property mapped there if (name == "view") { if (type.GetAllBaseTypeDefinitions().Any(p => p.ReflectionName == "MonoTouch.UIKit.UIViewController")) { continue; } } var ol = new IBOutlet(name, prop.Name, null, prop.ReturnType.ReflectionName); if (MonoDevelop.DesignerSupport.CodeBehind.IsDesignerFile(prop.Region.FileName)) { ol.IsDesigner = true; } info.Outlets.Add(ol); break; } } foreach (var meth in type.Methods) { foreach (var att in meth.Attributes) { var attType = att.AttributeType; bool isIBAction = attType.Equals(Resolve(dom, ibactionAttType)); if (!isIBAction) { if (!attType.Equals(Resolve(dom, exportAttType))) { continue; } } bool isDesigner = MonoDevelop.DesignerSupport.CodeBehind.IsDesignerFile(meth.Region.FileName); //only support Export from old designer files, user code must be IBAction if (!isDesigner && !isIBAction) { continue; } string[] name = null; var posArgs = att.PositionalArguments; if (posArgs.Count == 1 || posArgs.Count == 2) { var n = posArgs [0].ConstantValue as string; if (!string.IsNullOrEmpty(n)) { name = n.Split(colonChar); } } var action = new IBAction(name != null ? name [0] : meth.Name, meth.Name); int i = 1; foreach (var param in meth.Parameters) { string label = name != null && i < name.Length ? name [i] : null; if (label != null && label.Length == 0) { label = null; } action.Parameters.Add(new IBActionParameter(label, param.Name, null, param.Type.ReflectionName)); } if (MonoDevelop.DesignerSupport.CodeBehind.IsDesignerFile(meth.Region.FileName)) { action.IsDesigner = true; } info.Actions.Add(action); break; } } }