Ejemplo n.º 1
0
        /// <summary>
        /// 将栈顶的对象从 <paramref name="inputType"/> 转换为 <paramref name="outputType"/>。
        /// </summary>
        /// <param name="il">IL 指令生成器。</param>
        /// <param name="inputType">要转换的对象的类型。</param>
        /// <param name="outputType">要将输入对象转换到的类型。</param>
        /// <param name="isChecked">是否执行溢出检查。</param>
        /// <exception cref="ArgumentNullException"><paramref name="il"/> 为 <c>null</c>。</exception>
        /// <exception cref="ArgumentNullException"><paramref name="inputType"/> 为 <c>null</c>。</exception>
        /// <exception cref="ArgumentNullException"><paramref name="outputType"/> 为 <c>null</c>。</exception>
        public static void EmitConversion(this ILGenerator il, Type inputType, Type outputType, bool isChecked)
        {
            if (il == null)
            {
                throw CommonExceptions.ArgumentNull("il");
            }
            if (inputType == null)
            {
                throw CommonExceptions.ArgumentNull("inputType");
            }
            if (outputType == null)
            {
                throw CommonExceptions.ArgumentNull("outputType");
            }
            Contract.EndContractBlock();
            Conversion conversion = ConversionFactory.GetConversion(inputType, outputType);

            if (conversion == null)
            {
                throw CommonExceptions.InvalidCast(inputType, outputType);
            }
            if (conversion is FromNullableConversion)
            {
                il.EmitGetAddress(inputType);
            }
            conversion.Emit(il, inputType, outputType, isChecked);
        }
Ejemplo n.º 2
0
 /// <summary>
 /// 获取将对象从 <paramref name="inputType"/> 类型转换为 <paramref name="outputType"/> 类型的转换器。
 /// </summary>
 /// <param name="inputType">要转换的对象的类型。</param>
 /// <param name="outputType">要将输入对象转换到的类型。</param>
 /// <param name="buildGeneric"><c>true</c> 表示需要生成泛型类型转换委托;<c>false</c>
 /// 表示需要生成非泛型的类型转换委托。</param>
 /// <returns>将对象从 <paramref name="inputType"/> 类型转换为 <paramref name="outputType"/> 类型的转换器。
 /// 如果不存在则为 <c>null</c>。</returns>
 private static Converter GetConverterInternal(Type inputType, Type outputType, bool buildGeneric)
 {
     Contract.Requires(inputType != null && outputType != null);
     return(converterCache.GetOrAdd(new Tuple <Type, Type>(inputType, outputType), types =>
     {
         var conversion = ConversionFactory.GetConversion(inputType, outputType);
         if (conversion == null)
         {
             return null;
         }
         var converter = new Converter();
         var dlgConversion = conversion as DelegateConversion;
         if (dlgConversion != null)
         {
             converter.GenericConverter = dlgConversion.Converter;
             if (buildGeneric)
             {
                 return converter;
             }
         }
         if (conversion.ConversionType == ConversionType.Identity ||
             conversion.ConversionType == ConversionType.ImplicitReference ||
             conversion.ConversionType == ConversionType.Box ||
             conversion.ConversionType == ConversionType.Unbox)
         {
             converter.ObjectConverter = defaultObjectConverter;
             if (!buildGeneric)
             {
                 return converter;
             }
         }
         if (conversion.ConversionType == ConversionType.ExplicitReference)
         {
             // 对于显式引用转换,只需要检查一下实际类型是否是 outputType 即可。
             converter.ObjectConverter = obj =>
             {
                 if (obj != null && !outputType.IsInstanceOfType(obj))
                 {
                     throw CommonExceptions.InvalidCast(obj.GetType(), outputType);
                 }
                 return obj;
             };
             if (!buildGeneric)
             {
                 return converter;
             }
         }
         var dlg = BuildConverter(conversion, inputType, outputType, false, buildGeneric);
         if (buildGeneric)
         {
             converter.GenericConverter = dlg;
         }
         else
         {
             converter.ObjectConverter = (Converter <object, object>)dlg;
         }
         return converter;
     }));
 }
