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


C# Converter.Convert方法代码示例

本文整理汇总了C#中Converter.Convert方法的典型用法代码示例。如果您正苦于以下问题:C# Converter.Convert方法的具体用法?C# Converter.Convert怎么用?C# Converter.Convert使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Converter的用法示例。


在下文中一共展示了Converter.Convert方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: 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

示例2: 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

示例3: Converts

        public void Converts()
        {
            Converter converter = new Converter(new MarkdownWriter());

            string result = converter.Convert(Input);

            Approvals.Verify(result);
        }
开发者ID:appccelerate,项目名称:xBehaveMarkdownReport,代码行数:8,代码来源:Markdown.cs

示例4: CanConvert_JustHeading_To_NiceHtml

        public void CanConvert_JustHeading_To_NiceHtml()
        {
            var source = TestResources.JustHeadings;

            var converter = new Converter();

            var result = converter.Convert(source);

            Assert.Inconclusive();
        }
开发者ID:cleannote,项目名称:cleannote-csharp,代码行数:10,代码来源:Converter_Tests.cs

示例5: CanConvert_Heading_And_Formating_To_NiceHtml

        public void CanConvert_Heading_And_Formating_To_NiceHtml()
        {
            var source = TestResources.Headings_And_Formating;

            var converter = new Converter();

            var result = converter.Convert(source);

            Assert.Inconclusive();
        }
开发者ID:cleannote,项目名称:cleannote-csharp,代码行数:10,代码来源:Converter_Tests.cs

示例6: CanConvert_Borek01_To_NiceHtml

        public void CanConvert_Borek01_To_NiceHtml()
        {
            var source = TestResources.Borek01;

            var converter = new Converter();

            var result = converter.Convert(source);

            Assert.Inconclusive();
        }
开发者ID:cleannote,项目名称:cleannote-csharp,代码行数:10,代码来源:Converter_Tests.cs

示例7: 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)
        {
            if (targetType.IsGenericType && targetType.GetGenericTypeDefinition() == typeof(Nullable<>))
            {
                var genericArgument = targetType.GetGenericArguments().First();
                result = converter.Convert(value, genericArgument);
                return true;
            }

            result = null;
            return false;
        }
开发者ID:JackWangCUMT,项目名称:NetworkSocket,代码行数:22,代码来源:NullableConvert.cs

示例8: Convert_NestedObject_ShouldSucced

        public void Convert_NestedObject_ShouldSucced(Converter sut)
        {
            //Setup
            var columns = new List<string>() {
                "id",
                "city.name",
                "city.country.isoCode"
            };
            var matrix = new List<List<object>>()
            {
                new List<object>() { 1, "cityName1", "countryIsoCode1" },
                new List<object>() { 2, "cityName2", "countryIsoCode2" }
            };

            //Exercise
            var actual = sut.Convert(columns, matrix);

            //Verify
            actual.Should().NotBeEmpty()
                .And.HaveSameCount(matrix)
                .And.DeepContain(new Dictionary<string, object>()
                {
                    { "id", 1 },
                    { "city", new Dictionary<string, object>()
                        {
                            { "name", "cityName1" },
                            { "country", new Dictionary<string, object>()
                                {
                                    { "isoCode", "countryIsoCode1" }
                                }
                           }
                        }
                    }
                })
                .And.DeepContain(new Dictionary<string, object>()
                {
                    { "id", 2 },
                    { "city", new Dictionary<string, object>()
                        {
                            { "name", "cityName2" },
                            { "country", new Dictionary<string, object>()
                                {
                                    { "isoCode", "countryIsoCode2" }
                                }
                            }
                        }
                    }
                });
        }
开发者ID:tgropper,项目名称:Bardock.R2O,代码行数:49,代码来源:ConverterTest.cs

示例9: 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)
        {
            if (targetType.IsArray == false)
            {
                result = null;
                return false;
            }

            var items = value as IEnumerable;
            var elementType = targetType.GetElementType();

            if (items == null)
            {
                result = Array.CreateInstance(elementType, 0);
                return true;
            }

            var length = 0;
            var list = items as IList;
            if (list != null)
            {
                length = list.Count;
            }
            else
            {
                var enumerator = items.GetEnumerator();
                while (enumerator.MoveNext())
                {
                    length = length + 1;
                }
            }

            var index = 0;
            var array = Array.CreateInstance(elementType, length);
            foreach (var item in items)
            {
                var itemCast = converter.Convert(item, elementType);
                array.SetValue(itemCast, index);
                index = index + 1;
            }

            result = array;
            return true;
        }
开发者ID:JackWangCUMT,项目名称:NetworkSocket,代码行数:54,代码来源:ArrayConvert.cs

