Esempio n. 1
0
        private static TypeConverter ConverterValueFactory(Type converterType)
        {
            var ctor = DynamicReflectionDelegateFactory.CreateDefaultConstructor <TypeConverter>(converterType);

            return(ctor.Invoke());
        }
Esempio n. 2
0
        // ctor.
        // Мы защищены от одновременного создания с помощью Lazy.ExecutionAndPublication.
        public ContractActivator(Type dboType)
        {
            if (SingleNonEmptyCtor(dboType, out ConstructorInfo? singleCtor))
            {
                IsEmptyCtor    = false;
                _ctorActivator = DynamicReflectionDelegateFactory.CreateConstructor(dboType, singleCtor);

                ConstructorArguments = CreateConstructorArguments(singleCtor);
            }
            else
            {
                // Хоть у структуры и есть пустой конструктор, нам он не подходит.
                IsEmptyCtor         = true;
                _emptyCtorActivator = DynamicReflectionDelegateFactory.CreateDefaultConstructor <object>(dboType);
            }

            InitializeStreamingMethods(dboType, out OnDeserializingHandle, out OnDeserializedHandle);

            //if (!anonymousType)
            //{
            //    // Тип может быть readonly структурой, определить можно только перебором всех свойств и полей.
            //    bool isReadonlyStruct = GetIsReadonlyStruct(dboType);

            //    if (isReadonlyStruct)
            //    {
            //        // Хоть у структуры и есть пустой конструктор, нам он не подходит.
            //        IsEmptyCtor = false;

            //        ConstructorInfo[] ctors = dboType.GetConstructors();
            //        Debug.Assert(ctors.Length > 0, "У типа должны быть открытые конструкторы");

            //        if (ctors.Length != 0)
            //        {
            //            ConstructorInfo ctor = ctors[0];
            //            _ctorActivator = DynamicReflectionDelegateFactory.CreateConstructor(dboType, ctor);

            //            ConstructorArguments = CreateConstructorArguments(ctor);
            //        }
            //        else
            //            throw new MicroOrmException("Не найден открытый конструктор");

            //        InitializeStreamingMethods(dboType, out OnDeserializingHandle, out OnDeserializedHandle);
            //    }
            //    else
            //    // Не анонимный class
            //    {

            //    }
            //}
            //else
            {
                //_ctorActivator = DynamicReflectionDelegateFactory.CreateAnonimousConstructor(dboType);

                //// поля у анонимных типов не рассматриваются.
                //// берем только свойства по умолчанию.
                //PropertyInfo[] properties = dboType.GetProperties(BindingFlags.Public | BindingFlags.Instance);

                //// порядок полей такой же как у конструктора.
                //ConstructorArguments = CreateConstructorArguments(properties);
            }
            Contract = new TypeContract(dboType);
        }