Ejemplo n.º 3
0
        public ConversionRequest(string type, string from, string to, decimal value)
        {
            _from  = from;
            _to    = to;
            _value = value;

            _conversion = ConversionFactory.GetConversionOfType(type);
        }
Ejemplo n.º 4
0
 /// <summary>
 /// 添加将对象从 <typeparamref name="TInput"/> 类型转换为 <typeparamref name="TOutput"/> 类型的转换器。
 /// </summary>
 /// <param name="converter">将对象从 <typeparamref name="TInput"/> 类型转换为
 /// <typeparamref name="TOutput"/> 类型的转换器。</param>
 /// <exception cref="ArgumentNullException"><paramref name="converter"/> 为 <c>null</c>。</exception>
 /// <remarks><paramref name="converter"/> 不会覆盖预定义的隐式、显式类型转换和用户自定义的类型转换。
 /// 对于相同输入/输出类型的 <paramref name="converter"/>,后设置的会覆盖先设置的,以及任何
 /// <see cref="IConverterProvider"/> 提供的类型转换方法。</remarks>
 public static void AddConverter <TInput, TOutput>(Converter <TInput, TOutput> converter)
 {
     if (converter == null)
     {
         throw CommonExceptions.ArgumentNull("converter");
     }
     Contract.EndContractBlock();
     ConversionFactory.AddConverterProvider(new ConverterProvider(converter, typeof(TInput), typeof(TOutput)));
 }
Ejemplo n.º 5
0
        /// <summary>
        /// 确定当前 <see cref="Type"/> 的实例是否可以从 <paramref name="fromType"/> 的实例隐式类型转换得到。
        /// 这里仅考虑预定义的隐式类型转换,不考虑由 <c>implicit</c> 运算符指定的转换。
        /// </summary>
        /// <param name="type">当前类型。</param>
        /// <param name="fromType">要判断能否隐式类型转换得到的类型。</param>
        /// <returns>如果当前 <see cref="Type"/> 的实例是否可以从 <paramref name="fromType"/>
        /// 的实例隐式类型转换得到,则为 <c>true</c>;否则为 <c>false</c>。</returns>
        /// <exception cref="ArgumentNullException"><paramref name="type"/> 为 <c>null</c>。</exception>
        /// <exception cref="ArgumentNullException"><paramref name="fromType"/> 为 <c>null</c>。</exception>
        /// <remarks>
        /// 判断类型间能否进行隐式类型转换的算法来自于 《CSharp Language Specification》v5.0
        /// 的第 6.1 节。</remarks>
        /// <example>
        /// 下面是 <see cref="IsImplicitFrom"/> 方法与 <see cref="Type.IsAssignableFrom"/> 方法的一些对比。
        /// <code>
        /// Console.WriteLine(typeof(object).IsAssignableFrom(typeof(uint))); // True
        /// Console.WriteLine(typeof(object).IsImplicitFrom(typeof(uint))); // True
        /// Console.WriteLine(typeof(int).IsAssignableFrom(typeof(short))); // False
        /// Console.WriteLine(typeof(int).IsImplicitFrom(typeof(short))); // True
        /// Console.WriteLine(typeof(long?).IsAssignableFrom(typeof(int?))); // False
        /// Console.WriteLine(typeof(long?).IsImplicitFrom(typeof(int?))); // True
        /// </code>
        /// </example>
        /// <seealso href="http://www.cnblogs.com/cyjb/archive/p/TypeAssignableFrom.html">
        /// 《C# 判断类型间能否隐式或强制类型转换,以及开放泛型类型转换》</seealso>
        public static bool IsImplicitFrom(this Type type, Type fromType)
        {
            CommonExceptions.CheckArgumentNull(type, nameof(type));
            CommonExceptions.CheckArgumentNull(fromType, nameof(fromType));
            Contract.EndContractBlock();
            var conversion = ConversionFactory.GetPreDefinedConversion(fromType, type);

            return(conversion != null && conversion.ConversionType.IsImplicit());
        }
Ejemplo n.º 6
0
        protected override async Task OnInitializedAsync()
        {
            if (MatterLookupList.Count() == 0)
            {
                MatterLookupList = ConversionFactory.ConvertToDomainModel(await _api.GetMatterLookupAsync());
            }

            await base.OnInitializedAsync();
        }
