public override bool Equals(object obj)
        {
            ActiveRecordPropertyDescriptor other = obj as ActiveRecordPropertyDescriptor;

            if (other == null)
            {
                return(false);
            }

            return(_columnName.Equals(other._columnName));
        }
Beispiel #2
0
		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;
		}
		public void AddProperty( ActiveRecordPropertyDescriptor propertyDescriptor )
		{
			_properties.Add(propertyDescriptor);
		}
Beispiel #4
0
		private void AddAppropriateAttribute(CodeMemberProperty memberProperty, ActiveRecordPropertyDescriptor property)
		{
			bool needExplicitColumnName = (String.Compare(property.ColumnName, property.PropertyName, true) != 0);

			CodeAttributeDeclaration codeAttribute = null;

			if (property is ActiveRecordPrimaryKeyDescriptor)
			{
				codeAttribute = new CodeAttributeDeclaration("PrimaryKey"); 
				codeAttribute.Arguments.Add( new CodeAttributeArgument( 
					new CodeSnippetExpression("PrimaryKeyType.Native") ) );
			
				if (needExplicitColumnName)
				{
					codeAttribute.Arguments.Add( new CodeAttributeArgument(
						new CodeSnippetExpression(Quote(property.ColumnName)) ) );
				}
			}
			else 
			{
				codeAttribute = new CodeAttributeDeclaration("Property"); 

				if (!property.Insert)
				{
					codeAttribute.Arguments.Add( new CodeAttributeArgument("Insert", 
						new CodeSnippetExpression("false") ) );
				}
				if (!property.Update)
				{
					codeAttribute.Arguments.Add( new CodeAttributeArgument("Update", 
						new CodeSnippetExpression("false") ) );
				}

				if (needExplicitColumnName)
				{
					codeAttribute.Arguments.Add( new CodeAttributeArgument("Column",
						new CodeSnippetExpression(Quote(property.ColumnName)) ) );
				}
			}

			memberProperty.CustomAttributes.Add( codeAttribute );
		}
Beispiel #5
0
 public void AddProperty(ActiveRecordPropertyDescriptor propertyDescriptor)
 {
     _properties.Add(propertyDescriptor);
 }