public Encoder(string encoder) { var cd = Directory.GetCurrentDirectory(); // We change the current directory to the target dll because it might have other adjacent dll dependencies to find. Directory.SetCurrentDirectory(Path.GetDirectoryName(encoder)); dllHandle = LoadLibrary(encoder); Directory.SetCurrentDirectory(cd); if (dllHandle == IntPtr.Zero) { throw new ArgumentException($"\"{encoder}\"\nfailed to load. Error Code {Marshal.GetLastWin32Error()}."); } var convertHandle = GetProcAddress(dllHandle, "Convert"); if (convertHandle == IntPtr.Zero) { throw new ArgumentException($"{encoder}\nfailed to load the \"Convert\" function. Error code: {Marshal.GetLastWin32Error()}"); } var updateHandle = GetProcAddress(dllHandle, "Update"); if (updateHandle == IntPtr.Zero) { throw new ArgumentException($"{encoder}\nfailed to load the \"Update\" function. Error code: {Marshal.GetLastWin32Error()}"); } convertFunc = (ConvertDelegate)Marshal.GetDelegateForFunctionPointer(convertHandle, typeof(ConvertDelegate)); updateFunc = (UpdateDelegate)Marshal.GetDelegateForFunctionPointer(updateHandle, typeof(UpdateDelegate)); }
public ImageCpc(Main m, ConvertDelegate fctConvert) { InitializeComponent(); main = m; for (int i = 0; i < 16; i++) { // Générer les contrôles de "couleurs" colors[i] = new Label(); colors[i].BorderStyle = BorderStyle.FixedSingle; colors[i].Location = new Point(4 + i * 48, 568); colors[i].Size = new Size(40, 32); colors[i].Tag = i; colors[i].MouseDown += ClickColor; Controls.Add(colors[i]); // Générer les contrôles de "bloquage couleur" lockColors[i] = new CheckBox(); lockColors[i].Location = new Point(16 + i * 48, 600); lockColors[i].Size = new Size(20, 20); lockColors[i].Tag = i; lockColors[i].Click += ClickLock; Controls.Add(lockColors[i]); lockColors[i].Update(); } InitBitmapCpc(1, 100); Reset(); tailleCrayon.SelectedItem = "1"; Convert = fctConvert; pictureBox.Image = imgOrigine = BmpLock.Bitmap; }
public ImageCpc(ConvertDelegate fctConvert) { InitializeComponent(); int tx = pictureBox.Width; int ty = pictureBox.Height; bmp = new Bitmap(tx, ty); pictureBox.Image = bmp; bmpLock = new LockBitmap(bmp); bitmapCpc = new BitmapCpc(640, 400, 1); // ### for (int i = 0; i < 16; i++) { // Générer les contrôles de "couleurs" colors[i] = new Label(); colors[i].BorderStyle = BorderStyle.FixedSingle; colors[i].Location = new Point(4 + i * 48, 568); colors[i].Size = new Size(40, 32); colors[i].Tag = i; colors[i].Click += ClickColor; Controls.Add(colors[i]); // Générer les contrôles de "bloquage couleur" lockColors[i] = new CheckBox(); lockColors[i].Location = new Point(16 + i * 48, 600); lockColors[i].Size = new Size(20, 20); lockColors[i].Tag = i; lockColors[i].Click += ClickLock; Controls.Add(lockColors[i]); lockColors[i].Update(); } Reset(); ChangeZoom(1); Convert = fctConvert; }
public IList GetListObjects(string listName, string itemName, Type type, ConvertDelegate convert) { IList listObjs = null; IList jsonList = json[listName] as IList; if (jsonList != null && jsonList.Count > 0) { Type listType = typeof(List <>).MakeGenericType(new Type[] { type }); listObjs = Activator.CreateInstance(listType) as IList; foreach (object item in jsonList) { if (typeof(IDictionary).IsAssignableFrom(item.GetType())) // object { IDictionary subMap = item as IDictionary; object subObj = convert(new SimplifyJsonReader(subMap), type); if (subObj != null) { listObjs.Add(subObj); } } else if (typeof(IList).IsAssignableFrom(item.GetType())) // list or array { // TODO not support yet } else // string, bool, long, double, null, other { listObjs.Add(item); } } } return(listObjs); }
public static void MakeConverter(this ResourceDictionary dic, string key, ConvertDelegate convert, ConvertBackDelegate convertBack = null) { var conv = new ValueConverterGenerator(convert, convertBack); dic.Add(key, conv); }
static Converter() { DynamicMethod dMethod = new DynamicMethod($"Converter<{typeof(TFrom).Name},{typeof(TTo).Name}>", typeof(TTo), new[] { typeof(TFrom) }, typeof(ConvertDelegate).Module, true); ILGenerator il = dMethod.GetILGenerator(); il.Emit(OpCodes.Ldarg_0); il.Emit(OpCodes.Ret); _converter = (ConvertDelegate)dMethod.CreateDelegate(typeof(ConvertDelegate)); }
//конвертирует список типа TI в список типа TO public static IList <TO> ConvertAll <TI, TO>(IList <TI> list, ConvertDelegate <TI, TO> convert, ListConstructorDelegate <TO> construct) { IList <TO> converted = construct(); foreach (TI item in list) { converted.Add(convert(item)); } return(converted); }
public static void RegisterConverter(Type fromType, Type toType, ConvertDelegate converter) { var key = fromType.ToString() + "-" + toType.ToString(); if (_converters.ContainsKey(key)) { _converters[key] = converter; return; } _converters.Add(key, converter); }
public static IList <TOutput> ConvertAll <TInput, TOutput> (IList <TInput> list, ConvertDelegate <TInput, TOutput> convertDelegate, ListConstructorDelegate <TOutput> listConstructorDelegate) { IList <TOutput> resultList = listConstructorDelegate(); foreach (var item in list.Reverse()) { resultList.Add(convertDelegate(item)); } return(resultList); }
public T[] Convert <T>(ConvertDelegate <T> converter) { T[] array = new T[_strings.Length]; for (int i = 0; i < _strings.Length; ++i) { array[i] = converter(_strings[i]); } return(array); }
public static void AddConverter(Type fromType, Type toType, ConvertDelegate converter) { var doubleType = new DoubleType(fromType, toType); lock (_lockObject) { if (!_converters.ContainsKey(doubleType)) { _converters.Add(doubleType, converter); } } }
public object GetReferenceObject(object name, Type type, ConvertDelegate convert) { IDictionary dict = json[name] as IDictionary; if (dict != null && dict.Count > 0) { return(convert(new CJsonReader(dict), type)); } else { return(null); } }
private object ConvertIntern(string script, ref ConvertDelegate dlg, object value, object targetType, object parameter, CultureInfo culture) { if (String.IsNullOrEmpty(script)) { throw new NotImplementedException(); } if (dlg == null) // compile function { var localLua = getShell != null ? getShell.Value.Lua : lua; dlg = localLua.CreateLambda <ConvertDelegate>("convert.lua", script); } return(dlg.DynamicInvoke(value, targetType, parameter, getShell?.Value, culture)); } // func ConvertIntern
private static T ReadData <T>(string label, T defaultValue, ConvertDelegate <T> converter) { string input; T output; do { Write($"{label} ({defaultValue}): "); input = Console.ReadLine(); if (string.IsNullOrWhiteSpace(input)) { return(defaultValue); } }while (!converter(input, out output)); return(output); }
public void Process() { Task <string> t = new Task <string>(() => { ConvertDelegate cdelegate = new ConvertDelegate(Convertor); resetEvent.Set(); IAsyncResult res = cdelegate.BeginInvoke(textBoxInput.Text, WriteFileCallback, textBoxInput.Text); //异步执行完成 string resultstr = cdelegate.EndInvoke(res); return(resultstr); }); t.Start(); string result = t.Result; SetOutPut stcb = new SetOutPut(SetOutPutStr); t.ContinueWith((str) => { this.Invoke(stcb, result); return(result); }); }
private string convert(string dstr, DataType fromType, DataType toType) { var type = Convert.ToInt32(fromType); ConvertDelegate convertDelegate = null; if (type == 2) { convertDelegate = _2To; } else if (type == 4) { convertDelegate = _4To; } else if (type == 8) { convertDelegate = _8To; } else if (type == 10) { convertDelegate = _10To; } else if (type == 16) { convertDelegate = _16To; } else if (type == 32) { convertDelegate = _32To; } else if (type == 64) { convertDelegate = _64To; } var result = convertDelegate != null?convertDelegate(dstr, toType) : ""; return(result); }
public PixelConverter(PixelFormat input, PixelFormat output, ConvertDelegate converter) { Input = input; Output = output; this.converter = converter; }
public static IList <TOutput> ConvertAll <TInput, TOutput> (IList <TInput> list, ConvertDelegate <TInput, TOutput> convertDelegate, ListConstructorDelegate <TOutput> listConstructorDelegate) { throw new NotImplementedException(); }
public WpfActionValueConverter(ConvertDelegate convert, ConvertDelegate convertBack = null) { _convert = convert ?? throw new ArgumentNullException(nameof(convert)); _convertBack = convertBack; }
public InlineMultiConverter(ConvertDelegate convert, ConvertBackDelegate convertBack = null) { this._convert = convert ?? throw new ArgumentNullException(nameof(convert)); this._convertBack = convertBack; }
public static T[] GenerateArray <T>(string input, ConvertDelegate <T> converter) { return(new SimpleArrayParser(input).Convert <T>(converter)); }
// Create a new relation type for a particular heading // Called once for the generic, then once for each specific public static DataTypeRelation Create(string name, DataHeading heading, TypeFlags flags, ConvertDelegate converter = null, DefaultDelegate defaulter = null) { //var basetype = DataTypes.Table as DataTypeRelation; var dt = new DataTypeRelation { Name = name, Heading = heading, Flags = flags, }; return(dt); }
public InlineMultiConverter(ConvertDelegate convert, ConvertBackDelegate?convertBack = null) { _convert = convert; _convertBack = convertBack; }
// Create a new relation type for a particular heading // Called once for the generic, then once for each specific static DataTypeTuple Create(string name, DataHeading heading, TypeFlags flags, ConvertDelegate converter = null, DefaultDelegate defaulter = null) { //var basetype = DataTypes.Row as DataTypeTuple; var dt = new DataTypeTuple { Name = name, Heading = heading, Flags = flags, }; return(dt); }
public PcmFormatConverter(int numChannels) { mRand = new Random(); mErr = new int[numChannels]; var convertFromI16 = new ConvertDelegate[] { new ConvertDelegate(ConvClone), new ConvertDelegate(ConvI16toI24), new ConvertDelegate(ConvI16toI32), new ConvertDelegate(ConvI16toI32), new ConvertDelegate(ConvI16toF32), new ConvertDelegate(ConvI16toF64)}; var convertFromI24 = new ConvertDelegate[] { new ConvertDelegate(ConvI24or32toI16), new ConvertDelegate(ConvClone), new ConvertDelegate(ConvI24toI32), new ConvertDelegate(ConvI24toI32), new ConvertDelegate(ConvI24toF32), new ConvertDelegate(ConvI24toF64)}; var convertFromI32V24 = new ConvertDelegate[] { new ConvertDelegate(ConvI24or32toI16), new ConvertDelegate(ConvI32V24toI24), new ConvertDelegate(ConvClone), new ConvertDelegate(ConvI32V24toI32), new ConvertDelegate(ConvI32toF32), new ConvertDelegate(ConvI32toF64)}; var convertFromI32 = new ConvertDelegate[] { new ConvertDelegate(ConvI24or32toI16), new ConvertDelegate(ConvI32toI24orI32V24), new ConvertDelegate(ConvI32toI24orI32V24), new ConvertDelegate(ConvClone), new ConvertDelegate(ConvI32toF32), new ConvertDelegate(ConvI32toF64)}; var convertFromF32 = new ConvertDelegate[] { new ConvertDelegate(ConvF32toI16), new ConvertDelegate(ConvF32toI24orI32V24), new ConvertDelegate(ConvF32toI24orI32V24), new ConvertDelegate(ConvF32toI32), new ConvertDelegate(ConvClone), new ConvertDelegate(ConvF32toF64)}; var convertFromF64 = new ConvertDelegate[] { new ConvertDelegate(ConvF64toI16), new ConvertDelegate(ConvF64toI24orI32V24), new ConvertDelegate(ConvF64toI24orI32V24), new ConvertDelegate(ConvF64toI32), new ConvertDelegate(ConvF64toF32), new ConvertDelegate(ConvClone)}; mConvert = new ConvertDelegate[][] { convertFromI16, convertFromI24, convertFromI32V24, convertFromI32, convertFromF32, convertFromF64}; }
public PcmFormatConverter(int numChannels) { mRand = new Random(); mErr = new int[numChannels]; var convertFromI16 = new ConvertDelegate[] { new ConvertDelegate(ConvClone), new ConvertDelegate(ConvI16toI24), new ConvertDelegate(ConvI16toI32), new ConvertDelegate(ConvI16toI32), new ConvertDelegate(ConvI16toF32), new ConvertDelegate(ConvI16toF64) }; var convertFromI24 = new ConvertDelegate[] { new ConvertDelegate(ConvI24or32toI16), new ConvertDelegate(ConvClone), new ConvertDelegate(ConvI24toI32), new ConvertDelegate(ConvI24toI32), new ConvertDelegate(ConvI24toF32), new ConvertDelegate(ConvI24toF64) }; var convertFromI32V24 = new ConvertDelegate[] { new ConvertDelegate(ConvI24or32toI16), new ConvertDelegate(ConvI32V24toI24), new ConvertDelegate(ConvClone), new ConvertDelegate(ConvI32V24toI32), new ConvertDelegate(ConvI32toF32), new ConvertDelegate(ConvI32toF64) }; var convertFromI32 = new ConvertDelegate[] { new ConvertDelegate(ConvI24or32toI16), new ConvertDelegate(ConvI32toI24orI32V24), new ConvertDelegate(ConvI32toI24orI32V24), new ConvertDelegate(ConvClone), new ConvertDelegate(ConvI32toF32), new ConvertDelegate(ConvI32toF64) }; var convertFromF32 = new ConvertDelegate[] { new ConvertDelegate(ConvF32toI16), new ConvertDelegate(ConvF32toI24orI32V24), new ConvertDelegate(ConvF32toI24orI32V24), new ConvertDelegate(ConvF32toI32), new ConvertDelegate(ConvClone), new ConvertDelegate(ConvF32toF64) }; var convertFromF64 = new ConvertDelegate[] { new ConvertDelegate(ConvF64toI16), new ConvertDelegate(ConvF64toI24orI32V24), new ConvertDelegate(ConvF64toI24orI32V24), new ConvertDelegate(ConvF64toI32), new ConvertDelegate(ConvF64toF32), new ConvertDelegate(ConvClone) }; mConvert = new ConvertDelegate[][] { convertFromI16, convertFromI24, convertFromI32V24, convertFromI32, convertFromF32, convertFromF64 }; }
// Create a new Code type for a particular heading public static DataTypeCode Create(string name, DataHeading heading, TypeFlags flags, ConvertDelegate converter = null, DefaultDelegate defaulter = null) { var dt = new DataTypeCode { Name = name, Heading = heading, Flags = flags, }; dt.NativeType = TypeMaker.CreateType(dt); return(dt); }
public ValueConverter(ConvertBasicDelegate Convert, ConvertBasicDelegate ConvertBack = null) { this.convert = (value, targetType, parameter, culture) => { return(Convert.Invoke(value)); }; this.convertBack = (value, targetType, parameter, culture) => { return(ConvertBack?.Invoke(value)); }; }
public ValueConverterGenerator(ConvertDelegate convert, ConvertBackDelegate convertBack) { this.convert = convert; this.convertBack = convertBack; }
/// <summary> /// Registers a new converter from <typeparamref name="TSource"/> to <typeparamref name="TDestination"/>. /// </summary> /// <param name="convert"></param> /// <typeparam name="TSource"></typeparam> /// <typeparam name="TDestination"></typeparam> public static void Register <TSource, TDestination>(ConvertDelegate <TSource, TDestination> convert) { Converter <TSource, TDestination> .Convert = convert; }
public Item(string name, string format, ParseDelegate parse, ConvertDelegate toBase, ConvertDelegate toUnit) { Name = name; Format = format; _parse = parse; _toBase = toBase; _toUnit = toUnit; }
public ValueConverter(ConvertDelegate Convert, ConvertDelegate ConvertBack = null) { this.convert = Convert; this.convertBack = ConvertBack; }