Ejemplo n.º 7
0
        /// <summary>
        /// 确定当前 <see cref="Type"/> 的实例是否可以从 <paramref name="fromType"/> 的实例显式类型转换得到。
        /// 这里仅考虑预定义的显式类型转换,不考虑由 <c>implicit</c> 运算符和 <c>explicit</c> 运算符指定的转换。
        /// </summary>
        /// <param name="type">当前类型。</param>
        /// <param name="fromType">要判断能否显式类型转换得到的类型。</param>
        /// <returns>如果当前 <see cref="Type"/> 的实例是否可以从 <paramref name="fromType"/>
        /// 的实例显式类型转换得到,则为 <c>true</c>;否则为 <c>false</c>。</returns>
        /// <exception cref="ArgumentNullException"><paramref name="type"/> 为 <c>null</c>。</exception>
        /// <exception cref="ArgumentNullException"><paramref name="fromType"/> 为 <c>null</c>。</exception>
        /// <remarks>
        /// 判断类型间能否进行显式类型转换的算法来自于 《CSharp Language Specification》v5.0
        /// 的第 6.1 节。</remarks>
        /// <example>
        /// 下面是 <see cref="IsExplicitFrom"/> 方法的一些实例。
        /// <code>
        /// Console.WriteLine(typeof(uint).IsExplicitFrom(typeof(object))); // True
        /// Console.WriteLine(typeof(short).IsExplicitFrom(typeof(int))); // True
        /// Console.WriteLine(typeof(int).IsExplicitFrom(typeof(long?))); // True
        /// </code>
        /// </example>
        /// <seealso href="http://www.cnblogs.com/cyjb/archive/p/TypeAssignableFrom.html">
        /// 《C# 判断类型间能否隐式或强制类型转换,以及开放泛型类型转换》</seealso>
        public static bool IsExplicitFrom(this Type type, Type fromType)
        {
            CommonExceptions.CheckArgumentNull(type, "type");
            CommonExceptions.CheckArgumentNull(fromType, "fromType");
            Contract.EndContractBlock();
            Conversion conversion = ConversionFactory.GetPreDefinedConversion(fromType, type);

            return(conversion != null && conversion.ConversionType != ConversionType.None);
        }
Ejemplo n.º 8
0
 /// <summary>
 /// 返回 <paramref name="inputType"/> 类型和 <paramref name="outputType"/> 类型之间的标准转换类型。
 /// </summary>
 /// <param name="inputType">要转换的对象的类型。</param>
 /// <param name="outputType">要将输入对象转换到的类型。</param>
 /// <returns><paramref name="inputType"/> 类型和 <paramref name="outputType"/> 类型之间的标准转换类型。</returns>
 /// <remarks><para>这里标准转换指标准显式转换,包含了所有预定义隐式转换和预定义显式转换的子集,
 /// 该子集是预定义隐式转换反向的转换。也就是说,如果存在从 A 类型到 B 类型的预定义隐式转换,
 /// 那么 A 类型和 B 类型之间存在标准转换(A 到 B 或 B 到 A)。</para>
 /// <para>如果不存在标准类型转换,则总是返回 <see cref="ConversionType.None"/>,即使存在其它的类型转换。</para>
 /// </remarks>
 internal static ConversionType GetStandardConversion(Type inputType, Type outputType)
 {
     Contract.Requires(inputType != null && outputType != null);
     if (inputType == typeof(void) || outputType == typeof(void))
     {
         return(ConversionType.None);
     }
     return(ConversionFactory.GetStandardConversion(inputType, outputType));
 }
        protected override async Task OnInitializedAsync()
        {
            if (DataCollectionLookupList.Count() == 0)
            {
                DataCollectionLookupList = ConversionFactory.ConvertToDomainModelForLookup(await _api.GetDataCollectionsAsync());
            }

            await base.OnInitializedAsync();
        }
        public async Task <List <IPowerShellModule> > GetModules()
        {
            var myTask = Task.Factory.StartNew(() =>
                                               ExplorerExecutionHelper.ExecuteCommand <PSModuleInfo>("Get-Module -ListAvailable")
                                               );

            var result = await myTask;

            return(ConversionFactory.Convert(result));
        }
