예제 #1
0
        private DefaultTypeMapper()
        {
            // NumericTypesWithNullable, NodaTimeTypes, string, DateTime, DateTime?
            var typeRegistrations = Enumerable.Empty <TypeRegistration>()
                                    .Concat(TypeCache.NumericTypesWithNullable.TypeSource.TypeRegistrations)
                                    .Concat(TypeCache.NodaTimeTypes.Value.TypeSource.TypeRegistrations)
                                    .Concat(new[]
            {
                new TypeRegistration(typeof(string), "string"),
                new TypeRegistration(typeof(bool), "bool"),
                new TypeRegistration(typeof(bool?), "bool?"),
                new TypeRegistration(typeof(DateTime), "DateTime"),
                new TypeRegistration(typeof(DateTime?), "DateTime?"),
            })
                                    .ToArray();

            // Array types for each registration
            var arrayTypes = typeRegistrations
                             .Where(registration => !registration.Type.IsArray && registration.Alias != null)
                             .Select(registration => new TypeRegistration(registration.Type.MakeArrayType(), $"{registration.Alias}[]"));

            typeRegistrations = typeRegistrations
                                .Concat(arrayTypes)
                                .ToArray();

            _typeCache = TypeCache.Create(
                AssemblySource.Default,
                TypeSource.Empty.With(typeRegistrations: typeRegistrations));
        }
        public ReflectionDynamicObject(object obj)
        {
            _originalObject = obj ?? throw new ArgumentNullException(nameof(obj));

            var type = obj.GetType();

            _typeCache = s_cache.GetOrAdd(type, t => TypeCache.Create(t));
        }
예제 #3
0
        public ReflectionDynamicObject(Type type)
        {
            if (type == null)
            {
                throw new ArgumentNullException(nameof(type));
            }

            _typeCache = s_cache.GetOrAdd(type, t => TypeCache.Create(t));
        }
        public ReflectionDynamicObject(object obj)
        {
            _originalObject = obj ?? throw new ArgumentNullException(nameof(obj));

            var type = obj.GetType();

            if (!_cache.TryGetValue(type, out var typeCache))
            {
                typeCache    = TypeCache.Create(type);
                _cache[type] = typeCache;
            }

            _typeCache = typeCache;
        }
        public ReflectionDynamicObject(Type type)
        {
            if (type == null)
            {
                throw new ArgumentNullException(nameof(type));
            }

            if (!_cache.TryGetValue(type, out var typeCache))
            {
                typeCache    = TypeCache.Create(type);
                _cache[type] = typeCache;
            }

            _typeCache = typeCache;
        }