本文整理汇总了C#中IList.GetType方法的典型用法代码示例。如果您正苦于以下问题:C# IList.GetType方法的具体用法?C# IList.GetType怎么用?C# IList.GetType使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IList
的用法示例。
在下文中一共展示了IList.GetType方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CalculateTime
public static void CalculateTime(IList list, int k)
{
// Add
var startAdding = DateTime.Now;
string test = "Test string";
for (int i = 0; i < k; i++)
{
list.Add(test);
}
var finishAdding = DateTime.Now;
Console.WriteLine("Addition time (" + k + " elements) : " + list.GetType() + " " + (finishAdding - startAdding));
// Search
var startSearch = DateTime.Now;
for (int i = 0; i < k; i++)
{
bool a = list.Contains(test);
}
var finishSearch = DateTime.Now;
Console.WriteLine("Search time (" + k + " elements) : " + list.GetType() + " " + (finishSearch - startSearch));
// Remove
k = 1000;
var startRemoving = DateTime.Now;
for (int i = 0; i < k; i++)
{
list.Remove(test);
}
var finishRemoving = DateTime.Now;
Console.WriteLine("Removal time (" + k + " elements) : " + list.GetType() + " " + (finishRemoving - startRemoving) + "\n");
}
示例2: OnItemsSourceChanged
protected virtual void OnItemsSourceChanged(IList oldValue, IList newValue)
{
if (newValue == null)
return;
if (ItemsSourceType == null)
ItemsSourceType = newValue.GetType();
if (ItemType == null)
ItemType = newValue.GetType().GetGenericArguments()[0];
if (newValue.Count > 0)
SetText(newValue);
}
示例3: IListTypeDefinitionFinder
public IListTypeDefinitionFinder(IList list)
{
if (list == null) throw new ArgumentNullException("list");
_listType = list.GetType();
SetListTypeUnderlyingType();
}
示例4: ToJsonR
public object ToJsonR(IList items, Style style = Style.Full)
{
var jsonR = new JsonR();
Type itemType = GetListItemType(items.GetType());
jsonR.Type = itemType.Name;
SplitKeyValues(items, jsonR.Keys, jsonR.Values);
switch (style)
{
case Style.Keys:
return jsonR.Keys;
case Style.Values:
return jsonR.Values;
case Style.Type:
return jsonR.Type;
case Style.Hint:
return new {jsonR.Type, jsonR.Values };
}
return jsonR;
}
示例5: GetClipboardTextFromIList
public static String GetClipboardTextFromIList(IList argList, CultureInfo argCultureInfo, Boolean argWithHeaders, String argCellSeparator)
{
// Create the StringBuilder
StringBuilder finalBuilder = new StringBuilder();
if (argWithHeaders)
{
foreach (PropertyInfo prop in argList.GetType().GetGenericArguments()[0].GetProperties())
{
finalBuilder.AppendFormat("{0}{1}", GetClipboardTextFromValueObject(prop.Name, argCultureInfo).Replace(argCellSeparator, String.Empty), argCellSeparator);
}
if (finalBuilder.Length > argCellSeparator.Length - 1)
{
finalBuilder.Length -= argCellSeparator.Length; //remove cell separator character
}
finalBuilder.Append("\r\n"); // add \r\n
}
foreach (Object item in argList)
{
finalBuilder.AppendFormat("{0}\r\n", GetClipboardTextFromObject(item, argCultureInfo, argCellSeparator)); // add \r\n
}
if (finalBuilder.Length > 1)
{
finalBuilder.Length -= 2; //remove \r\n character
}
return finalBuilder.ToString();
}
示例6: SerializeXml
//ArrayList openElements = new ArrayList();
public void SerializeXml(IList<StarSystem> starSystems)
{
MemoryStream memXmlStream = new MemoryStream();
XmlSerializer serializer = new XmlSerializer(starSystems.GetType(), null, new Type[] { typeof(Planet), typeof(StarSystem) }, new XmlRootAttribute("Stars"), null, null);
serializer.Serialize(memXmlStream, starSystems);
XmlDocument xmlDoc = new XmlDocument();
memXmlStream.Seek(0, SeekOrigin.Begin);
xmlDoc.Load(memXmlStream);
XmlProcessingInstruction newPI;
String PItext = string.Format("type='text/xsl' href='{0}'", "system.xslt");
newPI = xmlDoc.CreateProcessingInstruction("xml-stylesheet", PItext);
xmlDoc.InsertAfter(newPI, xmlDoc.FirstChild);
// Now write the document
// out to the final output stream
XmlTextWriter wr = new XmlTextWriter("system.xml", System.Text.Encoding.ASCII);
wr.Formatting = Formatting.Indented;
wr.IndentChar = '\t';
wr.Indentation = 1;
XmlWriterSettings settings = new XmlWriterSettings();
XmlWriter writer = XmlWriter.Create(wr, settings);
xmlDoc.WriteTo(writer);
writer.Flush();
//Console.Write(xmlDoc.InnerXml);
}
示例7: FindNew
public static IList<IDatabaseObject> FindNew(IList<IDatabaseObject> oldsource, IList<IDatabaseObject> newsource)
{
if (oldsource.GetType() != newsource.GetType())
throw new Exception("Die Datentypen müssen für einen Vergleich gleich sein.");
if (oldsource.Count < 1) return newsource;
List<IDatabaseObject> result = new List<IDatabaseObject>();
Type t = oldsource[0].GetType();
PropertyInfo i = t.GetProperty("ObjectID");
if(i != null)
foreach (IDatabaseObject a in newsource)
{
bool isContained = false;
foreach (IDatabaseObject b in oldsource)
{
int id1 = (int)i.GetValue(a, null);
int id2 = (int)i.GetValue(b, null);
if (id1 == id2)
{
isContained = true;
break;
}
}
if (!isContained) result.Add(a);
}
return result;
}
示例8: List2XML
/// <summary>
/// Metodo para serializar una Lista de objetos en un XML simple
/// </summary>
/// <param name="thelist"> la lista de tipo List<T> </param>
/// <returns></returns>
public static string List2XML(IList thelist)
{
string xml = "";
try
{
XmlSerializer xmlSer = new XmlSerializer(thelist.GetType());
StringWriterWithEncoding sWriter = new StringWriterWithEncoding(Encoding.UTF8);
XmlSerializerNamespaces xsn = new XmlSerializerNamespaces();
xsn.Add(String.Empty, "");
xmlSer.Serialize(sWriter, thelist, xsn);
xml = sWriter.ToString();
}
catch (Exception e)
{
}
return xml;
}
示例9: Apply
public static void Apply(this FilterScheme filterScheme, IEnumerable rawCollection, IList filteredCollection)
{
Argument.IsNotNull("filterScheme", filterScheme);
Argument.IsNotNull("rawCollection", rawCollection);
Argument.IsNotNull("filteredCollection", filteredCollection);
IDisposable suspendToken = null;
var filteredCollectionType = filteredCollection.GetType();
if (filteredCollectionType.IsGenericTypeEx() && filteredCollectionType.GetGenericTypeDefinitionEx() == typeof(FastObservableCollection<>))
{
suspendToken = (IDisposable)filteredCollectionType.GetMethodEx("SuspendChangeNotifications").Invoke(filteredCollection, null);
}
filteredCollection.Clear();
foreach (object item in rawCollection)
{
if (filterScheme.CalculateResult(item))
{
filteredCollection.Add(item);
}
}
if (suspendToken != null)
{
suspendToken.Dispose();
}
}
示例10: ListSource
public ListSource(DialogViewController controller, IList list, IEnumerable<Type> viewTypes) : base(controller)
{
Sections = new Dictionary<int, Section>();
var section = new Section(controller) { DataContext = list };
IList<Type> viewTypesList = null;
if (viewTypes != null)
viewTypesList = viewTypes.ToList();
var genericType = list.GetType().GetGenericArguments().FirstOrDefault();
CellId = new NSString(genericType.ToString());
section.ViewTypes.Add(CellId, viewTypesList);
Sections.Add(0, section);
SelectedItems = list.GetType().CreateGenericListFromEnumerable(null);
CellFactory = new TableCellFactory<UITableViewCell>(CellId);
//SelectionDisplayMode = SelectionDisplayMode.Collapsed;
//CollapsedList = new List<object>();
// foreach(var item in Sections[0].DataContext)
// {
// CollapsedList.Add(item);
// }
// Sections[0].DataContext.Clear();
//
//IsCollapsed = true;
}
示例11: ArrayAdapter
public ArrayAdapter(IValue array)
{
_array = array;
_list = array.ActualType.CreateGenericListInstance().As<IList>();
_listType = _list.GetType().ToCachedType();
_listType.InvokeAction("AddRange", _list, array.Instance);
}
示例12: CloneList
/// <summary>
/// Clones an IList object and returns a list with the same type as the original list.
/// </summary>
public static IList CloneList(IList list)
{
if (list == null)
return null;
var newList = Activator.CreateInstance(list.GetType()) as IList;
foreach (var item in list)
newList.Add(item);
return newList;
}
示例13: GetListElementsType
public static Type GetListElementsType(IList Collection)
{
if (Collection == null)
{
return null;
}
else
{
return Collection.GetType().GenericTypeArguments.Single();
}
}
示例14: SelectedItemsReflector
public SelectedItemsReflector(ListBox target, IList mirror)
{
if ((_target = target) == null) throw new ArgumentNullException("'target' cannot be null");
if ((_mirror = mirror) == null) throw new ArgumentNullException("'mirror' cannot be null");
var observable = _mirror as INotifyCollectionChanged;
if (observable == null) throw new ArgumentException(String.Format("'mirror' has to be an instance of {0}, but {1}", typeof(INotifyCollectionChanged), _mirror.GetType()));
_target.SelectionChanged -= SelectionChangedEventHandler;
_target.SelectedItems.Clear();
foreach (var item in _mirror) _target.SelectedItems.Add(item);
_target.SelectionChanged += SelectionChangedEventHandler;
observable.CollectionChanged += CollectionChangedEventHandler;
}
示例15: ListaDinamica
public static MvcHtmlString ListaDinamica(this HtmlHelper html, string id, IList lista)
{
string strLink = String.Format("<ul data-role=\"listview\" data-filter=\"true\" data-filter-placeholder=\"Buscar...\" data-inset=\"true\">");
PropertyInfo[] properties = lista.GetType().GetProperties();
foreach (PropertyInfo property in properties)
{
if (property.PropertyType.Name == "Categoria")
{
foreach (Entities.Categoria categoria in lista)
{
strLink += ("<li><a href=\"../Categoria/Editar/"+ categoria.Id.ToString() +"\">" + categoria.Nome.ToString() + "</a></li>");
}
}
}
strLink += ("</ul>");
return new MvcHtmlString(strLink);
}