Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added new BsonSerializationOptionsAttribute which serves as the base …
…class for the existing BsonRepresentationAttribute and the new BsonDateTimeOptionsAttribute. Added DateTimeSerializationOptions to allow control over how DateTime values are serialized (representation, local/utc, dateOnly). Refactored AutoMapMember to process attributes in a loop. WriteDateTime in BsonWriter now checks that the value is in UTC (it is the job of the serializer to perform any needed conversions).
- Loading branch information
rstam
committed
Oct 30, 2010
1 parent
9c25039
commit 118aaf1
Showing
13 changed files
with
996 additions
and
65 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
58 changes: 58 additions & 0 deletions
58
Bson/DefaultSerializer/Attributes/BsonDateTimeOptionsAttribute.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
/* Copyright 2010 10gen Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
|
||
namespace MongoDB.Bson.DefaultSerializer { | ||
// [AttributeUsage(AttributeTargets.Property | AttributeTargets.Field)] | ||
public class BsonDateTimeOptionsAttribute : BsonSerializationOptionsAttribute { | ||
#region private fields | ||
private bool dateOnly = false; | ||
private DateTimeKind kind = DateTimeKind.Utc; | ||
private BsonType representation = BsonType.DateTime; | ||
#endregion | ||
|
||
#region constructors | ||
public BsonDateTimeOptionsAttribute() { | ||
} | ||
#endregion | ||
|
||
#region public properties | ||
public bool DateOnly { | ||
get { return dateOnly; } | ||
set { dateOnly = value; } | ||
} | ||
|
||
public DateTimeKind Kind { | ||
get { return kind; } | ||
set { kind = value; } | ||
} | ||
|
||
public BsonType Representation { | ||
get { return representation; } | ||
set { representation = value; } | ||
} | ||
#endregion | ||
|
||
#region public methods | ||
public override object GetOptions() { | ||
return new DateTimeSerializationOptions { DateOnly = dateOnly, Kind = kind, Representation = representation }; | ||
} | ||
#endregion | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletions
33
Bson/DefaultSerializer/Attributes/BsonSerializationOptionsAttribute.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
/* Copyright 2010 10gen Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
|
||
namespace MongoDB.Bson.DefaultSerializer { | ||
[AttributeUsage(AttributeTargets.Property | AttributeTargets.Field)] | ||
public abstract class BsonSerializationOptionsAttribute : Attribute { | ||
#region constructors | ||
protected BsonSerializationOptionsAttribute() { | ||
} | ||
#endregion | ||
|
||
#region public methods | ||
public abstract object GetOptions(); | ||
#endregion | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.