示例10: Convert

        public static string Convert(string input)
        {
            Dictionary<string, Converter.Tag> tagDict = new Dictionary<string, Converter.Tag>();

            tagDict.Add("stats", new Converter.NodeTag("stats", new Converter.Style(@"<Run FontWeight=""Bold"">", @"</Run>")));
            tagDict.Add("unique", new Converter.NodeTag("unique", new Converter.Style(@"<Run FontWeight=""Bold"" Foreground=""DarkBlue"">", @"</Run>")));
            tagDict.Add("i", new Converter.NodeTag("i", new Converter.Style(@"<Run FontStyle=""Italic"">", @"</Run>")));
            tagDict.Add("consumable", new Converter.NodeTag("consumable", new Converter.Style(@"<Run FontWeight=""Bold"" Foreground=""DarkOrange"">", @"</Run>")));
            tagDict.Add("active", new Converter.NodeTag("active", new Converter.Style(@"<Run FontWeight=""Bold"" Foreground=""DarkRed"">", @"</Run>")));
            tagDict.Add("passive", new Converter.NodeTag("passive", new Converter.Style(@"<Run FontWeight=""Bold"" Foreground=""DarkBlue"">", @"</Run>")));
            tagDict.Add("aura", new Converter.NodeTag("aura", new Converter.Style(@"<Run FontWeight=""Bold"" Foreground=""DarkGreen"">", @"</Run>")));
            tagDict.Add("br", new Converter.SingleTag("br", new Converter.Style("<LineBreak/>")));
            tagDict.Add("start", new Converter.SingleTag("start", new Converter.Style(@"<Paragraph FontFamily=""Global User Interface"">")));
            tagDict.Add("end", new Converter.SingleTag("end", new Converter.Style(@"</Paragraph>")));
            tagDict.Add("body", new Converter.NodeTag("body", new Converter.Style(@"<Run Text=""", @"""></Run>")));
            Converter c = new Converter(tagDict);

            return c.Convert(input);
        }
开发者ID:philippwiddra,项目名称:piltover-libraries,代码行数:19,代码来源:DescriptionToXamlConverter.cs

示例11: button1_Click

        private void button1_Click(object sender, EventArgs e)
        {
            Converter converter = new Converter();
            // Authentication
            converter.Username = "";
            converter.Password = "";
            converter.Domain = "";
            // Authentication
            string cType="";
            if (this.comboBox1.SelectedIndex==0) { cType="ObjCFiles";}
            if (this.comboBox1.SelectedIndex==1) { cType="ObjCARCFiles";}
            if (this.comboBox1.SelectedIndex==2) { cType="Javascript";}
            if (this.comboBox1.SelectedIndex==3) { cType="ActionScript";}

            converter.Type = cType ;
            converter.WsdlPaths = textBox1.Text;
            converter.Convert();
            FileInfo zf=converter.CreateArchive();
            MessageBox.Show(zf.FullName,"Code Generated");
        }
开发者ID:pgiacomo69,项目名称:sudzc,代码行数:20,代码来源:Form1.cs

示例12: Convert_SimpleObject_ShouldSucced

        public void Convert_SimpleObject_ShouldSucced(Converter sut)
        {
            //Setup
            var columns = new List<string>() {
                "id",
                "name"
            };
            var matrix = new List<List<object>>()
            {
                new List<object>() { 1, "name1" },
                new List<object>() { 2, "name2" },
                new List<object>() { 3, "name3" }
            };

            //Exercise
            var actual = sut.Convert(columns, matrix);

            //Verify
            actual.Should().NotBeEmpty()
                .And.HaveSameCount(matrix)
                .And.DeepContain(new Dictionary<string, object>() { { "id", 1 }, { "name", "name1" } })
                .And.DeepContain(new Dictionary<string, object>() { { "id", 2 }, { "name", "name2" } })
                .And.DeepContain(new Dictionary<string, object>() { { "id", 3 }, { "name", "name3" } });
        }
开发者ID:tgropper,项目名称:Bardock.R2O,代码行数:24,代码来源:ConverterTest.cs

示例13: CheckConversion

		private static void CheckConversion(string html, string expected)
		{
			var converter = new Converter();

			var result = converter.Convert(html);

			Assert.That(result, Is.EqualTo(expected));
		}
开发者ID:Leafney,项目名称:Html2Markdown,代码行数:8,代码来源:ConverterTest.cs

示例14: VerifyComplete

 public void VerifyComplete(Converter converter, Task<bool> res)
 {
     if (this.HandleFaultedTask(res))
     {
         EnableUi = true;
         converter.Dispose();
         return;
     }
     if (res.Result)
     {
         converter.Convert().ContinueWith(x => this.ConvertComplete(converter, x));
     }
 }
开发者ID:razerk,项目名称:OCTGN-Set-Guid-Converter,代码行数:13,代码来源:MainWindow.xaml.cs

示例15: It_should_convert_it_to_expected_value

 public void It_should_convert_it_to_expected_value(int input, string expected)
 {
     var sut = new Converter();
     string actual = sut.Convert(input);
     actual.Should().Be(expected);
 }
开发者ID:andygjp,项目名称:FizzBuzzKata,代码行数:6,代码来源:Tests.cs


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