Ejemplo n.º 11
0
 /// <summary>
 /// 添加指定的类型转换器提供者。
 /// </summary>
 /// <param name="provider">要添加的类型转换器提供者。</param>
 /// <exception cref="ArgumentNullException"><paramref name="provider"/> 为 <c>null</c>。</exception>
 /// <exception cref="ArgumentNullException"><paramref name="provider"/> 的源类型为 <c>null</c>。</exception>
 /// <remarks><paramref name="provider"/> 提供的类型转换方法不会覆盖预定义的隐式、显式类型转换和用户自定义的类型转换,
 /// 以及任何通过 <see cref="AddConverter{TInput, TOutput}"/> 方法设置的类型转换方法。
 /// 对于相同源类型的 <see cref="IConverterProvider"/>,<see cref="IConverterProvider.GetConverterTo"/>
 /// 方法提供的类型转换方法优先级更高,且后设置的优先级更高。</remarks>
 public static void AddConverterProvider(IConverterProvider provider)
 {
     CommonExceptions.CheckArgumentNull(provider, nameof(provider));
     if (provider.OriginType == null)
     {
         throw CommonExceptions.ArgumentNull(nameof(provider));
     }
     Contract.EndContractBlock();
     ConversionFactory.AddConverterProvider(provider);
 }
        public async Task <List <IPowerShellCommand> > GetCommands()
        {
            var myTask = Task.Factory.StartNew(() =>
                                               ExplorerExecutionHelper.ExecuteCommand <CommandInfo>("Get-Command")
                                               );

            var result = await myTask;

            return(ConversionFactory.Convert(result));
        }
        private async Task DataFieldPageNumberChanged(int changedPageNumber)
        {
            ViewModel.DataFieldLoading    = true;
            ViewModel.DataFieldPageNumber = changedPageNumber;

            var dataFieldDto = await _api.GetDataCollectionFieldsAsync(ViewModel.DataFieldPageNumber, ViewModel.DataFieldPageSize, ViewModel.SelectedDataCollection);

            ViewModel.DataFieldPagedData = new Page <DataFieldViewModel>(dataFieldDto.PageMetaDataDto.PageNumber, dataFieldDto.PageMetaDataDto.PageSize,
                                                                         dataFieldDto.PageMetaDataDto.PageCount, dataFieldDto.PageMetaDataDto.RecordCount,
                                                                         ConversionFactory.ConvertToDomainModel(dataFieldDto));
            ViewModel.DataFieldLoading = false;
        }
        public async Task AddNewDocument()
        {
            if (ViewModel.MatterLookupList == null)
            {
                ViewModel.MatterLookupList = ConversionFactory.ConvertToDomainModel(await _api.GetMatterLookupAsync());
            }

            ViewModel.AddEditViewModel = new DocumentAddEditViewModel();
            documentEditContext        = new EditContext(ViewModel.AddEditViewModel);

            ViewModel.ShowNewDocumentCard = !ViewModel.ShowNewDocumentCard;
        }
        private async Task DataCollectionPageNumberChanged(int changedPageNumber)
        {
            ViewModel.DataCollectionLoading    = true;
            ViewModel.DataCollectionPageNumber = changedPageNumber;

            var dataCollectionsDto = await _api.GetDataCollectionsAsync(ViewModel.DataCollectionPageNumber, ViewModel.DataCollectionPageSize, ViewModel.FilterByMatterType);

            ViewModel.DataCollectionPagedData = new Page <DataCollectionViewModel>(dataCollectionsDto.PageMetaDataDto.PageNumber, dataCollectionsDto.PageMetaDataDto.PageSize,
                                                                                   dataCollectionsDto.PageMetaDataDto.PageCount, dataCollectionsDto.PageMetaDataDto.RecordCount,
                                                                                   ConversionFactory.ConvertToDomainModel(dataCollectionsDto));
            ViewModel.DataCollectionLoading = false;
        }
        private async Task PageNumberChanged(int changedPageNumber)
        {
            ViewModel.Loading    = true;
            ViewModel.PageNumber = changedPageNumber;

            var resthooksDto = await _api.GetResthooksAsync(ViewModel.PageNumber, ViewModel.PageSize);

            ViewModel.ResthookPagedData = new Page <ResthookViewModel>(resthooksDto.PageMetaDataDto.PageNumber, resthooksDto.PageMetaDataDto.PageSize,
                                                                       resthooksDto.PageMetaDataDto.PageCount, resthooksDto.PageMetaDataDto.RecordCount,
                                                                       ConversionFactory.ConvertToDomainModel(resthooksDto));
            ViewModel.Loading = false;
        }
