本文整理汇总了C#中Converter类的典型用法代码示例。如果您正苦于以下问题:C# Converter类的具体用法?C# Converter怎么用?C# Converter使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Converter类属于命名空间,在下文中一共展示了Converter类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: MenuHandler
public void MenuHandler(Converter<ThreadItem, object> selector, MenuItem menu, PopupTargetInfo pti)
{
using (ViewList vl = this.js.ViewList())
using (DisposableList<ViewItem> views = new DisposableList<ViewItem>(vl))
using (DisposableList<ThreadItem> threads = new DisposableList<ThreadItem>()) {
//スレッドを抽出
foreach (ViewItem view in views) {
ThreadItem t = view.Thread();
if (t != null) threads.Add(t);
}
//スレッドを全部閉じる
foreach (ThreadItem t in threads) {
this.js.Close(t);
}
//スレッドのソートキー取得
List<ThreadKeyPair> pairs = new List<ThreadKeyPair>(threads.Count);
foreach (ThreadItem t in threads) {
pairs.Add(new ThreadKeyPair() {
Thread = t,
SortKey = (IComparable)selector(t),
});
}
//スレッドソート
if (this.ascending) {
pairs.Sort(this.AscendingComparison);
} else {
pairs.Sort(this.DescendingComparison);
}
//全部開く
foreach (var p in pairs) {
this.js.Open(p.Thread, 0, OpenOperation.Local, true, false, true);
}
}
}
示例2: Text
public Text(Converter converter)
: base(converter)
{
/*
this._escapedKeyChars.Add("\\",@"\\");
this._escapedKeyChars.Add("`",@"\`");
this._escapedKeyChars.Add("*",@"\*");
this._escapedKeyChars.Add("_",@"\_");
this._escapedKeyChars.Add("{",@"\{");
this._escapedKeyChars.Add("}",@"\}");
this._escapedKeyChars.Add("[",@"\[");
this._escapedKeyChars.Add("]",@"\]");
this._escapedKeyChars.Add("(",@"\)");
this._escapedKeyChars.Add("#",@"\#");
this._escapedKeyChars.Add("+",@"\+");
this._escapedKeyChars.Add("-",@"\-");
this._escapedKeyChars.Add(".",@"\.");
this._escapedKeyChars.Add("!",@"\!");
*/
this._escapedKeyChars.Add("*", @"\*");
this._escapedKeyChars.Add("_", @"\_");
this.Converter.Register("#text", this);
}
示例3: Execute
public void Execute(IGraphDS myGraphDS, long myIterations, Converter.WriteLineToConsole MyWriteLine)
{
var transactionID = myGraphDS.BeginTransaction(null);
var vertexType = myGraphDS.GetVertexType<IVertexType>(null, transactionID, new RequestGetVertexType("City"), (stats, vType) => vType);
var inCountryProperty = vertexType.GetOutgoingEdgeDefinition("InCountry");
var nameProperty = vertexType.GetPropertyDefinition("Name");
List<double> timeForCityCountryTraversal = new List<double>();
for (int i = 0; i < myIterations; i++)
{
Stopwatch sw = Stopwatch.StartNew();
foreach (var aCity in myGraphDS.GetVertices<IEnumerable<IVertex>>(null, transactionID, new RequestGetVertices("City"), (stats, v) => v))
{
var UK_Vertex = aCity.GetOutgoingSingleEdge(inCountryProperty.ID).GetTargetVertex();
}
sw.Stop();
timeForCityCountryTraversal.Add(sw.Elapsed.TotalMilliseconds);
}
myGraphDS.CommitTransaction(null, transactionID);
String result = GenerateTable(timeForCityCountryTraversal) + Environment.NewLine + String.Format("Average: {0}ms Median: {1}ms StandardDeviation {2}ms ", Statistics.Average(timeForCityCountryTraversal), Statistics.Median(timeForCityCountryTraversal), Statistics.StandardDeviation(timeForCityCountryTraversal));
Console.WriteLine(result);
MyWriteLine(result);
}
示例4: Convert
/// <summary>
/// 将value转换为目标类型
/// 并将转换所得的值放到result
/// 如果不支持转换,则返回false
/// </summary>
/// <param name="converter">转换器实例</param>
/// <param name="value">要转换的值</param>
/// <param name="targetType">转换的目标类型</param>
/// <param name="result">转换结果</param>
/// <returns>如果不支持转换,则返回false</returns>
public virtual bool Convert(Converter converter, object value, Type targetType, out object result)
{
var dic = value as IDictionary<string, object>;
if (dic == null)
{
result = null;
return false;
}
var instance = Activator.CreateInstance(targetType);
var setters = PropertySetter.GetPropertySetters(targetType);
foreach (var set in setters)
{
var key = dic.Keys.FirstOrDefault(k => string.Equals(k, set.Name, StringComparison.OrdinalIgnoreCase));
if (key != null)
{
var targetValue = converter.Convert(dic[key], set.Type);
set.SetValue(instance, targetValue);
}
}
result = instance;
return true;
}
示例5: BusinessCreateLight
public object BusinessCreateLight(List<BusinessLight> businesses, Converter converter, object dataObject)
{
DataTable dt = new DataTable();
dt.Columns.Add("ExternalId", typeof(string));
dt.Columns.Add("BusinessId", typeof(int));
dt.Columns.Add("GenderFCheckIns", typeof(int));
dt.Columns.Add("GenderMCheckIns", typeof(int));
Random rnd = new Random();
int icount = 0;
businesses.ForEach(x =>
{
DataRow dr = dt.NewRow();
dr["ExternalId"] = x.ExternalID;
dr["BusinessId"] = rnd.Next();
dr["GenderFCheckIns"] = icount;
dr["GenderMCheckIns"] = icount;
icount = icount + 10;
dt.Rows.Add(dr);
});
DataTableReader dtr = dt.CreateDataReader();
while(dtr.Read())
{
converter(dtr, dataObject);
}
//dt.Select().ToList().ForEach(x=> converter(x,dataObject));
return dt;
}
示例6: BusinessGetByLocation
public object BusinessGetByLocation(string latitude, string longitude,string distance, Converter converter, object dataObject)
{
// returns the externalid, internalid and the count
using (DBAccess dbaccess = new DBAccess())
{
SqlParameter parameter1 = new SqlParameter();
parameter1.ParameterName = "@latitude";
parameter1.SqlDbType = SqlDbType.Float;
parameter1.Value = latitude;
SqlParameter parameter2 = new SqlParameter();
parameter2.ParameterName = "@longitude";
parameter2.SqlDbType = SqlDbType.Float;
parameter2.Value = longitude;
SqlParameter parameter3 = new SqlParameter();
parameter3.ParameterName = "@distance";
parameter3.SqlDbType = SqlDbType.Int;
parameter3.Value = distance;
SqlParameter[] parameters = new SqlParameter[3] { parameter1, parameter2, parameter3 };
SqlDataReader reader = dbaccess.ExecuteProcedure("BusinessByLocationGet", this.sConn, parameters);
while (reader.Read())
{
converter(reader, dataObject);
}
}
return dataObject;
}
示例7: AndroidPlatform
static AndroidPlatform ()
{
var t = Type.GetType ("Android.Runtime.AndroidEnvironment, Mono.Android", throwOnError:true);
#if SECURITY_DEP
trustEvaluateSsl = (Converter<List<byte[]>, bool>)
Delegate.CreateDelegate (typeof (Converter<List<byte[]>, bool>),
t,
"TrustEvaluateSsl",
ignoreCase:false,
throwOnBindFailure:true);
#endif // SECURITY_DEP
getDefaultProxy = (Func<IWebProxy>)Delegate.CreateDelegate (
typeof (Func<IWebProxy>), t, "GetDefaultProxy",
ignoreCase:false,
throwOnBindFailure:true);
getInterfaceAddresses = (GetInterfaceAddressesDelegate)Delegate.CreateDelegate (
typeof (GetInterfaceAddressesDelegate), t, "GetInterfaceAddresses",
ignoreCase: false,
throwOnBindFailure: false);
freeInterfaceAddresses = (FreeInterfaceAddressesDelegate)Delegate.CreateDelegate (
typeof (FreeInterfaceAddressesDelegate), t, "FreeInterfaceAddresses",
ignoreCase: false,
throwOnBindFailure: false);
}
示例8: Convert
/// <summary>
/// 将value转换为目标类型
/// 并将转换所得的值放到result
/// 如果不支持转换,则返回false
/// </summary>
/// <param name="converter">转换器实例</param>
/// <param name="value">要转换的值</param>
/// <param name="targetType">转换的目标类型</param>
/// <param name="result">转换结果</param>
/// <returns>如果不支持转换,则返回false</returns>
public virtual bool Convert(Converter converter, object value, Type targetType, out object result)
{
var valueString = value.ToString();
if (targetType.IsEnum == true)
{
result = Enum.Parse(targetType, valueString, true);
return true;
}
var convertible = value as IConvertible;
if (convertible != null && typeof(IConvertible).IsAssignableFrom(targetType) == true)
{
result = convertible.ToType(targetType, null);
return true;
}
if (typeof(Guid) == targetType)
{
result = Guid.Parse(valueString);
return true;
}
else if (typeof(string) == targetType)
{
result = valueString;
return true;
}
result = null;
return false;
}
示例9: XmlSerializer
public XmlSerializer()
{
Culture = Framework.CultureInfo;
TypeInstantiator = Framework.TypeInstantiator;
//Converter = Framework.Converter;
Converter = new Converter(TypeInstantiator);
}
示例10: BusinessCreateLight
public object BusinessCreateLight(List<BusinessLight> businesses, Converter converter, object dataObject)
{
// returns the externalid, internalid and the count
DataTable businessDT = new DataTable("BusinessLight");
businessDT.Columns.Add("ExternalId", typeof(string));
businessDT.Columns.Add("SourceId", typeof(Int32));
businesses.ForEach(x =>
{
DataRow dr = businessDT.NewRow();
dr[0] = x.ExternalID;
dr[1] = x.Source;
businessDT.Rows.Add(dr);
});
using (DBAccess dbaccess = new DBAccess())
{
SqlParameter parameter = new SqlParameter();
parameter.ParameterName = "@BusinessLight";
parameter.SqlDbType = SqlDbType.Structured;
parameter.Value = businessDT;
SqlParameter[] parameters = new SqlParameter[1] { parameter };
SqlDataReader reader = dbaccess.ExecuteProcedure("CreateBusinessLight", this.sConn, parameters);
while (reader.Read())
{
converter(reader, dataObject);
}
}
return dataObject;
}
示例11: TestWebmConversion
public void TestWebmConversion()
{
Converter converter = new Converter();
ConvertSettings VideoSettings = new ConvertSettings();
bool result = converter.ConvertFile(currentPath + "\\SampleVideo.mp4", 7, 1, false, VideoSettings);
Assert.AreEqual(true, result);
}
示例12: Convert
/// <summary>
/// 将value转换为目标类型
/// 并将转换所得的值放到result
/// 如果不支持转换,则返回false
/// </summary>
/// <param name="converter">转换器实例</param>
/// <param name="value">要转换的值</param>
/// <param name="targetType">转换的目标类型</param>
/// <param name="result">转换结果</param>
/// <returns>如果不支持转换,则返回false</returns>
public virtual bool Convert(Converter converter, object value, Type targetType, out object result)
{
var dynamicObject = value as DynamicObject;
if (dynamicObject == null)
{
result = null;
return false;
}
var instance = Activator.CreateInstance(targetType);
var setters = PropertySetter.GetPropertySetters(targetType);
foreach (var set in setters)
{
object targetValue;
if (this.TryGetValue(dynamicObject, set.Name, out targetValue) == true)
{
targetValue = converter.Convert(targetValue, set.Type);
set.SetValue(instance, targetValue);
}
}
result = instance;
return true;
}
示例13: When_given_expr_refers_object_array_return_multiple_rows_with_multiple_columns_based_on_first_row
public void When_given_expr_refers_object_array_return_multiple_rows_with_multiple_columns_based_on_first_row()
{
var searchResult = JSONQuery.GetValue(jsonTestData, "Messages.Receives");
Converter converter = new Converter();
var data = converter.ConvertToRecord(searchResult);
Assert.AreEqual(data.Length, 3, "Wrong number of results");
Assert.AreEqual(data[0].FieldCount, 3, "Wrong field count of result");
// Validate column names
Assert.AreEqual(data[0].GetName(0), "Content", "1. field has invalid name");
Assert.AreEqual(data[0].GetName(1), "SendDate", "2. field has invalid name");
Assert.AreEqual(data[0].GetName(2), "AttachmentCount", "3. field has invalid name");
// 1. row data validation
Assert.AreEqual(data[0].GetString(0), "Great you?", "Invalid data on 1. column of 1. row");
Assert.AreEqual(data[0].GetDateTime(1), new DateTime(2013, 1, 21), "Invalid data on 2. column of 1. row");
Assert.AreEqual(data[0].GetDouble(2), 0, "Invalid data on 3. column of on 1. row");
// 2. row data validation
Assert.AreEqual(data[1].GetString(0), "Ok bye", "Invalid data on 1. column of 2. row");
Assert.AreEqual(data[1].GetDateTime(1), new DateTime(2013, 1, 25), "Invalid data on 2. column of 2. row");
Assert.AreEqual(data[1].GetDouble(2), 1, "Invalid data on 3. column of on 2. row");
// 3. row data validation
Assert.AreEqual(data[2].GetString(0), "Fine. Nothing new yet! You?", "Invalid data on 1. column of 3. row");
Assert.AreEqual(data[2].GetDateTime(1), new DateTime(2013, 3, 12), "Invalid data on 2. column of 3. row");
Assert.IsTrue(data[2].GetSqlDouble(2).IsNull, "Invalid data on 3. column of on 3. row");
}
示例14: FromSearchCriteria
/// <summary>
/// Extracts a list of <see cref="HqlCondition"/> objects from the specified <see cref="SearchCriteria"/>
/// </summary>
/// <param name="qualifier">The HQL qualifier to prepend to the criteria variables</param>
/// <param name="criteria">The search criteria object</param>
/// <param name="remapHqlExprFunc"></param>
/// <returns>A list of HQL conditions that are equivalent to the search criteria</returns>
public static HqlCondition[] FromSearchCriteria(string qualifier, SearchCriteria criteria, Converter<string, string> remapHqlExprFunc)
{
var hqlConditions = new List<HqlCondition>();
if (criteria is SearchConditionBase)
{
var sc = (SearchConditionBase)criteria;
if (sc.Test != SearchConditionTest.None)
{
hqlConditions.Add(GetCondition(remapHqlExprFunc(qualifier), sc.Test, sc.Values));
}
}
else
{
// recur on subCriteria
foreach (var subCriteria in criteria.EnumerateSubCriteria())
{
// use a different syntax for "extended properties" than regular properties
var subQualifier = criteria is ExtendedPropertiesSearchCriteria ?
string.Format("{0}['{1}']", qualifier, subCriteria.GetKey()) :
string.Format("{0}.{1}", qualifier, subCriteria.GetKey());
hqlConditions.AddRange(FromSearchCriteria(subQualifier, subCriteria, remapHqlExprFunc));
}
}
return hqlConditions.ToArray();
}
示例15: LoginCreate
public void LoginCreate(string userName, string password, SourceType UserSourceType, string ExternalID, Converter converter, object dataObject)
{
using (DBAccess dbaccess = new DBAccess())
{
SqlParameter parameter1 = new SqlParameter();
parameter1.ParameterName = "@UserName";
parameter1.Value = userName;
parameter1.SqlDbType = SqlDbType.VarChar;
SqlParameter parameter2 = new SqlParameter();
parameter2.ParameterName = "@UserPassword";
parameter2.Value = password;
parameter2.SqlDbType = SqlDbType.VarChar;
SqlParameter parameter3 = new SqlParameter();
parameter3.ParameterName = "@ExternalID";
parameter3.Value = ExternalID;
parameter3.SqlDbType = SqlDbType.NVarChar;
SqlParameter parameter4 = new SqlParameter();
parameter4.ParameterName = "@SourceID";
parameter4.Value = UserSourceType;
parameter4.SqlDbType = SqlDbType.Int;
SqlParameter[] parameters = new SqlParameter[4] { parameter1, parameter2, parameter3, parameter4 };
SqlDataReader reader = dbaccess.ExecuteProcedure("LoginCreate", this.connectionString, parameters);
while (reader.Read())
{
converter(reader, dataObject);
}
}
}