本文整理汇总了C#中System.Net.ServicePoint.GetType方法的典型用法代码示例。如果您正苦于以下问题:C# ServicePoint.GetType方法的具体用法?C# ServicePoint.GetType怎么用?C# ServicePoint.GetType使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Net.ServicePoint
的用法示例。
在下文中一共展示了ServicePoint.GetType方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: PrintServicePointConnections
private void PrintServicePointConnections(ServicePoint sp) {
var spType = sp.GetType();
var privateOrPublicInstanceField = BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance;
var connectionGroupField = spType.GetField("m_ConnectionGroupList",privateOrPublicInstanceField);
var value = (Hashtable)connectionGroupField.GetValue(sp);
var connectionGroups = value.Keys.Cast<object>().ToList();
var totalConnections = 0;
Output("ServicePoint: {0} (Connection Limit: {1}, Reported connections: {2})", sp.Address,sp.ConnectionLimit,sp.CurrentConnections);
foreach(var key in connectionGroups) {
var connectionGroup = value[key];
var groupType = connectionGroup.GetType();
var listField = groupType.GetField("m_ConnectionList",privateOrPublicInstanceField);
var listValue = (ArrayList)listField.GetValue(connectionGroup);
//Console.WriteLine("{3} {0}\nConnectionGroup: {1} Count: {2}",sp.Address, key,listValue.Count, DateTime.Now);
Output("{0}", key);
totalConnections+=listValue.Count;
}
Output("ConnectionGroupCount: {0}, Total Connections: {1}", connectionGroups.Count, totalConnections);
}
示例2: PrintServicePointConnections
private ServicePointStatusServicePoint PrintServicePointConnections(ServicePoint sp)
{
var spType = sp.GetType();
var privateOrPublicInstanceField = BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance;
var connectionGroupField = spType.GetField("m_ConnectionGroupList", privateOrPublicInstanceField);
var value = (Hashtable)connectionGroupField.GetValue(sp);
var connectionGroups = value.Keys.Cast<object>().ToList();
var servicePointStatus = new ServicePointStatusServicePoint
{
Address = sp.Address,
ConnectionLimit = sp.ConnectionLimit,
CurrentConnection = sp.CurrentConnections,
ConnectionGroupCount = connectionGroups.Count,
TotalConnections = 0
};
foreach (var key in connectionGroups)
{
var connectionGroup = value[key];
var groupType = connectionGroup.GetType();
var listField = groupType.GetField("m_ConnectionList", privateOrPublicInstanceField);
var listValue = (ArrayList)listField.GetValue(connectionGroup);
//Console.WriteLine("{3} {0}\nConnectionGroup: {1} Count: {2}",sp.Address, key,listValue.Count, DateTime.Now);
servicePointStatus.ConnectionGroups.Add(new ServicePointStatusConnectionGroup
{
Key = key,
Count = listValue.Count
});
servicePointStatus.TotalConnections += listValue.Count;
}
return servicePointStatus;
}