Permalink
Browse files

Code cleanup.

  • Loading branch information...
1 parent 17e3d57 commit 41b19cb1f4257fd082d452644c9cafbbcd95cb31 @lanwin lanwin committed Jun 2, 2010
Showing with 393 additions and 681 deletions.
  1. +1 −0 source/MongoDB.Tests/IntegrationTests/TestCollection.cs
  2. +1 −0 source/MongoDB.Tests/IntegrationTests/TestCollection_1.cs
  3. +1 −0 source/MongoDB.Tests/UnitTests/Bson/TestBsonReader.cs
  4. +1 −0 source/MongoDB.Tests/UnitTests/TestDBRef.cs
  5. +1 −0 source/MongoDB.Tests/UnitTests/TestOidGenerator.cs
  6. +7 −4 source/MongoDB/Bson/BsonDocumentBuilder.cs
  7. +4 −3 source/MongoDB/Bson/BsonDocumentDescriptor.cs
  8. +1 −3 source/MongoDB/CollectionMetadata.cs
  9. +1 −4 source/MongoDB/Configuration/Builders/MappingStoreBuilder.cs
  10. +1 −1 source/MongoDB/Configuration/Mapping/Auto/AutoMapper.cs
  11. +1 −4 source/MongoDB/Configuration/Mapping/Auto/AutoMappingProfile.cs
  12. +3 −3 source/MongoDB/Configuration/Mapping/Auto/OverridableAutoMappingProfile.cs
  13. +0 −2 source/MongoDB/Configuration/Mapping/Conventions/DefaultDictionaryAdapterConvention.cs
  14. +0 −4 source/MongoDB/Linq/ExecutionBuilder.cs
  15. +6 −22 source/MongoDB/Linq/Expressions/AggregateExpression.cs
  16. +1 −6 source/MongoDB/Linq/Expressions/AggregateType.cs
  17. +1 −6 source/MongoDB/Linq/Expressions/Alias.cs
  18. +2 −10 source/MongoDB/Linq/Expressions/AliasedExpression.cs
  19. +6 −23 source/MongoDB/Linq/Expressions/CollectionExpression.cs
  20. +0 −5 source/MongoDB/Linq/Expressions/ExpressionVisitor.cs
  21. +1 −5 source/MongoDB/Linq/Expressions/FieldDeclaration.cs
  22. +7 −24 source/MongoDB/Linq/Expressions/FieldExpression.cs
  23. +0 −3 source/MongoDB/Linq/Expressions/MongoExpression.cs
  24. +1 −5 source/MongoDB/Linq/Expressions/MongoExpressionComparer.cs
  25. +26 −23 source/MongoDB/Linq/Expressions/MongoExpressionExtensions.cs
  26. +1 −6 source/MongoDB/Linq/Expressions/MongoExpressionType.cs
  27. +1 −3 source/MongoDB/Linq/Expressions/MongoExpressionVisitor.cs
  28. +4 −16 source/MongoDB/Linq/Expressions/OrderExpression.cs
  29. +1 −6 source/MongoDB/Linq/Expressions/OrderType.cs
  30. +8 −25 source/MongoDB/Linq/Expressions/ProjectionExpression.cs
  31. +0 −3 source/MongoDB/Linq/Expressions/ScalarExpression.cs
  32. +2 −7 source/MongoDB/Linq/Expressions/SelectExpression.cs
  33. +2 −11 source/MongoDB/Linq/Expressions/SubqueryExpression.cs
  34. +1 −4 source/MongoDB/Linq/IMongoQueryable.cs
  35. +0 −1 source/MongoDB/Linq/MongoQuery.cs
  36. +8 −17 source/MongoDB/Linq/MongoQueryObject.cs
  37. +9 −10 source/MongoDB/Linq/MongoQueryProvider.cs
  38. +1 −9 source/MongoDB/Linq/Translators/AggregateChecker.cs
  39. +2 −2 source/MongoDB/Linq/Translators/AggregateRewriter.cs
  40. +1 −5 source/MongoDB/Linq/Translators/DeclaredAliasGatherer.cs
  41. +16 −11 source/MongoDB/Linq/Translators/DocumentFormatter.cs
  42. +5 −13 source/MongoDB/Linq/Translators/ExpressionReplacer.cs
  43. +1 −3 source/MongoDB/Linq/Translators/FieldGatherer.cs
  44. +1 −5 source/MongoDB/Linq/Translators/FieldMapper.cs
  45. +2 −5 source/MongoDB/Linq/Translators/FieldProjector.cs
  46. +12 −8 source/MongoDB/Linq/Translators/JavascriptFormatter.cs
  47. +1 −3 source/MongoDB/Linq/Translators/MapReduceFinalizerFunctionBuilder.cs
  48. +4 −9 source/MongoDB/Linq/Translators/MapReduceMapFunctionBuilder.cs
  49. +1 −9 source/MongoDB/Linq/Translators/MapReduceReduceFunctionBuilder.cs
  50. +3 −6 source/MongoDB/Linq/Translators/MongoQueryObjectBuilder.cs
  51. +1 −4 source/MongoDB/Linq/Translators/Nominator.cs
  52. +46 −62 source/MongoDB/Linq/Translators/OrderByRewriter.cs
  53. +27 −35 source/MongoDB/Linq/Translators/ProjectionBuilder.cs
  54. +18 −22 source/MongoDB/Linq/Translators/QueryBinder.cs
  55. +1 −5 source/MongoDB/Linq/Translators/QueryDuplicator.cs
  56. +1 −4 source/MongoDB/Linq/Translators/RedundantFieldRemover.cs
  57. +5 −14 source/MongoDB/Linq/Translators/RedundantSubqueryRemover.cs
  58. +2 −9 source/MongoDB/Linq/Translators/SubqueryRemover.cs
  59. +17 −31 source/MongoDB/Linq/TypeHelper.cs
  60. +0 −1 source/MongoDB/Obsolete/Cursor.cs
  61. +1 −0 source/MongoDB/Oid.cs
  62. +0 −1 source/MongoDB/Protocol/ReplyMessage.cs
  63. +0 −1 source/MongoDB/Serialization/BsonClassMapBuilder.cs
  64. +1 −3 source/MongoDB/Serialization/Builders/DocumentBuilder.cs
  65. +1 −3 source/MongoDB/Serialization/Builders/IObjectBuilder.cs
  66. +1 −3 source/MongoDB/Serialization/Descriptors/ArrayDescriptor.cs
  67. +85 −92 source/MongoDB/Util/Inflector.cs
  68. +12 −12 source/MongoDB/Util/OidGenerator.cs
  69. +13 −22 source/MongoDB/Util/ScopedDictionary.cs
