/// <summary></summary> /// <param name="start"></param> /// <param name="count"></param> /// <param name="selector"></param> /// <returns></returns> public IEnumerator <DELogLine> GetEnumerator(int start, int count, IPropertyReadOnlyDictionary selector) { // create selector if (selector != null) { //throw new NotImplementedException(); } // find the range to search in var idxFrom = start >> 5; var idxFromOffset = start & 0x1F; string lineData; var i = 0; logData.Seek(linesOffsetCache[idxFrom], SeekOrigin.Begin); using (var sr = new StreamReader(logData, Encoding.Default, false, 4096, true)) { while (i < count && (lineData = sr.ReadLine()) != null) { if (idxFromOffset > 0) { idxFromOffset--; } else { yield return(new DELogLine(lineData)); i++; } } } } // func GetEnumerator
} // func TryGetProperty /// <summary>Versucht einen Paremter zurückzugeben.</summary> /// <typeparam name="T">Rückgabewert.</typeparam> /// <param name="name">Parametername.</param> /// <param name="value">Wert der abgelegt wurde.</param> /// <returns><c>true</c>, wenn ein Wert gefunden wurde.</returns> public static bool TryGetProperty <T>(this IPropertyReadOnlyDictionary propertyDictionary, string name, out T value) { object ret; if (propertyDictionary.TryGetProperty(name, out ret) && ret != null) { try { if (ret is T) { value = (T)ret; } else { value = (T)Procs.ChangeType(ret, typeof(T)); } return(true); } catch (FormatException) { } } value = default(T); return(false); } // func TryGetProperty
} // func Add /// <summary>Implement a add method, that supports a LuaTable as argument.</summary> /// <param name="values">Values for the new row.</param> /// <returns>Added row.</returns> public PpsDataRow Add(IPropertyReadOnlyDictionary values) { var row = DataView.NewRow(DataView.Table.GetDataRowValues(values), null); AddNewItem(row); return(row); } // func Add
public LuaPropertiesTable(IPropertyReadOnlyDictionary properties) { if (properties == null) { throw new ArgumentNullException("properties"); } this.properties = properties; } // ctor
#pragma warning restore CS1591 // Missing XML comment for publicly visible type or member #region -- WriteProperty -------------------------------------------------------- /// <summary></summary> /// <param name="xml"></param> /// <param name="attributes"></param> /// <param name="propertyName"></param> /// <param name="targetPropertyName"></param> public static void WriteProperty(this XmlWriter xml, IPropertyReadOnlyDictionary attributes, string propertyName, string targetPropertyName = null) { var value = attributes.GetProperty <string>(propertyName, null); if (value == null) { return; } xml.WriteAttributeString(targetPropertyName ?? propertyName, value); } // proc WriteProperty
} // proc WriteList private static void WriteList <T>(IPropertyReadOnlyDictionary r, XmlWriter xml, IDEListDescriptor descriptor, IList <T> list, int startAt, int count) { WriteListCheckRange(xml, ref startAt, ref count, list.Count, false); if (count > 0) { var end = startAt + count; for (int i = startAt; i < end; i++) { descriptor.WriteItem(new DEListItemWriter(xml), (T)list[i]); } } } // proc WriteList
} // func GetPropertyLate /// <summary>Versucht einen Paremter zurückzugeben.</summary> /// <param name="name">Parametername.</param> /// <param name="value">Wert der abgelegt wurde.</param> /// <returns><c>true</c>, wenn ein Wert gefunden wurde.</returns> public static bool TryGetProperty(this IPropertyReadOnlyDictionary propertyDictionary, string name, out string value) { object ret; if (propertyDictionary.TryGetProperty(name, out ret) && ret != null) { value = ret.ToString(); return(true); } else { value = String.Empty; return(false); } } // func TryGetProperty
} // func TryMatchRegex public static void UpdateRange(Excel.Range range, Type baseCellType, IPropertyReadOnlyDictionary attributes) { if (range == null) { throw new ArgumentNullException(nameof(range)); } if (attributes == null) { throw new ArgumentNullException(nameof(attributes)); } baseCellType = baseCellType ?? typeof(object); // set number format if (attributes.TryGetProperty("xl.format", out string tmp)) { range.NumberFormat = tmp; } else if (attributes.TryGetProperty("format", out tmp)) { range.NumberFormat = ConvertNetToExcelFormat(baseCellType, tmp, CultureInfo.CurrentUICulture); } // set alignment if (attributes.TryGetProperty("halign", out tmp)) { range.HorizontalAlignment = GetAlignment(true, tmp); } if (attributes.TryGetProperty("valign", out tmp)) { range.HorizontalAlignment = GetAlignment(false, tmp); } //range.Borders //range.ColumnWidth; //range.RowHeight = 15; //range.ShrinkToFit; //range.WrapText = false; //range.Orientation; //range.AddIndent; //range.IndentLevel; } // func UpdateRange
} // class GenericWriter #endregion private void WriteListFetchTyped(Type type, IPropertyReadOnlyDictionary r, XmlWriter xml, IDEListDescriptor descriptor, object list, int startAt, int count) { Type typeGeneric = type.GetGenericTypeDefinition(); // Hole den generischen Typ ab // Suche die passende procedure var miWriteList = typeof(GenericWriter).GetTypeInfo().DeclaredMethods.Where(mi => mi.IsStatic && mi.Name == "WriteList" && mi.IsGenericMethodDefinition && mi.GetParameters()[3].ParameterType.Name == typeGeneric.Name).FirstOrDefault(); if (miWriteList == null) { throw new ArgumentNullException("writelist", String.Format("Keinen generische Implementierung gefunden ({0}).", typeGeneric.FullName)); } // Aufruf des Writers var typeDelegate = typeof(Action <, , , , ,>).MakeGenericType(typeof(IPropertyReadOnlyDictionary), typeof(XmlWriter), typeof(IDEListDescriptor), type, typeof(int), typeof(int)); var miWriteListTyped = miWriteList.MakeGenericMethod(type.GetTypeInfo().GenericTypeArguments[0]); var dlg = Delegate.CreateDelegate(typeDelegate, miWriteListTyped); dlg.DynamicInvoke(r, xml, descriptor, list, startAt, count); } // proc WriteListFetchListTyped
} // proc WriteList private static void WriteList <T>(IPropertyReadOnlyDictionary r, XmlWriter xml, IDEListDescriptor descriptor, IDERangeEnumerable2 <T> list, int startAt, int count) { WriteListCheckRange(xml, ref startAt, ref count, list.Count, true); if (count > 0) { using (var enumerator = list.GetEnumerator(startAt, count, r)) { while (count > 0) { if (!enumerator.MoveNext()) { break; } descriptor.WriteItem(new DEListItemWriter(xml), enumerator.Current); count--; } } } } // proc WriteList
} // func GetProperty /// <summary>Gibt einen Parameter zurück.</summary> /// <typeparam name="T">Rückgabewert.</typeparam> /// <param name="name">Parametername.</param> /// <param name="def">Defaultwert, falls der Wert nicht ermittelt werden konnte.</param> /// <returns>Abgelegter Wert oder der Default-Wert.</returns> public static T GetPropertyLate <T>(this IPropertyReadOnlyDictionary propertyDictionary, string name, Func <T> @default) { T r; return(propertyDictionary.TryGetProperty(name, out r) ? r : @default()); } // func GetPropertyLate
} // func GetProperty /// <summary>Gibt einen Parameter zurück.</summary> /// <param name="name">Parametername.</param> /// <param name="default">Defaultwert, falls der Wert nicht ermittelt werden konnte.</param> /// <returns>Abgelegter Wert oder der Default-Wert.</returns> public static string GetProperty(this IPropertyReadOnlyDictionary propertyDictionary, string name, string @default) { string r; return(propertyDictionary.TryGetProperty(name, out r) ? r : @default); } // func GetProperty