当前位置: 首页>>代码示例>>C#>>正文


C# Converter类代码示例

本文整理汇总了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);
         }
     }
 }
开发者ID:ohtake,项目名称:janeview-scripts,代码行数:34,代码来源:ThreadSortComponent.cs

示例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);
		}
开发者ID:nashdot,项目名称:reversemarkdown-net,代码行数:25,代码来源:Text.cs

示例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);
        }
开发者ID:sones,项目名称:benchmark,代码行数:31,代码来源:SuperNodesBenchmark.cs

示例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;
        }
开发者ID:JackWangCUMT,项目名称:NetworkSocket,代码行数:35,代码来源:DictionaryConvert.cs

示例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;
        }
开发者ID:ragsden,项目名称:mynglz,代码行数:29,代码来源:YelpBusinessResource.cs

示例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;
        }
开发者ID:ragsden,项目名称:src,代码行数:32,代码来源:BusinessResource.cs

示例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);
		}
开发者ID:Profit0004,项目名称:mono,代码行数:26,代码来源:AndroidPlatform.cs

示例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;
        }
开发者ID:JackWangCUMT,项目名称:NetworkSocket,代码行数:40,代码来源:PrimitiveContert.cs

示例9: XmlSerializer

 public XmlSerializer()
 {
     Culture = Framework.CultureInfo;
     TypeInstantiator = Framework.TypeInstantiator;
     //Converter = Framework.Converter;
     Converter = new Converter(TypeInstantiator);
 }
开发者ID:LazyTarget,项目名称:Lux,代码行数:7,代码来源:XmlSerializer.cs

示例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;
        }
开发者ID:ragsden,项目名称:mynglz,代码行数:34,代码来源:BusinessResource.cs

示例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);
 }
开发者ID:Mbuckley0,项目名称:VideoConverter,代码行数:7,代码来源:ConversionTest.cs

示例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;
        }
开发者ID:JackWangCUMT,项目名称:NetworkSocket,代码行数:35,代码来源:DynamicObjectConvert.cs

示例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");
        }
开发者ID:JFelton,项目名称:JQSQL,代码行数:26,代码来源:DataConverter_Tests.cs

示例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();
		}
开发者ID:nhannd,项目名称:Xian,代码行数:34,代码来源:HqlCondition.cs

示例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);
                }

            }
        }
开发者ID:ragsden,项目名称:src,代码行数:35,代码来源:UserResource.cs


注:本文中的Converter类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。