/// <summary> /// 初始化构造器 /// </summary> /// <param name="context"> 转换上下文 </param> /// <param name="type"> 需要构造的实例类型 </param> public ListBuilder(ConvertContext context, Type type) { _context = context; _type = type; _convertor = context.Get <T>(); Instance = null; }
public FaceSearchController( IFrameStream source, IOperation <Frame> frameProcessor, IConvertor <Frame, Portrait> convertor, IOperation <Portrait> portraitProcessor) { _source = source; _frameProcessor = frameProcessor; _convertor = convertor; _portraitProcessor = portraitProcessor; _worker.DoWork = delegate { var frames = frameProcessor.Execute(null).ToList(); var portraits = _convertor.Execute(frames).ToList(); var portraitsAfterProcess = _portraitProcessor.Execute(portraits).ToList(); foreach (var portrait in portraitsAfterProcess) { portrait.Dispose(); } }; _worker.OnExceptionRetry = () => _source.Connect(); }
public FaceSearchController( IFrameStream source, IOperation<Frame> frameProcessor, IConvertor<Frame, Portrait> convertor, IOperation<Portrait> portraitProcessor) { _source = source; _frameProcessor = frameProcessor; _convertor = convertor; _portraitProcessor = portraitProcessor; _worker.DoWork = delegate { var frames = frameProcessor.Execute(null).ToList(); var portraits = _convertor.Execute(frames).ToList(); var portraitsAfterProcess = _portraitProcessor.Execute(portraits).ToList(); foreach (var portrait in portraitsAfterProcess) { portrait.Dispose(); } }; _worker.OnExceptionRetry = () => _source.Connect(); }
public StoreService(IConvertor convertor, IFileSystemStore fileSystemStore, IPersonService personService, IHackingService hackingService) { this.convertor = convertor; this.fileSystemStore = fileSystemStore; this.personService = personService; this.hackingService = hackingService; }
public MyProfile(IConvertor convertor) { CreateMap <Model, ViewModel>() .ForMember(dest => dest.Id, opt => opt.MapFrom(src => src.Identifier)) .ForMember(dest => dest.Name, opt => opt.MapFrom(src => convertor.Execute(src.SomeText))) ; }
public TypeConverterWrapper(IConvertor convertor) { if (convertor == null) { throw new ArgumentNullException(nameof(convertor)); } _convertor = convertor; }
public static FaceSearchController CreateNewController(IFrameStream source, IOperation<Frame> frameProcessor, IConvertor<Frame, Portrait> convertor, IOperation<Portrait> portraitProcessor) { var controller = new FaceSearchController(source, frameProcessor, convertor, portraitProcessor); return controller; }
/// <summary> /// 初始化构造器 /// </summary> /// <param name="context"> 转换上下文 </param> /// <param name="type"> 待构造的对象实际类型 </param> /// <param name="keyConvertor"> 键转换器 </param> /// <param name="valueConvertor"> 值转换器 </param> public DictionaryBuilder(ConvertContext context, Type type, IConvertor <K> keyConvertor, IConvertor <V> valueConvertor) { _context = context; _type = type; Instance = null; _keyConvertor = keyConvertor; _valueConvertor = valueConvertor; }
public static FaceSearchController CreateNewController(IFrameStream source, IOperation <Frame> frameProcessor, IConvertor <Frame, Portrait> convertor, IOperation <Portrait> portraitProcessor) { var controller = new FaceSearchController(source, frameProcessor, convertor, portraitProcessor); return(controller); }
//通过设置行列数组读取 public static TDataType[,] StreamReadFromStrFile <TDataType>(StreamReader reader, long[] rowCollection, long[] columnCollection, string delims) { string lineData = null;//定义一个字符串做每一行的数据 long rowCount = rowCollection.Length; long columnCount = columnCollection.Length; int skipRowIndex = (int)rowCollection[0];//将开始的行数作为当前读取的行数索引 do { lineData = reader.ReadLine();//在数据流中读取一行 } while (skipRowIndex-- > 0 && null != lineData); // 读取到startRow的下一行,如果为空,则返回null if (null == lineData) { return(null); } IConvertor convertor = GetConvertor <TDataType>(); char[] delimArray = delims.ToCharArray(); //把一个“,”复制在字符数组 string[] lineElems = lineData.Split(delimArray); //读到的当前行数据使用“,”分隔后,放在字符串数组中lineElems if (columnCount == 0) { columnCollection = new long[lineElems.Length]; //将每一行数据的长度定义为列数 for (int j = 0; j < columnCount; j++) { columnCollection[j] = (uint)j; } } TDataType[,] readDatas = new TDataType[rowCount, columnCount]; //定义一个行为行数,列为列数减起始列数的数组 int i = (int)rowCollection[0]; //行索引 int rowIndex = 0; CopyStrToDst(lineElems, readDatas, convertor, rowIndex++, columnCollection); //原数据为每行数据,读取到readData中,readdata行索引从0开始,列数组 rowCount--; //要读取的总行数减一 while (null != (lineData = reader.ReadLine()) && rowCount > 0) { i++; if (rowCollection[rowIndex] == i) { //读下一行不为null,且要读取的总行数还大于零 lineElems = lineData.Split(delimArray); //再把该行数据用,分开 CopyStrToDst(lineElems, readDatas, convertor, rowIndex++, columnCollection); //把该行数据写入readdata里 rowCount--; } } if (rowCount != 0) { //如果要读取的行数不为零,也就是读到的该行为null,调整readData的行数 FitArrayRowCountToData(ref readDatas, (int)(readDatas.GetLength(0) - rowCount)); } return(readDatas); }
//通过设置起始位置和行列数读取 public static TDataType[,] StreamReadFromStrFile <TDataType>(StreamReader reader, long startRow, long startColumn, long rowCount, long columnCount, string delims) { string lineData = null; //定义一个字符串做每一行的数据 int skipRowIndex = (int)startRow; //将开始的行数作为当前读取的行数索引 do { lineData = reader.ReadLine();//在数据流中读取一行 } while (skipRowIndex-- > 0 && null != lineData); // 读取到startRow的下一行,如果为空,则返回null if (null == lineData) { return(null); } IConvertor convertor = GetConvertor <TDataType>(); char[] delimArray = delims.ToCharArray(); //把一个“,”复制在字符数组 string[] lineElems = lineData.Split(delimArray); //读到的当前行数据使用“,”分隔后,放在字符串数组中lineElems if (columnCount == -1) { columnCount = (uint)lineElems.Length; //将每一行数据的长度定义为列数 } if (startColumn >= columnCount) { //如果起始列大于列数,则抛错 throw new SeeSharpFileException(SeeSharpFileErrorCode.ParamCheckError, i18n.GetStr("ParamCheck.InvalidColIndex")); } TDataType[,] readDatas = new TDataType[rowCount, columnCount]; //定义一个行为行数,列为列数减起始列数的数组 long rowIndex = 0; //行索引 long[] columns = new long[columnCount]; //列数长度是总列数减去起始列数 for (int i = 0; i < columns.Length; i++) { columns[i] = startColumn++; //列的值从起始列开始增加 } CopyStrToDst(lineElems, readDatas, convertor, rowIndex++, columns); //原数据为每行数据,读取到readData中,readdata行索引从0开始,列数组 rowCount--; //要读取的总行数减一 while (null != (lineData = reader.ReadLine()) && rowCount > 0) { //读下一行不为null,且要读取的总行数还大于零 lineElems = lineData.Split(delimArray); //再把该行数据用,分开 CopyStrToDst(lineElems, readDatas, convertor, rowIndex++, columns); //把该行数据写入readdata里 rowCount--; } if (rowCount != 0) { //如果要读取的行数不为零,也就是读到的该行为null,调整readData的行数 FitArrayRowCountToData(ref readDatas, (int)(readDatas.GetLength(0) - rowCount)); } return(readDatas); }
public ExchangerApp() { exchange1 = new Exchange1(); exchange2 = new Exchange2(); pesoDolarConvertor = new ConvertPesoDolar(); dolarPesoConvertor = new ConvertDolarPeso(); dolarEuroConvertor = new ConvertDolarEuro(); euroDolarConvertor = new ConvertEuroDolar(); euroPesoConvertor = new ConvertEuroPeso(); pesoEuroConvertor = new ConvertPesoEuro(); }
public bool Of <TType>(object value, Func <string, bool> isOfType, IConvertor <string, TType> convert, out TType result) { result = default; var valueString = value?.ToString(); if (value == default || !isOfType(valueString)) { return(false); } return(convert.TryConvert(valueString, out result)); }
private static void AddStudentsToList(IConvertor<Student, String> convertor, IList<Student> studentList) { foreach (string line in File.ReadAllLines("Students.txt")) { if (string.IsNullOrWhiteSpace(line)) { continue; } Student student = convertor.ConvertFrom(line); studentList.Add(student); } }
private HttpRequest PrepareHttpRequest <T>(T request, HttpContext context) where T : ObsWebServiceRequest { IConvertor iconvertor = this.GetIConvertor(context); MethodInfo info = CommonUtil.GetTransMethodInfo(request.GetType(), iconvertor); HttpRequest httpRequest = info.Invoke(iconvertor, new object[] { request }) as HttpRequest; if (httpRequest == null) { throw new ObsException(string.Format("Cannot trans request:{0} to HttpRequest", request.GetType()), ErrorType.Sender, "Trans error", ""); } httpRequest.Endpoint = this.ObsConfig.Endpoint; httpRequest.PathStyle = this.ObsConfig.PathStyle; return(httpRequest); }
public static TDataType[,] StreamReadFromStrFile <TDataType>(StreamReader reader, uint lineCount, string delims, uint startRow, uint startColumn) { string lineData = null; int skipRowIndex = (int)startRow; do { lineData = reader.ReadLine(); } while (skipRowIndex-- > 0 && null != lineData); // 读取到startRow的下一行,如果为空,则返回null if (null == lineData) { return(null); } IConvertor convertor = GetConvertor <TDataType>(); char[] delimArray = delims.ToCharArray(); string[] lineElems = lineData.Split(delimArray); int colCount = lineElems.Length; if (startColumn >= colCount) { throw new SeeSharpFileException(SeeSharpFileErrorCode.ParamCheckError, i18n.GetStr("ParamCheck.InvalidColIndex")); } TDataType[,] readDatas = new TDataType[lineCount, colCount - startColumn]; int rowIndex = 0; uint[] columns = new uint[colCount - startColumn]; for (int i = 0; i < columns.Length; i++) { columns[i] = startColumn++; } CopyStrToDst(lineElems, readDatas, convertor, rowIndex++, columns); lineCount--; while (null != (lineData = reader.ReadLine()) && lineCount > 0) { lineElems = lineData.Split(delimArray); CopyStrToDst(lineElems, readDatas, convertor, rowIndex++, columns); lineCount--; } if (lineCount != 0) { FitArrayRowCountToData(ref readDatas, (int)(readDatas.GetLength(0) - lineCount)); } return(readDatas); }
/// <summary> /// Converts elements in the array to string representation. /// </summary> /// <typeparam name="TSource">The TSourse.</typeparam> /// <typeparam name="TResult">The TResult.</typeparam> /// <param name="array">The array.</param> /// <param name="convertor">The convertor.</param> /// <returns>The array with string items.</returns> public static TResult[] Transform <TSource, TResult>(this TSource[] array, IConvertor <TSource, TResult> convertor) { if (convertor == null) { throw new ArgumentNullException($"{nameof(convertor)} can't be null."); } TResult[] result = new TResult[array.Length]; for (int i = 0; i < array.Length; i++) { result[i] = convertor.Convert(array[i]); } return(result); }
public static TDataType[,] StreamReadFromStrFile <TDataType>(StreamReader reader, int lineCount, string delims, uint startRow, uint[] columns) { string lineData = null; int skipRowIndex = (int)startRow; do { lineData = reader.ReadLine(); } while (skipRowIndex-- > 0 && null != lineData); if (null == lineData) { return(null); } IConvertor convertor = GetConvertor <TDataType>(); char[] delimArray = delims.ToCharArray(); string[] lineElems = lineData.Split(delimArray); if (columns.Max() >= lineElems.Length) { throw new SeeSharpFileException(SeeSharpFileErrorCode.ParamCheckError, i18n.GetStr("ParamCheck.InvalidColIndex")); } TDataType[,] readDatas = new TDataType[lineCount - startRow, columns.Length]; int rowIndex = 0; CopyStrToDst(lineElems, readDatas, convertor, rowIndex++, columns); while (null != (lineData = reader.ReadLine())) { lineElems = lineData.Split(delimArray); CopyStrToDst(lineElems, readDatas, convertor, rowIndex++, columns); } return(readDatas); }
//通过设置起始位置和行列数读取 public static TDataType[] StreamReadFromStrFile <TDataType>(StreamReader reader, long index, long startIndex, long size, bool majorOrder, string delims) { TDataType[] readDatas; if (majorOrder == false) { string lineData = null; //定义一个字符串做每一行的数据 int skipRowIndex = (int)index; //将开始的行数作为当前读取的行数索引 do { lineData = reader.ReadLine();//在数据流中读取一行 } while (skipRowIndex-- > 0 && null != lineData); // 读取到startRow的下一行,如果为空,则返回null if (null == lineData) { return(null); } IConvertor convertor = GetConvertor <TDataType>(); char[] delimArray = delims.ToCharArray(); //把一个“,”复制在字符数组 string[] lineElems = lineData.Split(delimArray); //读到的当前行数据使用“,”分隔后,放在字符串数组中lineElems if (size == -1) { readDatas = new TDataType[(int)lineElems.Length - startIndex];//定义长度为总列数的数组 } else { readDatas = new TDataType[size];//定义长度为总列数的数组 } CopyStrToDst(lineElems, readDatas, convertor, startIndex);//原数据为每行数据,读取到readData中,readdata行索引从0开始,列数组 return(readDatas); } else { string lineData = null; //定义一个字符串做每一行的数据 int skipRowIndex = (int)startIndex; //将开始的行数作为当前读取的行数索引 do { lineData = reader.ReadLine();//在数据流中读取一行 } while (skipRowIndex-- > 0 && null != lineData); // 读取到startRow的下一行,如果为空,则返回null if (null == lineData) { return(null); } IConvertor convertor = GetConvertor <TDataType>(); char[] delimArray = delims.ToCharArray(); //把一个“,”复制在字符数组 string[] lineElems = lineData.Split(delimArray); //读到的当前行数据使用“,”分隔后,放在字符串数组中lineElems string[] singleColumn = new string[] { lineElems[index] }; readDatas = new TDataType[size]; //定义长度为总列数的数组 TDataType[] data = new TDataType[1]; CopyStrToDst(singleColumn, data, convertor); //原数据为每行数据,读取到readData中,readdata行索引从0开始,列数组 int i = 0; readDatas[i++] = data[0]; while (null != (lineData = reader.ReadLine()) && size > 1) { lineElems = lineData.Split(delimArray); //再把该行数据用,分开 singleColumn[0] = lineElems[index]; CopyStrToDst(singleColumn, data, convertor); //把该行数据写入readdata里 readDatas[i++] = data[0]; size--; } return(readDatas); } }
private static void CopyStrToDst <TDataType>(string[] srcStrs, TDataType[] dstStrs, IConvertor convertor, long startIndex = 0) { if ((srcStrs.Length - startIndex) < dstStrs.Length) { throw new SeeSharpFileException(SeeSharpFileErrorCode.DataLengthMismatch, i18n.GetStr("DataLengthMismatch")); } for (int i = (int)startIndex; i < dstStrs.Length + ((int)(startIndex)); i++) { dstStrs[i - startIndex] = (TDataType)convertor.Convert(srcStrs[i]); } }
/// <summary> /// преобразование объекта, для использования в другой объектной модели организации фильтрации данных /// </summary> /// <param name="visitor"> конвертор </param> public abstract void AcceptConvert(IConvertor visitor);
/// <summary> /// 从指定的 Type 创建新的 JsonType 对象 /// </summary> public JsonType(Type type) { if (type == null) { throw new ArgumentNullException(nameof(type)); } Type = type; DisplayText = ComponentServices.Converter.ToString(type); _members = new Dictionary <string, JsonMember>(StringComparer.OrdinalIgnoreCase); var list = new List <JsonMember>(); TypeCode = Type.GetTypeCode(type); IsMataType = EqualMataType(type); IsAnonymous = Type.IsGenericType && Type.Name.StartsWith("<>f__AnonymousType"); IsObject = type == typeof(object); Convertor = ConvertorServices.Container.GetConvertor(type); IsNumber = TypeCode >= TypeCode.SByte && TypeCode <= TypeCode.Decimal; //兼容IList,IDictionary,IList<T>,IDictionary<TKey, TValue> //判断接口 var iType = GetInterface(type, typeof(IDictionary <,>)); if (iType != null) { IsDictionary = true; var args = iType.GetGenericArguments(); if (type.IsInterface) //兼容 IDictionary<TKey, TValue> { Type = typeof(Dictionary <,>).MakeGenericType(args); } KeyType = Get(args[0]); ElementType = Get(args[1]); AddKeyValue = ((IAddOrSet) Activator.CreateInstance(typeof(AddOrSet <,>).MakeGenericType(KeyType.Type, ElementType.Type))) .IDictionaryT; return; } iType = GetInterface(type, typeof(IDictionary)); if (iType != null) { IsDictionary = true; if (type.IsInterface) //兼容 IDictionary { Type = typeof(Hashtable); } KeyType = Get <object>(); ElementType = KeyType; AddKeyValue = ((IAddOrSet) Activator.CreateInstance(typeof(AddOrSet <,>).MakeGenericType(KeyType.Type, ElementType.Type))) .IDictionary; return; } if (typeof(NameValueCollection).IsAssignableFrom(type)) { IsDictionary = true; KeyType = Get <string>(); ElementType = Get <string>(); AddKeyValue = (o, k, v) => ((NameValueCollection)o).Add((string)k, (string)v); return; } if (type.IsArray) { IsList = true; ElementType = Get(type.GetElementType()); AddValue = (o, v) => ((ArrayList)o).Add(v); return; } iType = GetInterface(type, typeof(ICollection <>)); if (iType != null) { IsList = true; var args = iType.GetGenericArguments(); if (type.IsInterface) //兼容 ICollection<T> { Type = typeof(List <>).MakeGenericType(args); } ElementType = Get(args[0]); AddValue = ((IAddOrSet) Activator.CreateInstance(typeof(AddOrSet <,>).MakeGenericType(typeof(object), ElementType.Type))) .ICollectionT; return; } iType = GetInterface(type, typeof(IList)); if (iType != null) { if (type.IsInterface) //兼容 ICollection<T> { Type = typeof(ArrayList); } IsList = true; ElementType = Get <object>(); AddValue = ((IAddOrSet)Activator.CreateInstance(typeof(AddOrSet <,>).MakeGenericType(typeof(object), ElementType.Type))).IList; return; } if (IsAnonymous == false) { //过滤基本类型 if (type.IsPrimitive || type == typeof(string) || type.IsEnum || (type.Namespace == "System" && type.Module == typeof(int).Module && type.IsValueType && typeof(IFormattable).IsAssignableFrom(type))) { PropertyCount = 0; return; } } var flags = BindingFlags.Instance | BindingFlags.Public; //枚举属性 foreach (var p in Type.GetProperties(flags)) { //获取索引器 if (p.GetIndexParameters()?.Length > 0) { continue; } var jm = JsonMember.Create(p); if (jm != null) { if (_members.ContainsKey(jm.JsonName)) { throw new ArgumentException($"JsonName重复:{jm.JsonName}"); } _members[jm.JsonName] = jm; list.Add(jm); } } PropertyCount = list.Count; //枚举字段 foreach (var f in Type.GetFields(flags)) { var jm = JsonMember.Create(f); if (jm != null) { if (_members.ContainsKey(jm.JsonName)) { throw new ArgumentException($"JsonName重复:{jm.JsonName}"); } _members[jm.JsonName] = jm; list.Add(jm); } } Members = list.ToArray(); }
public abstract string Convert(IConvertor convertor);
public static IDisposable Bind <T1, T2>(Func <T1> propertyAGetter, Action <T1> propertyASetter, Func <T2> propertyBGetter, Action <T2> propertyBSetter, IConvertor <T1, T2> convertor, BindingTypes bindingTypes = BindingTypes.Default, params IFilter <T1>[] filters) { var propertyBBinding = Observable.EveryUpdate() .Select(x => convertor.From(propertyBGetter())) .ApplyInputFilters(filters) .DistinctUntilChanged() .Subscribe(propertyASetter); if (bindingTypes == BindingTypes.OneWay) { return(propertyBBinding); } if (propertyBSetter == null) { throw new SetterNotProvidedException(); } var propertyABinding = Observable.EveryUpdate() .Select(x => propertyAGetter()) .ApplyOutputFilters(filters) .DistinctUntilChanged() .Select(convertor.From) .Subscribe(propertyBSetter); return(new CompositeDisposable(propertyABinding, propertyBBinding)); }
public override string Convert(IConvertor convertor) { return(convertor.ConvertHyperlink(this)); }
public virtual void AcceptConvert(IConvertor visitor) { visitor.Convert(this); }
// public abstract Currency Exchange(Currency from, string to); public abstract Currency Exchange(Currency from, IConvertor currencyConvertor);
public override void AcceptConvert(IConvertor visitor) { //TODO: CR: PYA: NotSupported or InvalidOperation? //TODO: CR: PYA-FIX: throw new NotSupportedException("Convert of objects of this class not supported by IConvertor"); }
private static void CopyStrToDst <TDataType>(string[] srcStrs, TDataType[,] dstStrs, IConvertor convertor, int rowIndex, uint[] columnIndexes) { int copySize = dstStrs.GetLength(1); if (columnIndexes.Length != copySize) { throw new SeeSharpFileException(SeeSharpFileErrorCode.ParamCheckError, i18n.GetFStr("ParamCheck.ColCountNotFit", rowIndex + 1)); } for (int i = 0; i < copySize; i++) { dstStrs[rowIndex, i] = (TDataType)convertor.Convert(srcStrs[columnIndexes[i]]); } }
/// <summary> /// преобразование объекта, для использования в другой объектной модели организации фильтрации данных /// </summary> /// <param name="visitor"> конвертор </param> public override void AcceptConvert(IConvertor visitor) { visitor.Convert(this); }
public Plugger(IConvertor convertor) { this.convertor = convertor; }
public override string Convert(IConvertor convertor) { return(convertor.ConvertBoldText(this)); }
public static IDisposable Bind <T1, T2>(IReactiveProperty <T1> propertyA, IReactiveProperty <T2> propertyB, IConvertor <T1, T2> convertor, BindingTypes bindingTypes = BindingTypes.Default, params IFilter <T1>[] filters) { var propertyBBinding = propertyB .Select(convertor.From) .ApplyInputFilters(filters) .DistinctUntilChanged() .Subscribe(x => propertyA.Value = x); if (bindingTypes == BindingTypes.OneWay) { return(propertyBBinding); } var propertyABinding = propertyA .ApplyOutputFilters(filters) .DistinctUntilChanged() .Select(convertor.From) .Subscribe(x => propertyB.Value = x); return(new CompositeDisposable(propertyABinding, propertyBBinding)); }