Ejemplo n.º 17
0
 /// <summary>
 /// 添加指定的类型转换器提供者。
 /// </summary>
 /// <param name="provider">要添加的类型转换器提供者。</param>
 /// <exception cref="ArgumentNullException"><paramref name="provider"/> 为 <c>null</c>。</exception>
 /// <exception cref="ArgumentNullException"><paramref name="provider"/> 的源类型为 <c>null</c>。</exception>
 /// <remarks><paramref name="provider"/> 提供的类型转换方法不会覆盖预定义的隐式、显式类型转换和用户自定义的类型转换,
 /// 以及任何通过 <see cref="AddConverter{TInput, TOutput}"/> 方法设置的类型转换方法。
 /// 对于相同源类型的 <see cref="IConverterProvider"/>,<see cref="IConverterProvider.GetConverterTo"/>
 /// 方法提供的类型转换方法优先级更高,且后设置的优先级更高。</remarks>
 public static void AddConverterProvider(IConverterProvider provider)
 {
     if (provider == null)
     {
         throw CommonExceptions.ArgumentNull("provider");
     }
     if (provider.OriginType == null)
     {
         throw CommonExceptions.ArgumentNull("provider.OriginType");
     }
     Contract.EndContractBlock();
     ConversionFactory.AddConverterProvider(provider);
 }
        private async Task PageNumberChanged(int changedPageNumber)
        {
            ViewModel.Loading = true;
            ViewModel.EnableMultipleDelete = false;
            ViewModel.PageNumber           = changedPageNumber;

            var documentsDto = await _api.GetDocumentsAsync(ViewModel.PageNumber, ViewModel.PageSize, ViewModel.FilterByMatter);

            ViewModel.DocumentPagedData = new Page <DocumentViewModel>(documentsDto.PageMetaDataDto.PageNumber, documentsDto.PageMetaDataDto.PageSize,
                                                                       documentsDto.PageMetaDataDto.PageCount, documentsDto.PageMetaDataDto.RecordCount,
                                                                       ConversionFactory.ConvertToDomainModel(documentsDto));
            ViewModel.Loading = false;
        }
Ejemplo n.º 19
0
        /// <summary>
        /// 确定当前 <see cref="Type"/> 的实例是否可以从 <paramref name="fromType"/> 的实例显式类型转换得到。
        /// 这里仅考虑预定义的显式类型转换,不考虑由 <c>implicit</c> 运算符和 <c>explicit</c> 运算符指定的转换。
        /// </summary>
        /// <param name="type">当前类型。</param>
        /// <param name="fromType">要判断能否显式类型转换得到的类型。</param>
        /// <returns>如果当前 <see cref="Type"/> 的实例是否可以从 <paramref name="fromType"/>
        /// 的实例显式类型转换得到,则为 <c>true</c>;否则为 <c>false</c>。</returns>
        /// <exception cref="ArgumentNullException"><paramref name="type"/> 为 <c>null</c>。</exception>
        /// <exception cref="ArgumentNullException"><paramref name="fromType"/> 为 <c>null</c>。</exception>
        /// <remarks>
        /// 判断类型间能否进行显式类型转换的算法来自于 《CSharp Language Specification》v5.0
        /// 的第 6.1 节。</remarks>
        /// <example>
        /// 下面是 <see cref="IsImplicitFrom"/> 方法的一些实例。
        /// <code>
        /// Console.WriteLine(typeof(uint).IsExplicitFrom(typeof(object))); // True
        /// Console.WriteLine(typeof(short).IsExplicitFrom(typeof(int))); // True
        /// Console.WriteLine(typeof(int).IsExplicitFrom(typeof(long?))); // True
        /// </code>
        /// </example>
        /// <seealso href="http://www.cnblogs.com/cyjb/archive/p/TypeAssignableFrom.html">
        /// 《C# 判断类型间能否隐式或强制类型转换,以及开放泛型类型转换》</seealso>
        public static bool IsExplicitFrom(this Type type, Type fromType)
        {
            if (type == null)
            {
                throw CommonExceptions.ArgumentNull("type");
            }
            if (fromType == null)
            {
                throw CommonExceptions.ArgumentNull("otherType");
            }
            Contract.EndContractBlock();
            Conversion conversion = ConversionFactory.GetPreDefinedConversion(fromType, type);

            return(conversion != null && conversion.ConversionType != ConversionType.None);
        }
