public void CreateFieldName() { INamingService service = (INamingService)Kernel[typeof(INamingService)]; Assert.AreEqual("_orderName", service.CreateFieldName("order_name")); Assert.AreEqual("_name", service.CreateFieldName("name")); Assert.AreEqual("_customerName", service.CreateFieldName("customerName")); Assert.AreEqual("_customerName", service.CreateFieldName("customer_name")); Assert.AreEqual("_customerName", service.CreateFieldName("customer_Name")); Assert.AreEqual("_customerName", service.CreateFieldName("CustomerName")); Assert.AreEqual("_name", service.CreateFieldName("_name")); }
private CodeMemberProperty CreatePropertyMember(ActiveRecordPropertyDescriptor property, CodeTypeDeclaration declaration) { String targetTypeName = null; if (property.PropertyType != null) { targetTypeName = property.PropertyType.FullName; } else if (property is ActiveRecordPropertyRelationDescriptor) { targetTypeName = (property as ActiveRecordPropertyRelationDescriptor).TargetType.ClassName; } else { throw new ApplicationException("Could not resolve property type"); } String fieldName = _namingService.CreateFieldName(property.PropertyName); declaration.Members.Add(new CodeMemberField(targetTypeName, fieldName)); CodeMemberProperty memberProperty = new CodeMemberProperty(); memberProperty.Attributes = MemberAttributes.Public | MemberAttributes.Final; memberProperty.Name = property.PropertyName; memberProperty.Type = new CodeTypeReference(targetTypeName); CodeFieldReferenceExpression fieldReference = new CodeFieldReferenceExpression( new CodeThisReferenceExpression(), fieldName); memberProperty.GetStatements.Add( new CodeMethodReturnStatement(fieldReference)); memberProperty.SetStatements.Add( new CodeAssignStatement(fieldReference, new CodeArgumentReferenceExpression("value"))); return(memberProperty); }