public static GenerateDotNetName ( String prefix, String value ) : String | ||
prefix | String | The prefix. |
value | String | The value. |
return | String |
private static CodeMemberProperty GenerateProperty(GenerationContext context, @class cls, property property) { String propertyType = context.ConvertType(property.type, true); String propertyName = NamingHelper.GenerateDotNetName(String.Empty, property.name); // Define various references CodeTypeReference typeReference = new CodeTypeReference(propertyType); CodeThisReferenceExpression thisReferenceExpression = new CodeThisReferenceExpression(); CodeTypeReferenceExpression typeReferenceExpression = new CodeTypeReferenceExpression("ObjectiveCRuntime"); // Define the property CodeMemberProperty memberProperty = new CodeMemberProperty(); memberProperty.Attributes = MemberAttributes.Public; memberProperty.Name = propertyName; memberProperty.Type = typeReference; // Generate getter switch (property.access) { case "r": case "rw": { String selector = NamingHelper.GenerateObjCName(property.name); CodeMethodReferenceExpression methodReferenceExpression = new CodeMethodReferenceExpression(typeReferenceExpression, "SendMessage"); methodReferenceExpression.TypeArguments.Add(typeReference); CodeMethodInvokeExpression invokeExpression = new CodeMethodInvokeExpression(methodReferenceExpression, thisReferenceExpression, new CodePrimitiveExpression(selector)); CodeMethodReturnStatement returnStatement = new CodeMethodReturnStatement(invokeExpression); memberProperty.GetStatements.Add(returnStatement); break; } default: break; } // Generate setter switch (property.access) { case "rw": case "w": { String selector = "set" + propertyName + ":"; CodeMethodReferenceExpression methodReferenceExpression = new CodeMethodReferenceExpression(typeReferenceExpression, "SendMessage"); CodeMethodInvokeExpression invokeExpression = new CodeMethodInvokeExpression(methodReferenceExpression, thisReferenceExpression, new CodePrimitiveExpression(selector), new CodeVariableReferenceExpression("value")); CodeExpressionStatement expressionStatement = new CodeExpressionStatement(invokeExpression); memberProperty.SetStatements.Add(expressionStatement); break; } default: break; } return(memberProperty); }
private static CodeTypeDeclaration GenerateEnumeration(GenerationContext context, enumeration enumeration) { String enumerationName = NamingHelper.GenerateDotNetName(context.Prefix, enumeration.name); CodeTypeDeclaration typeDeclaration = new CodeTypeDeclaration(); typeDeclaration.Name = enumerationName; typeDeclaration.IsEnum = true; typeDeclaration.BaseTypes.Add(typeof(uint)); IEnumerable <enumerator> values = enumeration.enumerator; foreach (enumerator value in values) { CodeMemberField memberField = new CodeMemberField(); memberField.Name = NamingHelper.GenerateDotNetName(enumerationName, value.name); if (!String.IsNullOrEmpty(value.code)) { uint constant = NamingHelper.ToUInt32(value.code); memberField.InitExpression = new CodePrimitiveExpression(constant); memberField.Comments.Add(new CodeCommentStatement("'" + value.code + "' => '0x" + constant.ToString("X8") + "'")); } typeDeclaration.Members.Add(memberField); } return(typeDeclaration); }
private static CodeMemberProperty GenerateElement(GenerationContext context, @class cls, element element) { String value; @class typeCls = context.Classes.FirstOrDefault(c => String.Equals(c.name, element.type)); if (typeCls != null) { // Make sure that we use the correct plural value = typeCls.plural ?? typeCls.name + "s"; } else { // Use the default name value = element.type; } String elementName = NamingHelper.GenerateDotNetName(String.Empty, value); String selector = NamingHelper.GenerateObjCName(value); // Define various references CodeTypeReference typeReference = new CodeTypeReference("SBElementArray"); CodeThisReferenceExpression thisReferenceExpression = new CodeThisReferenceExpression(); CodeTypeReferenceExpression typeReferenceExpression = new CodeTypeReferenceExpression("ObjectiveCRuntime"); // Define the property CodeMemberProperty memberProperty = new CodeMemberProperty(); memberProperty.Attributes = MemberAttributes.Public; memberProperty.Name = elementName; memberProperty.Type = typeReference; // Generate the getter CodeMethodReferenceExpression methodReferenceExpression = new CodeMethodReferenceExpression(typeReferenceExpression, "SendMessage"); methodReferenceExpression.TypeArguments.Add(typeReference); CodeMethodInvokeExpression invokeExpression = new CodeMethodInvokeExpression(methodReferenceExpression, thisReferenceExpression, new CodePrimitiveExpression(selector)); CodeMethodReturnStatement returnStatement = new CodeMethodReturnStatement(invokeExpression); memberProperty.GetStatements.Add(returnStatement); return(memberProperty); }
/// <summary> /// Converts the type. /// </summary> public String ConvertType(String type, bool anyType) { String result = type; // Search for a known class or enumeration @class typeCls = (from cls in this.Classes where (cls.id != null && String.Equals(cls.id, type)) || (cls.id == null && String.Equals(cls.name, type)) select cls).FirstOrDefault(); enumeration typeEnumeration = (from enm in this.Enumerations where (enm.id != null && String.Equals(enm.id, type)) || (enm.id == null && String.Equals(enm.name, type)) select enm).FirstOrDefault(); if (typeCls != null) { result = NamingHelper.GenerateDotNetName(this.Prefix, typeCls.name); return(result); } else if (typeEnumeration != null) { result = NamingHelper.GenerateDotNetName(this.Prefix, typeEnumeration.name); return(result); } if (anyType) { // Search for a common type switch (type) { case "void": result = "void"; break; case "boolean": result = "Boolean"; break; case "integer": case "unsigned integer": result = "NSInteger"; break; case "double integer": result = "Int64"; break; case "real": result = "double"; break; case "property": result = "IntPtr"; break; case "list": result = "NSArray"; break; case "color": case "RGB color": result = "NSColor"; break; case "data": case "tdta": case "picture": result = "NSData"; break; case "date": result = "NSDate"; break; case "record": result = "NSDictionary"; break; case "type": result = "NSNumber"; break; case "point": result = "NSPoint"; break; case "text": case "version": result = "NSString"; break; case "rectangle": result = "NSRect"; break; case "alias": case "file": result = "NSURL"; break; case "specifier": case "location specifier": result = "SBObject"; break; default: result = "Id"; break; } } return(result); }