本文整理汇总了C#中System.Type.IsEquivalentTo方法的典型用法代码示例。如果您正苦于以下问题:C# Type.IsEquivalentTo方法的具体用法?C# Type.IsEquivalentTo怎么用?C# Type.IsEquivalentTo使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Type
的用法示例。
在下文中一共展示了Type.IsEquivalentTo方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: AreEquivalent
internal static bool AreEquivalent(Type t1, Type t2)
{
if (!(t1 == t2))
{
return t1.IsEquivalentTo(t2);
}
return true;
}
示例2: AreEquivalent
internal static bool AreEquivalent(Type t1, Type t2)
{
#if CLR2 || SILVERLIGHT
return t1 == t2;
#else
return t1 == t2 || t1.IsEquivalentTo(t2);
#endif
}
示例3: ConvertTo
public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType)
{
if (destinationType.IsEquivalentTo(typeof(string)))
{
return ((BuildAction)value).Name;
}
return null;
}
示例4: ReadJson
public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
{
if (objectType.IsEquivalentTo(typeof(SemanticVersion)) && reader.Value is string)
{
SemanticVersion value;
if (SemanticVersion.TryParse((string)reader.Value, out value))
{
return value;
}
}
throw new NotSupportedException();
}
示例5: CheckType
public override bool CheckType(Type propertyType)
{
if (propertyType.IsEquivalentTo(typeof(int))
|| propertyType.Equals(ExpectedType())
|| (propertyType.IsGenericType
&& typeof(int) == propertyType.GetGenericArguments().FirstOrDefault()))
{
return true;
}
else
{
return false;
}
}
示例6: ConvertTo
public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType) {
if (destinationType.IsEquivalentTo(typeof(string)))
{
string result = null;
// In some cases if multiple nodes are selected the windows form engine
// calls us with a null value if the selected node's property values are not equal
if (value != null)
{
result = SR.GetString(((OutputType)value).ToString(), culture);
}
else
{
result = SR.GetString(OutputType.Library.ToString(), culture);
}
if (result != null) return result;
}
return base.ConvertTo(context, culture, value, destinationType);
}
示例7: ReadJson
public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
{
if (objectType.IsEquivalentTo(typeof(VersionOptions.AssemblyVersionOptions)))
{
if (reader.Value is string)
{
Version value;
if (Version.TryParse((string)reader.Value, out value))
{
return new VersionOptions.AssemblyVersionOptions(value);
}
}
else if (reader.TokenType == JsonToken.StartObject)
{
// Temporarily remove ourselves from the serializer so we don't recurse infinitely.
serializer.Converters.Remove(this);
var result = serializer.Deserialize<VersionOptions.AssemblyVersionOptions>(reader);
serializer.Converters.Add(this);
return result;
}
}
throw new NotSupportedException();
}
示例8: GetPreDefinedConversionNotVoid
/// <summary>
/// 返回的将对象从 <paramref name="inputType"/> 类型转换为 <paramref name="outputType"/>
/// 类型的预定义类型转换。
/// </summary>
/// <param name="inputType">要转换的对象的类型,不能是 <see cref="Void"/>。</param>
/// <param name="outputType">要将输入对象转换到的类型,不能是 <see cref="Void"/>。</param>
/// <returns>将对象从 <paramref name="inputType"/> 类型转换为 <paramref name="outputType"/>
/// 类型的预定义类型转换,如果不存在则为 <c>null</c>。</returns>
public static Conversion GetPreDefinedConversionNotVoid(Type inputType, Type outputType)
{
Contract.Requires(inputType != null && outputType != null &&
inputType != typeof(void) && outputType != typeof(void));
// 测试相等转换。
if (inputType.IsEquivalentTo(outputType))
{
return IdentityConversion.Default;
}
if (inputType.IsValueType)
{
if (outputType.IsValueType)
{
// 值类型间转换。
return GetBetweenValueTypeConversion(inputType, outputType);
}
// 装箱转换。
if (outputType.IsAssignableFrom(inputType))
{
return BoxConversion.Default;
}
Type inputUnderlyingType = Nullable.GetUnderlyingType(inputType);
if (inputUnderlyingType != null && outputType.IsAssignableFrom(inputUnderlyingType))
{
// 装箱为可空类型的内部类型实现的接口。
return BoxConversion.Default;
}
return null;
}
if (outputType.IsValueType)
{
// 拆箱转换。
if (inputType.IsAssignableFrom(outputType))
{
return UnboxConversion.Default;
}
Type outputUnderlyingType = Nullable.GetUnderlyingType(outputType);
if (outputUnderlyingType != null && inputType.IsAssignableFrom(outputUnderlyingType))
{
return UnboxConversion.Default;
}
return null;
}
// 隐式引用转换。
if (outputType.IsAssignableFrom(inputType))
{
return IdentityConversion.ImplicitReference;
}
// 显式引用转换。
return GetExplicitRefConversion(inputType, outputType);
}
示例9: AreEquivalent
// keep in sync with System.Core version
internal static bool AreEquivalent(Type t1, Type t2) {
#if CLR2 || SILVERLIGHT // type equivalence not implemented on Silverlight
return t1 == t2;
#else
return t1 == t2 || t1.IsEquivalentTo(t2);
#endif
}
示例10: return
object System.IServiceProvider.GetService(Type serviceType)
{
if (serviceType.IsEquivalentTo(typeof(IOleCommandTarget)))
return ((IOleCommandTarget)menuService);
else if (serviceType.IsEquivalentTo(typeof(System.ComponentModel.Design.IMenuCommandService)))
return ((System.ComponentModel.Design.IMenuCommandService)menuService);
else
return this.serviceProvider.GetService(serviceType);
}
示例11: ParameterTypeMatches
private static bool ParameterTypeMatches(Type type, ParameterInfo param)
{
if (!type.IsEquivalentTo(param.ParameterType))
{
return false;
}
// TODO (tomat): how expensive is GetOptional/GetRequiredCustomModifiers?
ModifiedType modified = type as ModifiedType;
return IsEquivalentTo(modified != null ? modified.OptionalModifiers : null, param.GetOptionalCustomModifiers())
&& IsEquivalentTo(modified != null ? modified.RequiredModifiers : null, param.GetRequiredCustomModifiers());
}
示例12: AreEquivalent
protected bool AreEquivalent( Type lhs, Type rhs )
{
return lhs == rhs || lhs.IsEquivalentTo( rhs );
}
示例13: GetService
/// <devdoc>
/// Override to GetService so we can route requests
/// to the package's service provider.
/// </devdoc>
protected override object GetService(Type serviceType)
{
if (serviceType == null) {
throw new ArgumentNullException("serviceType");
}
if (serviceType.IsEquivalentTo(typeof(AmbientProperties))) {
if (_ambientProperties == null) {
IUIService uis = GetService(typeof(IUIService)) as IUIService;
_ambientProperties = new AmbientProperties();
_ambientProperties.Font = (Font)uis.Styles["DialogFont"];
}
return _ambientProperties;
}
if (_provider != null) {
object service = _provider.GetService(serviceType);
if (service != null) {
return service;
}
}
return base.GetService(serviceType);
}
示例14: CanConvertFrom
public override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceType) {
if (sourceType.IsEquivalentTo(typeof(string))) return true;
return base.CanConvertFrom(context, sourceType);
}
示例15: CreateService
public static object CreateService(IServiceContainer container, Type serviceType) {
if (serviceType.IsEquivalentTo(typeof(IPythonToolsOptionsService))) {
return new PythonToolsOptionsService(container);
}
return null;
}