@@ -1,5 +1,6 @@
using System;
using System.Linq;
+using MongoDB.Util;
using NUnit.Framework;
namespace MongoDB.IntegrationTests
@@ -2,6 +2,7 @@
using System.Collections.Generic;
using System.Linq;
using MongoDB.Attributes;
+using MongoDB.Util;
using NUnit.Framework;
namespace MongoDB.IntegrationTests
@@ -2,6 +2,7 @@
using System.IO;
using System.Text;
using MongoDB.Bson;
+using MongoDB.Util;
using NUnit.Framework;
namespace MongoDB.UnitTests.Bson
@@ -2,6 +2,7 @@
using System.IO;
using System.Runtime.Serialization.Formatters.Binary;
using System.Xml.Serialization;
+using MongoDB.Util;
using NUnit.Framework;
namespace MongoDB.UnitTests
@@ -1,4 +1,5 @@
using System;
+using MongoDB.Util;
using NUnit.Framework;
namespace MongoDB.UnitTests
@@ -1,6 +1,7 @@
using System;
using System.Collections;
using System.Collections.Generic;
+using System.Linq;
namespace MongoDB.Bson
{
@@ -78,20 +79,22 @@ public void EndProperty(object instance, string name, object value)
/// </summary>
/// <param name = "doc">The doc.</param>
/// <returns></returns>
- private Type GetTypeForIEnumerable(Document doc)
+ private Type GetTypeForIEnumerable(IDictionary<string, object> doc)
{
if(doc.Keys.Count < 1)
return typeof(Object);
+
Type comp = null;
- foreach(var key in doc.Keys)
+
+ foreach(var test in doc.Keys.Select(key => doc[key])
+ .Select(obj => obj.GetType()))
{
- var obj = doc[key];
- var test = obj.GetType();
if(comp == null)
comp = test;
else if(comp != test)
return typeof(Object);
}
+
return comp;
}
@@ -1,5 +1,6 @@
using System.Collections;
using System.Collections.Generic;
+using System.Linq;
namespace MongoDB.Bson
{
@@ -37,10 +38,10 @@ public class BsonDocumentDescriptor : IBsonObjectDescriptor
/// </summary>
/// <param name="instance">The instance.</param>
/// <returns></returns>
- public IEnumerable<BsonProperty> GetProperties(object instance){
+ public IEnumerable<BsonProperty> GetProperties(object instance)
+ {
var document = (Document)instance;
- foreach(var key in document.Keys)
- yield return new BsonProperty(key);
+ return document.Keys.Select(key => new BsonProperty(key));
}
/// <summary>
@@ -42,9 +42,7 @@ public Document Options
{
if(_options != null)
return _options;
- var doc = _database["system.namespaces"].FindOne(new Document().Add("name", _fullName));
- if(doc == null)
- doc = new Document();
+ var doc = _database["system.namespaces"].FindOne(new Document().Add("name", _fullName)) ?? new Document();
if(doc.Contains("create"))
doc.Remove("create");
//Not sure why this is here. The python driver has it.
@@ -61,10 +61,7 @@ public void DefaultProfile(Action<AutoMappingProfileBuilder> config)
if (config == null)
throw new ArgumentNullException("config");
- var dp = _defaultProfile as AutoMappingProfile;
-
- if (dp == null)
- dp = new AutoMappingProfile();
+ var dp = _defaultProfile as AutoMappingProfile ?? new AutoMappingProfile();
config(new AutoMappingProfileBuilder(dp));
_defaultProfile = dp;
@@ -115,7 +115,7 @@ public AutoMapper(Func<Type, bool> filter)
subClassMap.Discriminator = discriminator;
else
{
- Array array = null;
+ Array array;
if(parentDiscriminator.GetType().IsArray)
array = Array.CreateInstance(typeof(object), ((Array)parentDiscriminator).Length + 1);
else
@@ -177,10 +177,7 @@ public virtual object GetDefaultValue(Type classType, MemberInfo member)
var att = member.GetCustomAttribute<MongoDefaultAttribute>(true);
if (att != null)
defaultValue = att.Value;
- if (defaultValue == null)
- defaultValue = _conventions.DefaultValueConvention.GetDefaultValue(member.GetReturnType());
-
- return defaultValue;
+ return defaultValue ?? (_conventions.DefaultValueConvention.GetDefaultValue(member.GetReturnType()));
}
/// <summary>
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
+using System.Linq;
using System.Reflection;
using MongoDB.Configuration.CollectionAdapters;
using MongoDB.Configuration.DictionaryAdapters;
@@ -57,9 +58,8 @@ public MemberInfo FindIdMember(Type classType)
/// <returns></returns>
public IEnumerable<MemberInfo> FindMembers(Type classType)
{
- foreach(var member in _profile.FindMembers(classType))
- if((bool)GetMemberOverrideValue(classType, member, o => !o.Ignore, v => v.HasValue, true))
- yield return member;
+ return _profile.FindMembers(classType)
+ .Where(member => (bool)GetMemberOverrideValue(classType, member, o => !o.Ignore, v => v.HasValue, true));
}
/// <summary>
@@ -1,8 +1,6 @@
using System;
using System.Collections;
using System.Collections.Generic;
-
-using MongoDB.Configuration.CollectionAdapters;
using MongoDB.Configuration.DictionaryAdapters;
namespace MongoDB.Configuration.Mapping.Conventions
@@ -1,10 +1,6 @@
using System;
using System.Collections.Generic;
-using System.Linq;
using System.Linq.Expressions;
-using System.Reflection;
-using System.Text;
-
using MongoDB.Linq.Expressions;
using MongoDB.Linq.Translators;
@@ -1,38 +1,22 @@
using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
using System.Linq.Expressions;
namespace MongoDB.Linq.Expressions
{
internal class AggregateExpression : MongoExpression
{
- private readonly AggregateType _aggregateType;
- private readonly Expression _argument;
- private readonly bool _distinct;
+ public AggregateType AggregateType { get; private set; }
- public AggregateType AggregateType
- {
- get { return _aggregateType; }
- }
+ public Expression Argument { get; private set; }
- public Expression Argument
- {
- get { return _argument; }
- }
-
- public bool Distinct
- {
- get { return _distinct; }
- }
+ public bool Distinct { get; private set; }
public AggregateExpression(Type type, AggregateType aggregateType, Expression argument, bool distinct)
: base(MongoExpressionType.Aggregate, type)
{
- _aggregateType = aggregateType;
- _argument = argument;
- _distinct = distinct;
+ AggregateType = aggregateType;
+ Argument = argument;
+ Distinct = distinct;
}
}
}
@@ -1,9 +1,4 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-
-namespace MongoDB.Linq.Expressions
+namespace MongoDB.Linq.Expressions
{
internal enum AggregateType
{
@@ -1,9 +1,4 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-
-namespace MongoDB.Linq.Expressions
+namespace MongoDB.Linq.Expressions
{
internal sealed class Alias
{ }
@@ -1,23 +1,15 @@
using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
namespace MongoDB.Linq.Expressions
{
internal abstract class AliasedExpression : MongoExpression
{
- private Alias _alias;
-
- public Alias Alias
- {
- get { return _alias; }
- }
+ public Alias Alias { get; private set; }
protected AliasedExpression(MongoExpressionType nodeType, Type type, Alias alias)
: base(nodeType, type)
{
- _alias = alias;
+ Alias = alias;
}
}
}
@@ -1,38 +1,21 @@
using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Linq.Expressions;
-using System.Text;
namespace MongoDB.Linq.Expressions
{
internal class CollectionExpression : AliasedExpression
{
- private readonly string _collectionName;
- private readonly IMongoDatabase _database;
- private readonly Type _documentType;
+ public string CollectionName { get; private set; }
- public string CollectionName
- {
- get { return _collectionName; }
- }
+ public IMongoDatabase Database { get; private set; }
- public IMongoDatabase Database
- {
- get { return _database; }
- }
-
- public Type DocumentType
- {
- get { return _documentType; }
- }
+ public Type DocumentType { get; private set; }
public CollectionExpression(Alias alias, IMongoDatabase database, string collectionName, Type documentType)
: base(MongoExpressionType.Collection, typeof(void), alias)
{
- _collectionName = collectionName;
- _database = database;
- _documentType = documentType;
+ CollectionName = collectionName;
+ Database = database;
+ DocumentType = documentType;
}
}
}
@@ -2,16 +2,11 @@
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq.Expressions;
-using System.Reflection;
namespace MongoDB.Linq.Expressions
{
internal abstract class ExpressionVisitor
{
- protected ExpressionVisitor()
- {
- }
-
protected virtual Expression Visit(Expression exp)
{
if (exp == null)
@@ -1,8 +1,4 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Linq.Expressions;
+using System.Linq.Expressions;
namespace MongoDB.Linq.Expressions
{
@@ -1,38 +1,21 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Linq.Expressions;
-using System.Text;
+using System.Linq.Expressions;
namespace MongoDB.Linq.Expressions
{
internal class FieldExpression : MongoExpression
{
- private readonly Alias _alias;
- private readonly Expression _expression;
- private readonly string _name;
+ public Alias Alias { get; private set; }
- public Alias Alias
- {
- get { return _alias; }
- }
+ public Expression Expression { get; private set; }
- public Expression Expression
- {
- get { return _expression; }
- }
-
- public string Name
- {
- get { return _name; }
- }
+ public string Name { get; private set; }
public FieldExpression(Expression expression, Alias alias, string name)
: base(MongoExpressionType.Field, expression.Type)
{
- _alias = alias;
- _expression = expression;
- _name = name;
+ Alias = alias;
+ Expression = expression;
+ Name = name;
}
}
}
@@ -1,7 +1,4 @@
using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
using System.Linq.Expressions;
namespace MongoDB.Linq.Expressions
Oops, something went wrong.

0 comments on commit 41b19cb

Please sign in to comment.