Ejemplo n.º 20
0
        /// <summary>
        /// 获取转换类型的指令生成器,能够将栈顶的对象从 <paramref name="inputType"/> 转换为
        /// <paramref name="outputType"/>。
        /// </summary>
        /// <param name="il">IL 指令生成器。</param>
        /// <param name="inputType">要转换的对象的类型。</param>
        /// <param name="outputType">要将输入对象转换到的类型。</param>
        /// <param name="conversionType">类型转换类型的限制。</param>
        /// <returns>类型转换的指令生成器,如果不能进行类型转换则返回 <c>null</c>。</returns>
        internal static Converter GetConversion(this ILGenerator il, Type inputType, Type outputType,
                                                ConversionType conversionType)
        {
            Contract.Requires(il != null && inputType != null && outputType != null);
            Contract.Requires(conversionType == ConversionType.Implicit ||
                              conversionType == ConversionType.Explicit ||
                              conversionType == ConversionType.UserDefined);
            Conversion conversion = conversionType == ConversionType.UserDefined ?
                                    ConversionFactory.GetConversion(inputType, outputType) :
                                    ConversionFactory.GetPreDefinedConversion(inputType, outputType);

            if (conversion == null || conversion.ConversionType > conversionType)
            {
                return(null);
            }
            return(new Converter(conversion, il, inputType, outputType));
        }
Ejemplo n.º 21
0
        /// <summary>
        /// 获取将对象从 <typeparamref name="TInput"/> 类型转换为 <typeparamref name="TOutput"/> 类型的转换器。
        /// </summary>
        /// <typeparam name="TInput">输入对象的类型。</typeparam>
        /// <typeparam name="TOutput">输出对象的类型。</typeparam>
        /// <returns>将对象从 <typeparamref name="TInput"/> 类型转换为 <typeparamref name="TOutput"/> 类型的转换器。
        /// 如果不存在则为 <c>null</c>。</returns>
        /// <overloads>
        /// <summary>
        /// 获取将对象从一种类型转换为另一种类型的转换器。
        /// </summary>
        /// </overloads>
        public static Converter <TInput, TOutput> GetConverter <TInput, TOutput>()
        {
            var inputType  = typeof(TInput);
            var outputType = typeof(TOutput);
            var converter  = GetConverterInternal(inputType, outputType, true);

            if (converter == null)
            {
                return(null);
            }
            if (converter.GenericConverter == null)
            {
                converter.GenericConverter = BuildConverter(ConversionFactory.GetConversion(inputType, outputType),
                                                            inputType, outputType, false, true);
            }
            return(converter.GenericConverter as Converter <TInput, TOutput>);
        }
        public async Task <IPowerShellCommandMetadata> GetCommandMetadata(IPowerShellCommand command)
        {
            var script = string.Format("New-object System.Management.Automation.CommandMetaData -ArgumentList (Get-Command {0})", command.Name);

            var myTask = Task.Factory.StartNew(() =>
                                               ExplorerExecutionHelper.ExecuteCommand <CommandMetadata>(script)
                                               );

            var result = await myTask;
            var items  = ConversionFactory.Convert(result);

            if (items.Count > 0)
            {
                return(items[0]);
            }

            return(new PowerShellCommandMetadata());
        }
