void WriteActionSignature(IBAction action, System.IO.TextWriter writer) { writer.Write("- (IBAction){0}", action.ObjCName); bool isFirst = true; foreach (var param in action.Parameters) { string paramType = param.ObjCType; if (isFirst && paramType == "NSObject") { paramType = "id"; } else { paramType = paramType + " *"; } if (isFirst) { isFirst = false; writer.Write(":({0}){1}", paramType, param.Name); } else { writer.Write(" {0}:({1}){2}", param.Label, paramType, param.Name); } } }
void UpdateType(ProjectDom dom, NSObjectTypeInfo info, IType type) { info.Actions.Clear(); info.Outlets.Clear(); foreach (var prop in type.Properties) { foreach (var att in prop.Attributes) { if (att.AttributeType.FullName != connectAttType.FullName) { continue; } string name = null; if (att.PositionalArguments.Count == 1) { name = (string)((System.CodeDom.CodePrimitiveExpression)att.PositionalArguments[0]).Value; } if (string.IsNullOrEmpty(name)) { name = prop.Name; } info.Outlets.Add(new IBOutlet(name, prop.Name, null, prop.ReturnType.FullName)); break; } } foreach (var meth in type.Methods) { foreach (var att in meth.Attributes) { if (att.AttributeType.FullName != exportAttType.FullName) { continue; } string[] name = null; if (att.PositionalArguments.Count == 1) { var n = (string)((System.CodeDom.CodePrimitiveExpression)att.PositionalArguments[0]).Value; if (!string.IsNullOrEmpty(n)) { name = n.Split(colonChar); } } var action = new IBAction(name != null? name [0] : meth.Name, meth.Name); info.Actions.Add(action); 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.ReturnType.FullName)); } break; } } }
void WriteActionSignature(IBAction action, System.IO.TextWriter writer) { writer.Write("- (IBAction){0}", action.ObjCName); bool isFirst = true; foreach (var param in action.Parameters) { string paramType = param.ObjCType; if (paramType == null) { throw new ObjectiveCGenerationException(string.Format( "Could not generate Obj-C code for action '{0}' in class '{1}' as the type '{2}'" + "of its parameter '{3}' could not be resolved to Obj-C", action.CliName, this.CliName, param.CliType, param.Name), this); } if (isFirst && paramType == "NSObject") { paramType = "id"; } else { paramType = paramType + " *"; } if (isFirst) { isFirst = false; writer.Write(":({0}){1}", paramType, param.Name); } else { writer.Write(" {0}:({1}){2}", param.Label, paramType, param.Name); } } }
void AddParameters (IBAction action) { bool isFirst = true; foreach (var p in action.Parameters) { if (!isFirst) { Write (", "); } else { isFirst = false; } Write (p.CliType); Write (" "); Write (EscapeIdentifier (p.Name)); } }
public static NSObjectTypeInfo ParseHeader(string headerFile) { var text = System.IO.File.ReadAllText(headerFile); var matches = ibRegex.Matches(text); var type = new NSObjectTypeInfo(System.IO.Path.GetFileNameWithoutExtension(headerFile), null, null, null, false); foreach (Match match in matches) { var kind = match.Groups[1].Value; var def = match.Groups[2].Value; if (kind == "IBOutlet") { var split = def.Split(whitespaceChars, StringSplitOptions.RemoveEmptyEntries); if (split.Length != 2) { continue; } string objcType = split[1].TrimStart('*'); if (objcType == "id") { objcType = "NSObject"; } type.Outlets.Add(new IBOutlet((objcType), null, split[0].TrimEnd('*'), null)); } else { string[] split = def.Split(colonChar); var action = new IBAction(split[0].Trim(), null); string label = null; for (int i = 1; i < split.Length; i++) { var s = split[i].Split(splitActionParamsChars, StringSplitOptions.RemoveEmptyEntries); string objcType = s[0]; if (objcType == "id") { objcType = "NSObject"; } var par = new IBActionParameter(label, s[1], objcType, null); label = s.Length == 3? s[2] : null; action.Parameters.Add(par); } type.Actions.Add(action); } } return(type); }
void AddParameters(IBAction action) { bool isFirst = true; foreach (var p in action.Parameters) { if (!isFirst) { Write(", "); } else { isFirst = false; } Write(p.CliType); Write(" "); Write(EscapeIdentifier(p.Name)); } }
public static CodeTypeMember CreateEventMethod(CodeTypeReference exportAtt, IBAction action) { var meth = new CodeMemberMethod() { Name = action.CliName, ReturnType = new CodeTypeReference(typeof(void)), }; foreach (var p in action.Parameters) { meth.Parameters.Add(new CodeParameterDeclarationExpression() { Name = p.Name, Type = new CodeTypeReference(p.ObjCType) }); } AddAttribute(meth.CustomAttributes, exportAtt, action.GetObjcFullName()); return(meth); }
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; } } }
static void GenerateAction(CodeTypeReference actionAtt, CodeTypeDeclaration type, IBAction action, CodeDomProvider provider) { var m = CreateEventMethod(actionAtt, action); type.Members.Add(m); if (provider.FileExtension == "pas") { m.UserData ["OxygenePartial"] = "YES"; m.UserData ["OxygeneEmpty"] = "YES"; } }
public static CodeTypeMember CreateEventMethod (CodeTypeReference exportAtt, IBAction action) { var meth = new CodeMemberMethod () { Name = action.CliName, ReturnType = new CodeTypeReference (typeof (void)), }; foreach (var p in action.Parameters) { meth.Parameters.Add (new CodeParameterDeclarationExpression () { Name = p.Name, Type = new CodeTypeReference (p.ObjCType) }); } AddAttribute (meth.CustomAttributes, exportAtt, action.GetObjcFullName ()); return meth; }
void UpdateTypeMembers(ProjectDom dom, NSObjectTypeInfo info, IType type) { info.Actions.Clear(); info.Outlets.Clear(); foreach (var prop in type.Properties) { foreach (var att in prop.Attributes) { bool isIBOutlet = att.AttributeType.FullName == iboutletAttType.FullName; if (!isIBOutlet) { if (att.AttributeType.FullName != connectAttType.FullName) { continue; } } string name = null; if (att.PositionalArguments.Count == 1) { name = (string)((System.CodeDom.CodePrimitiveExpression)att.PositionalArguments[0]).Value; } 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 (dom.GetInheritanceTree(type).Any(p => p.FullName == "MonoTouch.UIKit.UIViewController")) { continue; } } var ol = new IBOutlet(name, prop.Name, null, prop.ReturnType.FullName); if (MonoDevelop.DesignerSupport.CodeBehind.IsDesignerFile(prop.DeclaringType.CompilationUnit.FileName)) { ol.IsDesigner = true; } info.Outlets.Add(ol); break; } } foreach (var meth in type.Methods) { foreach (var att in meth.Attributes) { bool isIBAction = att.AttributeType.FullName == ibactionAttType.FullName; if (!isIBAction) { if (att.AttributeType.FullName != exportAttType.FullName) { continue; } } bool isDesigner = MonoDevelop.DesignerSupport.CodeBehind.IsDesignerFile( meth.DeclaringType.CompilationUnit.FileName); //only support Export from old designer files, user code must be IBAction if (!isDesigner && !isIBAction) { continue; } string[] name = null; if (att.PositionalArguments.Count == 1) { var n = (string)((System.CodeDom.CodePrimitiveExpression)att.PositionalArguments[0]).Value; 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.ReturnType.FullName)); } if (MonoDevelop.DesignerSupport.CodeBehind.IsDesignerFile(meth.DeclaringType.CompilationUnit.FileName)) { action.IsDesigner = true; } info.Actions.Add(action); break; } } }
void WriteActionSignature (IBAction action, System.IO.TextWriter writer) { writer.Write ("- (IBAction){0}", action.ObjCName); bool isFirst = true; foreach (var param in action.Parameters) { string paramType = param.ObjCType; if (paramType == null) { throw new ObjectiveCGenerationException (string.Format ( "Could not generate Obj-C code for action '{0}' in class '{1}' as the type '{2}'" + "of its parameter '{3}' could not be resolved to Obj-C", action.CliName, this.CliName, param.CliType, param.Name), this); } if (isFirst && paramType == "NSObject") paramType = "id"; else paramType = paramType + " *"; if (isFirst) { isFirst = false; writer.Write (":({0}){1}", paramType, param.Name); } else { writer.Write (" {0}:({1}){2}", param.Label, paramType, param.Name); } } }
static void GenerateAction (CodeTypeReference actionAtt, CodeTypeDeclaration type, IBAction action, CodeDomProvider provider) { var m = CreateEventMethod (actionAtt, action); type.Members.Add (m); if (provider.FileExtension == "pas") { m.UserData ["OxygenePartial"] = "YES"; m.UserData ["OxygeneEmpty"] = "YES"; } }
public static NSObjectTypeInfo ParseHeader (string headerFile) { string text = File.ReadAllText (headerFile); string userType = null, userBaseType = null; MatchCollection matches; NSObjectTypeInfo type; // First, grep for classes matches = typeInfoRegex.Matches (text); foreach (Match match in matches) { if (match.Groups[1].Value != "interface") continue; if (userType != null) { // UNSUPPORTED: more than 1 user-type defined in this header return null; } userType = match.Groups[2].Value; userBaseType = match.Groups[3].Value; } if (userType == null) return null; type = new NSObjectTypeInfo (userType, null, userBaseType, null, false, true, true); // Now grep for IBActions and IBOutlets matches = ibRegex.Matches (text); foreach (Match match in matches) { var kind = match.Groups[1].Value; var def = match.Groups[2].Value; if (kind == "IBOutlet") { var split = def.Split (whitespaceChars, StringSplitOptions.RemoveEmptyEntries); if (split.Length != 2) continue; string objcName = split[1].TrimStart ('*'); string objcType = split[0].TrimEnd ('*'); if (objcType == "id") objcType = "NSObject"; if (string.IsNullOrEmpty (objcType)) { MessageService.ShowError (GettextCatalog.GetString ("Error while parsing header file."), string.Format (GettextCatalog.GetString ("The definition '{0}' can't be parsed."), def)); objcType = "NSObject"; } IBOutlet outlet = new IBOutlet (objcName, objcName, objcType, null); outlet.IsDesigner = true; type.Outlets.Add (outlet); } else { string[] split = def.Split (colonChar); string name = split[0].Trim (); var action = new IBAction (name, name); action.IsDesigner = true; string label = null; for (int i = 1; i < split.Length; i++) { var s = split[i].Split (splitActionParamsChars, StringSplitOptions.RemoveEmptyEntries); string objcType = s[0]; if (objcType == "id") objcType = "NSObject"; var par = new IBActionParameter (label, s[1], objcType, null); label = s.Length == 3? s[2] : null; action.Parameters.Add (par); } type.Actions.Add (action); } } return type; }
public static NSObjectTypeInfo ParseHeader (string headerFile) { var text = System.IO.File.ReadAllText (headerFile); var matches = ibRegex.Matches (text); var type = new NSObjectTypeInfo (System.IO.Path.GetFileNameWithoutExtension (headerFile), null, null, null, false); foreach (Match match in matches) { var kind = match.Groups[1].Value; var def = match.Groups[2].Value; if (kind == "IBOutlet") { var split = def.Split (whitespaceChars, StringSplitOptions.RemoveEmptyEntries); if (split.Length != 2) continue; string objcName = split[1].TrimStart ('*'); string objcType = split[0].TrimEnd ('*'); if (objcType == "id") objcType = "NSObject"; if (string.IsNullOrEmpty (objcType)) { MessageService.ShowError (GettextCatalog.GetString ("Error while parsing header file."), string.Format (GettextCatalog.GetString ("The definition '{0}' can't be parsed."), def)); objcType = "NSObject"; } type.Outlets.Add (new IBOutlet (objcName, null, objcType, null)); } else { string[] split = def.Split (colonChar); var action = new IBAction (split[0].Trim (), null); string label = null; for (int i = 1; i < split.Length; i++) { var s = split[i].Split (splitActionParamsChars, StringSplitOptions.RemoveEmptyEntries); string objcType = s[0]; if (objcType == "id") objcType = "NSObject"; var par = new IBActionParameter (label, s[1], objcType, null); label = s.Length == 3? s[2] : null; action.Parameters.Add (par); } type.Actions.Add (action); } } return type; }
public static NSObjectTypeInfo ParseHeader(string headerFile) { string text = File.ReadAllText(headerFile); string userType = null, userBaseType = null; MatchCollection matches; NSObjectTypeInfo type; // First, grep for classes matches = typeInfoRegex.Matches(text); foreach (Match match in matches) { if (match.Groups[1].Value != "interface") { continue; } if (userType != null) { // UNSUPPORTED: more than 1 user-type defined in this header return(null); } userType = match.Groups[2].Value; userBaseType = match.Groups[3].Value; } if (userType == null) { return(null); } type = new NSObjectTypeInfo(userType, null, userBaseType, null, false, true, true); // Now grep for IBActions and IBOutlets matches = ibRegex.Matches(text); foreach (Match match in matches) { var kind = match.Groups[1].Value; var def = match.Groups[2].Value; if (kind == "IBOutlet") { var split = def.Split(whitespaceChars, StringSplitOptions.RemoveEmptyEntries); string objcType = split[0].TrimEnd('*'); string objcName = null; for (int i = 1; i < split.Length; i++) { objcName = split[i].TrimStart('*'); if (string.IsNullOrEmpty(objcName)) { continue; } if (i + 1 < split.Length) { // This is a bad sign... what tokens are after the name?? objcName = null; break; } } if (string.IsNullOrEmpty(objcType) || string.IsNullOrEmpty(objcName)) { MessageService.ShowError(GettextCatalog.GetString("Error while parsing header file."), string.Format(GettextCatalog.GetString("The definition '{0}' can't be parsed."), def)); // We can't recover if objcName is empty... if (string.IsNullOrEmpty(objcName)) { continue; } // We can try using NSObject... objcType = "NSObject"; } if (objcType == "id") { objcType = "NSObject"; } IBOutlet outlet = new IBOutlet(objcName, objcName, objcType, null); outlet.IsDesigner = true; type.Outlets.Add(outlet); } else { string[] split = def.Split(colonChar); string name = split[0].Trim(); var action = new IBAction(name, name); action.IsDesigner = true; string label = null; for (int i = 1; i < split.Length; i++) { var s = split[i].Split(splitActionParamsChars, StringSplitOptions.RemoveEmptyEntries); string objcType = s[0]; if (objcType == "id") { objcType = "NSObject"; } var par = new IBActionParameter(label, s[1], objcType, null); label = s.Length == 3? s[2] : null; action.Parameters.Add(par); } type.Actions.Add(action); } } return(type); }
static void GenerateAction (CodeTypeReference exportAtt, CodeTypeDeclaration type, IBAction action, CodeDomProvider provider, CodeGeneratorOptions generatorOptions) { if (provider is Microsoft.CSharp.CSharpCodeProvider) { type.Members.Add (new CodeSnippetTypeMember ("[" + exportAtt.BaseType + "(\"" + action.GetObjcFullName () + "\")]")); var sb = new System.Text.StringBuilder (); sb.Append ("partial void "); sb.Append (provider.CreateEscapedIdentifier (action.CliName)); sb.Append (" ("); if (action.Parameters != null) { bool isFirst = true; foreach (var p in action.Parameters) { if (!isFirst) { sb.Append (", "); } else { isFirst = false; } sb.Append (p.CliType); sb.Append (" "); sb.Append (provider.CreateEscapedIdentifier (p.Name)); } } sb.Append (");"); type.Members.Add (new CodeSnippetTypeMember (sb.ToString ())); return; } var m = CreateEventMethod (exportAtt, action); type.Members.Add (m); if (provider.FileExtension == "pas") { m.UserData ["OxygenePartial"] = "YES"; m.UserData ["OxygeneEmpty"] = "YES"; } }
void WriteActionSignature (IBAction action, System.IO.TextWriter writer) { writer.Write ("- (IBAction){0}", action.ObjCName); bool isFirst = true; foreach (var param in action.Parameters) { string paramType = param.ObjCType; if (isFirst && paramType == "NSObject") paramType = "id"; else paramType = paramType + " *"; if (isFirst) { isFirst = false; writer.Write (":({0}){1}", paramType, param.Name); } else { writer.Write (" {0}:({1}){2}", param.Label, paramType, param.Name); } } }
void UpdateTypeMembers (ProjectDom dom, NSObjectTypeInfo info, IType type) { info.Actions.Clear (); info.Outlets.Clear (); foreach (var prop in type.Properties) { foreach (var att in prop.Attributes) { bool isIBOutlet = att.AttributeType.FullName == iboutletAttType.FullName; if (!isIBOutlet) { if (att.AttributeType.FullName != connectAttType.FullName) continue; } string name = null; if (att.PositionalArguments.Count == 1) name = (string)((System.CodeDom.CodePrimitiveExpression)att.PositionalArguments[0]).Value; if (string.IsNullOrEmpty (name)) name = prop.Name; var ol = new IBOutlet (name, prop.Name, null, prop.ReturnType.FullName); if (MonoDevelop.DesignerSupport.CodeBehind.IsDesignerFile (prop.DeclaringType.CompilationUnit.FileName)) ol.IsDesigner = true; info.Outlets.Add (ol); break; } } foreach (var meth in type.Methods) { foreach (var att in meth.Attributes) { bool isIBAction = att.AttributeType.FullName == ibactionAttType.FullName; if (!isIBAction) { if (att.AttributeType.FullName != exportAttType.FullName) continue; } bool isDesigner = MonoDevelop.DesignerSupport.CodeBehind.IsDesignerFile ( meth.DeclaringType.CompilationUnit.FileName); //only support Export from old designer files, user code must be IBAction if (!isDesigner && !isIBAction) continue; string[] name = null; if (att.PositionalArguments.Count == 1) { var n = (string)((System.CodeDom.CodePrimitiveExpression)att.PositionalArguments[0]).Value; 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.ReturnType.FullName)); } if (MonoDevelop.DesignerSupport.CodeBehind.IsDesignerFile (meth.DeclaringType.CompilationUnit.FileName)) action.IsDesigner = true; info.Actions.Add (action); break; } } }
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.DeclaringTypeDefinition.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; } } }
void UpdateTypeMembers (ProjectDom dom, NSObjectTypeInfo info, IType type) { info.Actions.Clear (); info.Outlets.Clear (); foreach (var prop in type.Properties) { foreach (var att in prop.Attributes) { bool isIBOutlet = att.AttributeType.FullName == iboutletAttType.FullName; if (!isIBOutlet) { if (att.AttributeType.FullName != connectAttType.FullName) continue; } string name = null; if (att.PositionalArguments.Count == 1) name = (string)((System.CodeDom.CodePrimitiveExpression)att.PositionalArguments[0]).Value; 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 (dom.GetInheritanceTree (type).Any (p => p.FullName == "MonoTouch.UIKit.UIViewController")) continue; var ol = new IBOutlet (name, prop.Name, null, prop.ReturnType.FullName); if (MonoDevelop.DesignerSupport.CodeBehind.IsDesignerFile (prop.DeclaringType.CompilationUnit.FileName)) ol.IsDesigner = true; info.Outlets.Add (ol); break; } } foreach (var meth in type.Methods) { foreach (var att in meth.Attributes) { bool isIBAction = att.AttributeType.FullName == ibactionAttType.FullName; if (!isIBAction) { if (att.AttributeType.FullName != exportAttType.FullName) continue; } bool isDesigner = MonoDevelop.DesignerSupport.CodeBehind.IsDesignerFile ( meth.DeclaringType.CompilationUnit.FileName); //only support Export from old designer files, user code must be IBAction if (!isDesigner && !isIBAction) continue; string[] name = null; if (att.PositionalArguments.Count == 1) { var n = (string)((System.CodeDom.CodePrimitiveExpression)att.PositionalArguments[0]).Value; 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.ReturnType.FullName)); } if (MonoDevelop.DesignerSupport.CodeBehind.IsDesignerFile (meth.DeclaringType.CompilationUnit.FileName)) action.IsDesigner = true; info.Actions.Add (action); break; } } }
static void UpdateTypeMembers (ProjectDom dom, NSObjectTypeInfo info, IType type) { info.Actions.Clear (); info.Outlets.Clear (); foreach (var prop in type.Properties) { foreach (var att in prop.Attributes) { if (att.AttributeType.FullName != connectAttType.FullName) continue; string name = null; if (att.PositionalArguments.Count == 1) name = (string)((System.CodeDom.CodePrimitiveExpression)att.PositionalArguments[0]).Value; if (string.IsNullOrEmpty (name)) name = prop.Name; info.Outlets.Add (new IBOutlet (name, prop.Name, null, prop.ReturnType.FullName)); break; } } foreach (var meth in type.Methods) { foreach (var att in meth.Attributes) { if (att.AttributeType.FullName != exportAttType.FullName) continue; string[] name = null; if (att.PositionalArguments.Count == 1) { var n = (string)((System.CodeDom.CodePrimitiveExpression)att.PositionalArguments[0]).Value; if (!string.IsNullOrEmpty (n)) name = n.Split (colonChar); } var action = new IBAction (name != null? name [0] : meth.Name, meth.Name); info.Actions.Add (action); 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.ReturnType.FullName)); } break; } } }
public static NSObjectTypeInfo ParseHeader (string headerFile) { var text = System.IO.File.ReadAllText (headerFile); var matches = ibRegex.Matches (text); var type = new NSObjectTypeInfo (System.IO.Path.GetFileNameWithoutExtension (headerFile), null, null, null, false); foreach (Match match in matches) { var kind = match.Groups[1].Value; var def = match.Groups[2].Value; if (kind == "IBOutlet") { var split = def.Split (whitespaceChars, StringSplitOptions.RemoveEmptyEntries); if (split.Length != 2) continue; type.Outlets.Add (new IBOutlet (split[1].TrimStart ('*'), null, split[0].TrimEnd ('*'), null)); } else { string[] split = def.Split (colonChar); var action = new IBAction (split[0].Trim (), null); string label = null; for (int i = 1; i < split.Length; i++) { var s = split[i].Split (splitActionParamsChars, StringSplitOptions.RemoveEmptyEntries); var par = new IBActionParameter (label, s[1], s[0], null); label = s.Length == 3? s[2] : null; action.Parameters.Add (par); } type.Actions.Add (action); } } return type; }
static void GenerateAction(CodeTypeReference exportAtt, CodeTypeDeclaration type, IBAction action, CodeDomProvider provider, CodeGeneratorOptions generatorOptions) { if (provider is Microsoft.CSharp.CSharpCodeProvider) { type.Members.Add(new CodeSnippetTypeMember("[" + exportAtt.BaseType + "(\"" + action.GetObjcFullName() + "\")]")); var sb = new System.Text.StringBuilder(); sb.Append("partial void "); sb.Append(provider.CreateEscapedIdentifier(action.CliName)); sb.Append(" ("); if (action.Parameters != null) { bool isFirst = true; foreach (var p in action.Parameters) { if (!isFirst) { sb.Append(", "); } else { isFirst = false; } sb.Append(p.CliType); sb.Append(" "); sb.Append(provider.CreateEscapedIdentifier(p.Name)); } } sb.Append(");"); type.Members.Add(new CodeSnippetTypeMember(sb.ToString())); return; } var m = CreateEventMethod(exportAtt, action); type.Members.Add(m); if (provider.FileExtension == "pas") { m.UserData ["OxygenePartial"] = "YES"; m.UserData ["OxygeneEmpty"] = "YES"; } }