RaUI/Source/MyDb/HtmlAgilityPack.Shared/Utilities.cs
鑫Intel a1d6dce946 ### 2021-08-03更新
------
#### MyDbV4    V3.0.2108.0301
- *.[新增]新增内置HtmlAgilityPack组件。
2021-08-30 19:47:56 +08:00

64 lines
2.0 KiB
C#

// Description: Html Agility Pack - HTML Parsers, selectors, traversors, manupulators.
// Website & Documentation: http://html-agility-pack.net
// Forum & Issues: https://github.com/zzzprojects/html-agility-pack
// License: https://github.com/zzzprojects/html-agility-pack/blob/master/LICENSE
// More projects: http://www.zzzprojects.com/
// Copyright © ZZZ Projects Inc. 2014 - 2017. All rights reserved.
using System;
using System.Collections.Generic;
using System.ComponentModel;
namespace HtmlAgilityPack
{
internal static class Utilities
{
public static TValue GetDictionaryValueOrDefault<TKey, TValue>(Dictionary<TKey, TValue> dict, TKey key, TValue defaultValue = default(TValue)) where TKey : class
{
TValue value;
if (!dict.TryGetValue(key, out value))
return defaultValue;
return value;
}
#if !(METRO || NETSTANDARD1_3 || NETSTANDARD1_6)
internal static object To(this Object @this, Type type)
{
if (@this != null)
{
Type targetType = type;
if (@this.GetType() == targetType)
{
return @this;
}
TypeConverter converter = TypeDescriptor.GetConverter(@this);
if (converter != null)
{
if (converter.CanConvertTo(targetType))
{
return converter.ConvertTo(@this, targetType);
}
}
converter = TypeDescriptor.GetConverter(targetType);
if (converter != null)
{
if (converter.CanConvertFrom(@this.GetType()))
{
return converter.ConvertFrom(@this);
}
}
if (@this == DBNull.Value)
{
return null;
}
}
return @this;
}
#endif
}
}