Ejemplo n.º 1
0
        private TClass Deserialize(BsonDeserializationContext context, BsonDeserializationArgs args)
        {
            CheckItemMap();
            var bsonReader = context.Reader;

            if (bsonReader.GetCurrentBsonType() == BsonType.Null)
            {
                bsonReader.ReadNull();
                return(null);
            }
            else
            {
                var idref = dbRef.Deserialize(context, args);

                if (idref == null || idref.Id == null)
                {
                    return(null);
                }

                TClass obj = ReflectionTools.CreateInstance <TClass>();
                itemIdMap.Setter.Invoke(obj, BsonTypeMapper.MapToDotNetValue(idref.Id));

                //TODO: Buscar na collection correta a instancia completa.
                return(obj);
            }
        }
Ejemplo n.º 2
0
 private static IServiceCollection RegisterService(IServiceCollection services, IEnumerable <Type> types)
 {
     foreach (var type in types)
     {
         IServiceManager manager = ReflectionTools.CreateInstance(type) as IServiceManager;
         services = manager.RegisterService(services);
     }
     return(services);
 }
Ejemplo n.º 3
0
        public void CanCreateInstanceWithNonPublicDefaultConstructor()
        {
            var x = ReflectionTools.CreateInstance <TypeWithPrivateDefaultCtor>();
            var y = ReflectionTools.CreateInstance <TypeWithProtectedDefaultCtor>();
            var z = ReflectionTools.CreateInstance <TypeWithInternalDefaultCtor>();

            Assert.IsNotNull(x);
            Assert.IsNotNull(y);
            Assert.IsNotNull(z);
        }
Ejemplo n.º 4
0
        protected override void OnModelCreating(ModelBuilder builder)
        {
            string             assemblyPath = string.Empty;
            IEnumerable <Type> types        = null;

            if (MapperAssembly != null && MapperAssembly.Length > 0)
            {
                types = ReflectionTools.GetSubTypes <EntityTypeCofiguration>(MapperAssembly);
            }
            if (types == null)
            {
                types = ReflectionTools.GetSubTypes <EntityTypeCofiguration>();
            }
            foreach (var type in types)
            {
                var instance = ReflectionTools.CreateInstance(type) as EntityTypeCofiguration;
                instance.ModelConfigurate(builder);
            }
        }
Ejemplo n.º 5
0
        object IBsonSerializer.Deserialize(BsonDeserializationContext context, BsonDeserializationArgs args)
        {
            var bsonReader = context.Reader;

            if (bsonReader.GetCurrentBsonType() == BsonType.Null)
            {
                bsonReader.ReadNull();
                return(null);
            }
            else
            {
                var value = (TMember)this.serializer.Deserialize(context, args);

                var obj = ReflectionTools.CreateInstance <TClass>();


                prop.SetValue(obj, value);
                return(obj);
            }
        }
Ejemplo n.º 6
0
        private TClass Deserialize(BsonDeserializationContext context, BsonDeserializationArgs args)
        {
            CheckItemMap();
            var reader      = context.Reader;
            var bsonType    = reader.CurrentBsonType;
            var elementType = typeof(MongoDBRef);

            switch (bsonType)
            {
            case BsonType.Null:
                reader.ReadNull();
                return(null);

            case BsonType.Array:
                reader.ReadStartArray();
                var lista_objs = (IList)Activator.CreateInstance(typeof(List <>).MakeGenericType(itemType));

                //var serializer = BsonSerializer.LookupSerializer(elementType);
                while (reader.ReadBsonType() != BsonType.EndOfDocument)
                {
                    var mref = BsonSerializer.Deserialize(reader, elementType) as MongoDBRef;
                    if (mref == null)
                    {
                        lista_objs.Add(null);
                    }
                    else
                    {
                        var obj = ReflectionTools.CreateInstance(itemType);
                        itemIdMap.Setter.Invoke(obj, BsonTypeMapper.MapToDotNetValue(mref.Id));
                        lista_objs.Add(obj);
                    }
                }
                reader.ReadEndArray();
                return((TClass)(object)lista_objs);

            default:

                var message = string.Format("Can't deserialize a {0} from BsonType {1}.", elementType.FullName, bsonType);
                throw new ApplicationException(message);
            }
        }
Ejemplo n.º 7
0
 public void CanCreateStructInstance()
 {
     MyStruct m = ReflectionTools.CreateInstance <MyStruct>();
 }