A class can be described by zero or more IBPartialClassDescription (from the IB file, from a header file, etc).
public static IBObject GetInstance(IDictionary <String, String> attributes) { IBObject obj; switch (attributes["class"]) { case "NSArray": case "NSMutableArray": obj = new IBArray(attributes); break; case "NSDictionary": case "NSMutableDictionary": obj = new IBDictionary(attributes); break; case "IBClassDescriber": obj = new IBClassDescriber(attributes); break; case "IBPartialClassDescription": obj = new IBPartialClassDescription(attributes); break; case "NSSet": case "NSMutableSet": obj = new IBSet(attributes); break; default: obj = new IBObject(attributes); break; } return(obj); }
public static CodeTypeMember GetExposedMethod(IBPartialClassDescription.ActionDescription action) { String selector = action.Message; String name = GenerateMethodName(selector); // Create a public method CodeMemberMethod exposedMethod = new CodeMemberMethod(); exposedMethod.Attributes = MemberAttributes.Public; exposedMethod.Name = "__" + name; exposedMethod.ReturnType = new CodeTypeReference(typeof(void)); exposedMethod.Parameters.Add(new CodeParameterDeclarationExpression("Id", "sender")); // Add custom attributes exposedMethod.CustomAttributes.Add(new CodeAttributeDeclaration("IBAction")); exposedMethod.CustomAttributes.Add(new CodeAttributeDeclaration("ObjectiveCMessage", new CodeAttributeArgument(new CodePrimitiveExpression(selector)))); // Add body to call partial method exposedMethod.Statements.Add(new CodeMethodInvokeExpression( new CodeThisReferenceExpression(), name, new CodeArgumentReferenceExpression("sender") ) ); return exposedMethod; }
public static IBObject GetInstance(IDictionary<String, String> attributes) { IBObject obj; switch (attributes["class"]) { case "NSArray": case "NSMutableArray": obj = new IBArray(attributes); break; case "NSDictionary": case "NSMutableDictionary": obj = new IBDictionary(attributes); break; case "IBClassDescriber": obj = new IBClassDescriber(attributes); break; case "IBPartialClassDescription": obj = new IBPartialClassDescription(attributes); break; case "NSSet": case "NSMutableSet": obj = new IBSet(attributes); break; default: obj = new IBObject(attributes); break; } return obj; }
public static CodeTypeMember GetOutletField(IBPartialClassDescription.OutletDescription outlet) { CodeMemberField field = new CodeMemberField(outlet.ClassName, outlet.Name); field.Attributes = MemberAttributes.Public; // Add custom attributes field.CustomAttributes.Add(new CodeAttributeDeclaration("IBOutlet")); field.CustomAttributes.Add(new CodeAttributeDeclaration("ObjectiveCField")); return field; }
public static CodeTypeMember GetPartialMethod(IBPartialClassDescription.ActionDescription action, CodeBehindWriter writer) { String selector = action.Message; String name = GenerateMethodName(selector); // Partial method are only possible by using a snippet of code as CodeDom does not handle them CodeSnippetTypeMember partialMethod; if (writer.Provider is CSharpCodeProvider) { partialMethod = new CodeSnippetTypeMember("partial void " + name + "(Id sender);" + Environment.NewLine); } else if (writer.Provider is VBCodeProvider) { // TODO: Check the generated code partialMethod = new CodeSnippetTypeMember("Partial Private Sub " + name + "(Id sender)" + Environment.NewLine + "End Sub" + Environment.NewLine); } else { throw new NotSupportedException("Provider not supported yet : " + writer.Provider); } return partialMethod; }