Ejemplo n.º 23
0
        /// <summary>
        /// 返回 <paramref name="types"/> 中能够被其它所有类型包含的类型。
        /// </summary>
        /// <param name="types">类型集合。</param>
        /// <returns><paramref name="types"/> 中能够被其它所有类型包含的类型,如果不存在则为 <c>null</c>。</returns>
        /// <exception cref="ArgumentNullException"><paramref name="types"/> 为 <c>null</c>。</exception>
        /// <remarks>若 A 类型可以隐式类型转换(指预定义的类型转换)为 B 类型,那么就称 A 被 B 包含,而 B 包含 A。</remarks>
        public static Type GetEncompassedType(IEnumerable <Type> types)
        {
            if (types == null)
            {
                throw CommonExceptions.ArgumentNull("types");
            }
            Contract.EndContractBlock();
            Type encompassedType = null;

            foreach (Type type in types)
            {
                if (type == null)
                {
                    continue;
                }
                if (encompassedType == null)
                {
                    encompassedType = type;
                }
                else if (encompassedType != type)
                {
                    // 这里剔除 void 类型,但若 types 全部是 void,能够使得结果是 void。
                    if (encompassedType == typeof(void))
                    {
                        encompassedType = type;
                    }
                    else if (type != typeof(void))
                    {
                        ConversionType convType = ConversionFactory.GetStandardConversion(encompassedType, type);
                        if (convType == ConversionType.None)
                        {
                            return(null);
                        }
                        if (convType.IsExplicit())
                        {
                            encompassedType = type;
                        }
                    }
                }
            }
            return(encompassedType);
        }
Ejemplo n.º 24
0
        public async Task SearchFilenotes(string searchString)
        {
            if (searchString.Length > 2)
            {
                ViewModel.Loading = true;
                ViewModel.EnableMultipleDelete = false;
                ViewModel.PageNumber           = 1;

                var filenotesDto = await _api.SearchFilenotesAsync(searchString, ViewModel.PageSize);

                ViewModel.FilenotePagedData = new Page <FilenoteViewModel>(filenotesDto.PageMetaDataDto.PageNumber, filenotesDto.PageMetaDataDto.PageSize,
                                                                           filenotesDto.PageMetaDataDto.PageCount, filenotesDto.PageMetaDataDto.RecordCount,
                                                                           ConversionFactory.ConvertToDomainModel(filenotesDto));
                ViewModel.Loading = false;
            }
            else
            {
                await PageNumberChanged(1);
            }
        }
Ejemplo n.º 25
0
        /// <summary>
        /// 获取将对象从 <paramref name="inputType"/> 类型转换为 <paramref name="outputType"/> 类型的转换器。
        /// </summary>
        /// <param name="inputType">要转换的对象的类型。</param>
        /// <param name="outputType">要将输入对象转换到的类型。</param>
        /// <returns>将对象从 <paramref name="inputType"/> 类型转换为 <paramref name="outputType"/> 类型的转换器。
        /// 如果不存在则为 <c>null</c>。</returns>
        /// <remarks>尽可能使用泛型方法 <see cref="GetConverter{TInput,TOutput}"/>,这样可以避免额外的类型转换。</remarks>
        /// <exception cref="ArgumentNullException"><paramref name="inputType"/> 为 <c>null</c>。</exception>
        /// <exception cref="ArgumentNullException"><paramref name="outputType"/> 为 <c>null</c>。</exception>
        public static Converter <object, object> GetConverter(Type inputType, Type outputType)
        {
            if (inputType == null)
            {
                throw CommonExceptions.ArgumentNull("inputType");
            }
            if (outputType == null)
            {
                throw CommonExceptions.ArgumentNull("outputType");
            }
            Contract.EndContractBlock();
            Converter converter = GetConverterInternal(inputType, outputType, false);

            if (converter == null)
            {
                return(null);
            }
            return(converter.ObjectConverter ?? (converter.ObjectConverter = (Converter <object, object>)BuildConverter(
                                                     ConversionFactory.GetConversion(inputType, outputType), inputType, outputType, false, false)));
        }
