/// <summary> /// Releases all allocated resources /// </summary> /// <param name="managed">True if called by user, false if called by finalizer</param> protected virtual void Dispose(bool managed) { if (!IsDisposed) { if (InValuesHandle.IsAllocated) { InValuesHandle.Free(); } if (OutValuesHandle.IsAllocated) { OutValuesHandle.Free(); } if (Data != null) { Data.Dispose(); } if (managed) { ConversionMethod = null; Data = null; } IsDisposed = true; } }
/// <summary> /// Creates a new instance of the <see cref="ColorConverter"/> class /// </summary> /// <param name="inColor">The input color</param> /// <param name="outColor">The output color</param> public ColorConverter(Color inColor, Color outColor) { if (inColor == null || outColor == null) { throw new ArgumentNullException(); } if (!IsInitiated) { Init(); } InColor = inColor; OutColor = outColor; InValuesHandle = GCHandle.Alloc(InColor.Values, GCHandleType.Pinned); OutValuesHandle = GCHandle.Alloc(OutColor.Values, GCHandleType.Pinned); InValues = (double *)InValuesHandle.AddrOfPinnedObject(); OutValues = (double *)OutValuesHandle.AddrOfPinnedObject(); Data = new ConversionData(InColor, OutColor); var types = new Type[] { typeof(ColorConverter), typeof(double *), typeof(double *), typeof(ConversionData) }; DynamicMethod convMethod = new DynamicMethod("ConversionMethod", null, types, typeof(ColorConverter)); GetConversionMethod(convMethod.GetILGenerator()); ConversionMethod = convMethod.CreateDelegate(typeof(ConversionDelegate), this) as ConversionDelegate; }
/// <summary> /// Creates a new instance of the <see cref="CC_ExecuteMethod"/> class /// </summary> /// <param name="method">The method to execute</param> public CC_ExecuteMethod(ConversionDelegate method) { if (method == null) { throw new ArgumentNullException(nameof(method)); } MethodC = method; }
public PathCheckData(Color inColor, Color outColor, ConversionDelegate conversion, double[] inValues, double[] outValues) : this(inColor, outColor, inValues, outValues) { if (conversion == null) { throw new ArgumentNullException(nameof(conversion)); } this.conversion = conversion; }
public OneNumber(IDoubleInputToken t, ConversionDelegate convertToken) { _token = t; _convert = convertToken; if (_token is DoubleToken) { _result = _convert(GetValue(null).First()); } }
protected Conversion(T Color1, U Color2) { this.Color1 = Color1; this.Color2 = Color2; var types = Assembly.GetAssembly(typeof(ConversionPath)).GetTypes(); var paths = (from t in types where t.IsSubclassOf(typeof(ConversionPath)) && !t.IsAbstract select t).ToArray(); int c = 0; for (int i = 0; i < paths.Length; i++) { var args = paths[i].BaseType.GetGenericArguments(); if (args.Length == 2) { if (args[0] == typeof(U) && args[1] == typeof(T)) { ConvToT = GetDelegate(paths[i]); if (ConvToT == null) { ConvToTEx = GetDelegateEx(paths[i]); IsConversionEx = true; } c++; } else if (args[0] == typeof(T) && args[1] == typeof(U)) { ConvToU = GetDelegate(paths[i]); if (ConvToU == null) { ConvToUEx = GetDelegateEx(paths[i]); IsConversionEx = true; } c++; } if (c == 2) { break; } } } if (IsConversionEx && (ConvToUEx == null || ConvToTEx == null)) { throw new MissingMethodException(); } else if (!IsConversionEx && (ConvToU == null || ConvToT == null)) { throw new MissingMethodException(); } }
public Range(IDoubleInputToken start, IDoubleInputToken step, IDoubleInputToken end, ConversionDelegate convertToken) { _start = start; _step = step; _end = end; _convert = convertToken; if (_start is DoubleToken && _step is DoubleToken && _end is DoubleToken) { _result = GetValue(null); } }
public Sequence(IDoubleInputToken start, IDoubleInputToken step, IDoubleInputToken count, ConversionDelegate convertToken) { _start = start; _step = step; _count = count; _convert = convertToken; if (_start is DoubleToken && _step is DoubleToken && _count is DoubleToken) { _result = GetValue(null); } }
private void PerformConversion(string[] files) { if (InvokeRequired) { ConversionDelegate d = PerformConversion; Invoke(d, new object[] { files }); } else { SetUIConverting(true); ConvertFiles(files); } }
public OneNumber(IDoubleInputToken t, ConversionDelegate convertToken) { _token = t; _convert = convertToken; if (_token is DoubleToken) _result = _convert(GetValue(null).First()); }
public ApproxRange(IDoubleInputToken start, IDoubleInputToken step, IDoubleInputToken end, ConversionDelegate convertToken) : base(start, step, end, convertToken) { }
public CountRange(IDoubleInputToken startToken, IDoubleInputToken countToken, IDoubleInputToken endToken, ConversionDelegate convertToken) : base(startToken, countToken, endToken, convertToken) { }
public static List<IDoubleSequence> ParseValue(string text, char[] seps, List<string> identifiers, ConversionDelegate convertToken) { var idSet = new HashSet<string>(identifiers); return text.Replace(" ", "").Split(seps, StringSplitOptions.RemoveEmptyEntries).Select( delegate(string x) { var rangeIdentifiers = x.Split( Sublists.RangeSeparatorTokens, StringSplitOptions.RemoveEmptyEntries).Select(s => s.Trim()).ToArray(); if (rangeIdentifiers.Length > 3) throw new Exception("Bad range syntax: not of format \"start..end[..(increment|#count)]\""); if (rangeIdentifiers.Length == 0) throw new Exception("No identifiers found."); IDoubleInputToken startToken = ParseToken(rangeIdentifiers[0], idSet, identifiers); if (rangeIdentifiers.Length > 1) { if (rangeIdentifiers[1].StartsWith("#")) { var countToken = rangeIdentifiers[1].Substring(1); IDoubleInputToken endToken = ParseToken(countToken, idSet, identifiers); if (rangeIdentifiers.Length > 2) { if (rangeIdentifiers[2].StartsWith("#") || rangeIdentifiers[2].StartsWith("~")) throw new Exception("Cannot use range or approx. identifier on increment field when one has already been used to specify a count."); return new Sequence(startToken, ParseToken(rangeIdentifiers[2], idSet, identifiers), endToken, convertToken); } return new Sequence(startToken, new DoubleToken(1), endToken, convertToken) as IDoubleSequence; } else { IDoubleInputToken endToken = ParseToken(rangeIdentifiers[1], idSet, identifiers); if (rangeIdentifiers.Length > 2) { if (rangeIdentifiers[2].StartsWith("#")) { var count = rangeIdentifiers[2].Substring(1); IDoubleInputToken countToken = ParseToken(count, idSet, identifiers); return new CountRange(startToken, countToken, endToken, convertToken); } if (rangeIdentifiers[2].StartsWith("~")) { var approx = rangeIdentifiers[2].Substring(1); IDoubleInputToken approxToken = ParseToken(approx, idSet, identifiers); return new ApproxRange(startToken, approxToken, endToken, convertToken); } return new Range(startToken, ParseToken(rangeIdentifiers[2], idSet, identifiers), endToken, convertToken); } return new Range(startToken, new DoubleToken(1), endToken, convertToken) as IDoubleSequence; } } return new OneNumber(startToken, convertToken) as IDoubleSequence; }).ToList(); }
public static List <IDoubleSequence> ParseValue(string text, char[] seps, List <string> identifiers, ConversionDelegate convertToken) { var idSet = new HashSet <string>(identifiers); var doubleSequenceList = text.Replace(" ", "") .Split(seps, StringSplitOptions.RemoveEmptyEntries) .Select(x => new OneNumber(ParseToken(x, idSet, identifiers), convertToken) as IDoubleSequence) .ToList(); return(doubleSequenceList); }
public static List <IDoubleSequence> ParseValue(string text, char[] seps, List <string> identifiers, ConversionDelegate convertToken) { var idSet = new HashSet <string>(identifiers); return(text.Replace(" ", "").Split(seps, StringSplitOptions.RemoveEmptyEntries).Select( delegate(string x) { var rangeIdentifiers = x.Split( RangeSeparatorTokens, StringSplitOptions.RemoveEmptyEntries).Select(s => s.Trim()).ToArray(); if (rangeIdentifiers.Length > 3) { throw new Exception("Bad range syntax: not of format \"start..end[..(increment|#count)]\""); } if (rangeIdentifiers.Length == 0) { throw new Exception("No identifiers found."); } IDoubleInputToken startToken = ParseToken(rangeIdentifiers[0], idSet, identifiers); if (rangeIdentifiers.Length > 1) { if (rangeIdentifiers[1].StartsWith("#")) { var countToken = rangeIdentifiers[1].Substring(1); IDoubleInputToken endToken = ParseToken(countToken, idSet, identifiers); if (rangeIdentifiers.Length > 2) { if (rangeIdentifiers[2].StartsWith("#") || rangeIdentifiers[2].StartsWith("~")) { throw new Exception("Cannot use range or approx. identifier on increment field when one has already been used to specify a count."); } return new Sequence(startToken, ParseToken(rangeIdentifiers[2], idSet, identifiers), endToken, convertToken); } return new Sequence(startToken, new DoubleToken(1), endToken, convertToken) as IDoubleSequence; } else { IDoubleInputToken endToken = ParseToken(rangeIdentifiers[1], idSet, identifiers); if (rangeIdentifiers.Length > 2) { if (rangeIdentifiers[2].StartsWith("#")) { var count = rangeIdentifiers[2].Substring(1); IDoubleInputToken countToken = ParseToken(count, idSet, identifiers); return new CountRange(startToken, countToken, endToken, convertToken); } if (rangeIdentifiers[2].StartsWith("~")) { var approx = rangeIdentifiers[2].Substring(1); IDoubleInputToken approxToken = ParseToken(approx, idSet, identifiers); return new ApproxRange(startToken, approxToken, endToken, convertToken); } return new Range(startToken, ParseToken(rangeIdentifiers[2], idSet, identifiers), endToken, convertToken); } double identifierValue0, identifierValue1; var canBeParsed0 = System.Double.TryParse(rangeIdentifiers[0], out identifierValue0); var canBeParsed1 = System.Double.TryParse(rangeIdentifiers[1], out identifierValue1); //both of the value can be parsed as double if (canBeParsed0 && canBeParsed1) { if (identifierValue0 < identifierValue1) { return new Range(startToken, new DoubleToken(1), endToken, convertToken) as IDoubleSequence; } else { return new Range(startToken, new DoubleToken(-1), endToken, convertToken) as IDoubleSequence; } } //the input cannot be parsed as double, return a default function and let it handle the error return new Range(startToken, new DoubleToken(1), endToken, convertToken) as IDoubleSequence; } } return new OneNumber(startToken, convertToken) as IDoubleSequence; }).ToList()); }