Ejemplo n.º 26
0
 public static bool CanChangeType(Type inputType, Type outputType)
 {
     if (inputType == null)
     {
         throw CommonExceptions.ArgumentNull("inputType");
     }
     if (outputType == null)
     {
         throw CommonExceptions.ArgumentNull("outputType");
     }
     Contract.EndContractBlock();
     try
     {
         return(ConversionFactory.GetConversion(inputType, outputType) != null);
     }
     catch
     {
         return(false);
     }
 }
Ejemplo n.º 27
0
        /// <summary>
        /// 将栈顶的对象从 <paramref name="inputType"/> 转换为 <paramref name="outputType"/>。
        /// </summary>
        /// <param name="il">IL 指令生成器。</param>
        /// <param name="inputType">要转换的对象的类型。</param>
        /// <param name="outputType">要将输入对象转换到的类型。</param>
        /// <param name="isChecked">是否执行溢出检查。</param>
        /// <param name="conversionType">类型转换类型的限制。</param>
        internal static void EmitConversion(this ILGenerator il, Type inputType, Type outputType, bool isChecked,
                                            ConversionType conversionType)
        {
            Contract.Requires(il != null && inputType != null && outputType != null);
            Contract.Requires(conversionType == ConversionType.Implicit ||
                              conversionType == ConversionType.Explicit ||
                              conversionType == ConversionType.UserDefined);
            Conversion conversion = conversionType == ConversionType.UserDefined ?
                                    ConversionFactory.GetConversion(inputType, outputType) :
                                    ConversionFactory.GetPreDefinedConversion(inputType, outputType);

            if (conversion == null || conversion.ConversionType > conversionType)
            {
                throw CommonExceptions.InvalidCast(inputType, outputType);
            }
            if (conversion is FromNullableConversion)
            {
                il.EmitGetAddress(inputType);
            }
            conversion.Emit(il, inputType, outputType, isChecked);
        }
        protected override async Task OnInitializedAsync()
        {
            if (ViewModel.MatterTypeLookupList.Count() == 0)
            {
                ViewModel.MatterTypeLookupList = ConversionFactory.ConvertToDomainModel(await _api.GetMatterTypesLookupAsync());
            }

            if (ViewModel.DataCollectionLookupList.Count() == 0)
            {
                ViewModel.DataCollectionLookupList = ConversionFactory.ConvertToDomainModelForLookup(await _api.GetDataCollectionsAsync());
            }

            if (ViewModel.DataTypeLookupList.Count() == 0)
            {
                ViewModel.DataTypeLookupList = BuildDataTypeLookupList();
            }

            await DataCollectionPageNumberChanged(1);

            await base.OnInitializedAsync();
        }
Ejemplo n.º 29
0
 public static bool CanChangeType(Type inputType, Type outputType)
 {
     CommonExceptions.CheckArgumentNull(inputType, nameof(inputType));
     CommonExceptions.CheckArgumentNull(outputType, nameof(outputType));
     Contract.EndContractBlock();
     if (inputType.ContainsGenericParameters)
     {
         throw CommonExceptions.TypeContainsGenericParameters(inputType);
     }
     if (outputType.ContainsGenericParameters)
     {
         throw CommonExceptions.TypeContainsGenericParameters(outputType);
     }
     try
     {
         return(ConversionFactory.GetConversion(inputType, outputType) != null);
     }
     catch
     {
         return(false);
     }
 }
        public async Task EditDocument(int documentId)
        {
            if (ViewModel.MatterLookupList == null)
            {
                ViewModel.MatterLookupList = ConversionFactory.ConvertToDomainModel(await _api.GetMatterLookupAsync());
            }

            var documentDto = await _api.GetDocumentAsync(documentId);

            if (documentDto != null)
            {
                ViewModel.AddEditViewModel = new DocumentAddEditViewModel()
                {
                    DocumentId = documentDto.DocumentId,
                    Name       = documentDto.Name,
                    ActionId   = documentDto.Links.MatterId?.ToString()
                };

                documentEditContext           = new EditContext(ViewModel.AddEditViewModel);
                ViewModel.ShowNewDocumentCard = !ViewModel.ShowNewDocumentCard;
            }
        }