internal static bool AreEquivalent(Type t1, Type t2) { #if CLR2 || SILVERLIGHT return t1 == t2; #else return t1 == t2 || t1.IsEquivalentTo(t2); #endif }
internal static bool AreEquivalent(Type t1, Type t2) { if (!(t1 == t2)) { return t1.IsEquivalentTo(t2); } return true; }
public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType) { if (destinationType.IsEquivalentTo(typeof(string))) { return ((BuildAction)value).Name; } return null; }
object IServiceProvider.GetService(System.Type serviceType) { if (serviceType.IsEquivalentTo(typeof(IVsToolWindowToolbar))) { return(this); } if (serviceType.IsEquivalentTo(typeof(IOleCommandTarget))) { return(commandService); } if ((serviceType.IsEquivalentTo(typeof(IVsToolWindowToolbarHost))) && (null != ToolbarHost)) { return(ToolbarHost); } return(provider.GetService(serviceType)); }
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(); }
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; } }
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); }
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(); }
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()); }
/// <summary> /// Determines if two CLR types are equivalent. /// </summary> /// <param name="typeA">First type to compare.</param> /// <param name="typeB">Second type to compare.</param> /// <returns>true if the types are equivalent (they both represent the same type), or false otherwise.</returns> /// <remarks>This method abstracts away the necessity to call Type.IsEquivalentTo method in .NET 4 and higher but /// use simple reference equality on platforms which don't have that method (like Silverlight).</remarks> internal static bool AreTypesEquivalent(Type typeA, Type typeB) { DebugUtils.CheckNoExternalCallers(); if (typeA == null || typeB == null) { return false; } else { #if SILVERLIGHT || WINDOWS_PHONE || ORCAS return typeA == typeB; #else return typeA.IsEquivalentTo(typeB); #endif } }
/// <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 (_provider != null) { if (serviceType.IsEquivalentTo(typeof(AmbientProperties))) { if (_uis == null) { _uis = (IUIService)_provider.GetService(typeof(IUIService)); } if (_ambientProperties == null) { _ambientProperties = new AmbientProperties(); } if (_uis != null) { // update the _ambientProperties in case the styles have changed // since last time. _ambientProperties.Font = (Font)_uis.Styles["DialogFont"]; } return _ambientProperties; } object service = _provider.GetService(serviceType); if (service != null) { return service; } } return base.GetService(serviceType); }
public static string Format(Type enumType, object value, string format) { if (enumType == null) { throw new ArgumentNullException(nameof(enumType)); } if (!enumType.IsEnum) { throw new ArgumentException(SR.Arg_MustBeEnum, nameof(enumType)); } if (value == null) { throw new ArgumentNullException(nameof(value)); } if (format == null) { throw new ArgumentNullException(nameof(format)); } RuntimeType rtType = enumType as RuntimeType; if (rtType == null) { throw new ArgumentException(SR.Arg_MustBeType, nameof(enumType)); } // Check if both of them are of the same type Type valueType = value.GetType(); Type underlyingType = GetUnderlyingType(enumType); // If the value is an Enum then we need to extract the underlying value from it if (valueType.IsEnum) { if (!valueType.IsEquivalentTo(enumType)) { throw new ArgumentException(SR.Format(SR.Arg_EnumAndObjectMustBeSameType, valueType.ToString(), enumType.ToString())); } if (format.Length != 1) { // all acceptable format string are of length 1 throw new FormatException(SR.Format_InvalidEnumFormatSpecification); } return(((Enum)value).ToString(format)); } // The value must be of the same type as the Underlying type of the Enum else if (valueType != underlyingType) { throw new ArgumentException(SR.Format(SR.Arg_EnumFormatUnderlyingTypeAndObjectMustBeSameType, valueType.ToString(), underlyingType.ToString())); } if (format.Length != 1) { // all acceptable format string are of length 1 throw new FormatException(SR.Format_InvalidEnumFormatSpecification); } char formatCh = format[0]; if (formatCh == 'G' || formatCh == 'g') { return(GetEnumName(rtType, ToUInt64(value)) ?? value.ToString()); } if (formatCh == 'D' || formatCh == 'd') { return(value.ToString()); } if (formatCh == 'X' || formatCh == 'x') { return(InternalFormattedHexString(value)); } if (formatCh == 'F' || formatCh == 'f') { return(Enum.InternalFlagsFormat(rtType, ToUInt64(value)) ?? value.ToString()); } throw new FormatException(SR.Format_InvalidEnumFormatSpecification); }
protected bool AreEquivalent( Type lhs, Type rhs ) { return lhs == rhs || lhs.IsEquivalentTo( rhs ); }
public static bool AreEquivalent(Type t1, Type t2) { return t1.IsEquivalentTo(t2); }
// 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 }
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) { if (((CopyToOutputDirectory)value) == CopyToOutputDirectory.DoNotCopy) result = SR.GetString(SR.DoNotCopy, culture); if (((CopyToOutputDirectory)value) == CopyToOutputDirectory.Always) result = SR.GetString(SR.CopyAlways, culture); if (((CopyToOutputDirectory)value) == CopyToOutputDirectory.PreserveNewest) result = SR.GetString(SR.CopyIfNewer, culture); } else { result = ""; } if (result != null) return result; } return base.ConvertTo(context, culture, value, destinationType); }
/// <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); }
// keep in sync with System.Core version internal static bool AreEquivalent(Type t1, Type t2) { #if !CLR4 return t1 == t2; #else return t1 == t2 || t1.IsEquivalentTo(t2); #endif }
private static bool IsTypeEquivalent(Type argType, Type paramType) { bool flag = false; if (argType.IsEquivalentTo(paramType)) { return true; } if (argType.IsSubclassOf(paramType)) { return true; } if (argType.IsEquivalentTo(paramType.GetElementType())) { return true; } if (argType.IsSubclassOf(typeof(Array)) && paramType.IsSubclassOf(typeof(Array))) { flag = true; } return flag; }
internal static bool AreEquivalent(Type t1, Type t2) { #if MICROSOFT_SCRIPTING_CORE || SILVERLIGHT return t1 == t2; #else return t1 == t2 || t1.IsEquivalentTo(t2); #endif }
// keep in sync with System.Core version internal static bool AreEquivalent(Type t1, Type t2) { #if FEATURE_TYPE_EQUIVALENCE return t1 == t2 || t1.IsEquivalentTo(t2); #else return t1 == t2; #endif }
private static void SelectEnvAndExt(ToolWindow envs, IPythonInterpreterFactory interpreter, Type extension, int retries) { if (retries <= 0) { Debug.Fail("Failed to select environment/extension after multiple retries"); return; } var select = envs.IsLoaded ? envs.Environments.OfType<EnvironmentView>().FirstOrDefault(e => e.Factory == interpreter) : null; if (select == null) { envs.Dispatcher.InvokeAsync(() => SelectEnvAndExt(envs, interpreter, extension, retries - 1), DispatcherPriority.Background); return; } var ext = select?.Extensions.FirstOrDefault(e => e != null && extension.IsEquivalentTo(e.GetType())); envs.Environments.MoveCurrentTo(select); if (ext != null) { var exts = envs.Extensions; if (exts != null && exts.Contains(ext)) { exts.MoveCurrentTo(ext); ((ext as IEnvironmentViewExtension)?.WpfObject as ICanFocus)?.Focus(); } } }
public static String Format(Type enumType, Object value, String format) { if (enumType == null) { throw new ArgumentNullException("enumType"); } if (!enumType.IsEnum) { throw new ArgumentException(Environment.GetResourceString("Arg_MustBeEnum"), "enumType"); } if (value == null) { throw new ArgumentNullException("value"); } if (format == null) { throw new ArgumentNullException("format"); } Contract.EndContractBlock(); RuntimeType rtType = enumType as RuntimeType; if (rtType == null) { throw new ArgumentException(Environment.GetResourceString("Arg_MustBeType"), "enumType"); } // Check if both of them are of the same type Type valueType = value.GetType(); Type underlyingType = GetUnderlyingType(enumType); // If the value is an Enum then we need to extract the underlying value from it if (valueType.IsEnum) { Type valueUnderlyingType = GetUnderlyingType(valueType); if (!valueType.IsEquivalentTo(enumType)) { throw new ArgumentException(Environment.GetResourceString("Arg_EnumAndObjectMustBeSameType", valueType.ToString(), enumType.ToString())); } valueType = valueUnderlyingType; value = ((Enum)value).GetValue(); } // The value must be of the same type as the Underlying type of the Enum else if (valueType != underlyingType) { throw new ArgumentException(Environment.GetResourceString("Arg_EnumFormatUnderlyingTypeAndObjectMustBeSameType", valueType.ToString(), underlyingType.ToString())); } if (format.Length != 1) { // all acceptable format string are of length 1 throw new FormatException(Environment.GetResourceString("Format_InvalidEnumFormatSpecification")); } char formatCh = format[0]; if (formatCh == 'D' || formatCh == 'd') { return(value.ToString()); } if (formatCh == 'X' || formatCh == 'x') { // Retrieve the value from the field. return(InternalFormattedHexString(value)); } if (formatCh == 'G' || formatCh == 'g') { return(InternalFormat(rtType, value)); } if (formatCh == 'F' || formatCh == 'f') { return(InternalFlagsFormat(rtType, value)); } throw new FormatException(Environment.GetResourceString("Format_InvalidEnumFormatSpecification")); }
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); }
public override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceType) { if (sourceType.IsEquivalentTo(typeof(string))) return true; return base.CanConvertFrom(context, sourceType); }
/// <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); }
private bool TypesArePrimitiveAndConvertible(Type source, Type dest) { Type nonNullableSourceType = source.GetNonNullableType(); Type nonNullableDestinationType = dest.GetNonNullableType(); return (!(source.IsEnum || dest.IsEnum)) && (source.IsEquivalentTo(dest) || ((source.IsNullableType() && dest.IsEquivalentTo(nonNullableSourceType)) || ((dest.IsNullableType() && source.IsEquivalentTo(nonNullableDestinationType)) || ((source.IsNumeric() && dest.IsNumeric()) && (nonNullableDestinationType != TypeSystem.Boolean))))); }
///////////////////////////////////////////////////////////////////////////////// private bool TypesAreEqual(Type t1, Type t2) { if (t1 == t2) { return true; } return t1.IsEquivalentTo(t2); }
/// <include file='doc\WindowPane.uex' path='docs/doc[@for="WindowPane.GetService"]' /> /// <devdoc> /// Maps to IServiceProvider for service routing. /// </devdoc> protected virtual object GetService(Type serviceType) { if (_zombie) { Debug.Fail("GetService called after WindowPane was zombied"); return null; } if (serviceType == null) { throw new ArgumentNullException("serviceType"); } // We provide IMenuCommandService, so we will // demand create it. MenuCommandService also // implements IOleCommandTarget, but unless // someone requested IMenuCommandService no commands // will exist, so we don't demand create for // IOleCommandTarget // if (serviceType.IsEquivalentTo(typeof(IMenuCommandService))) { EnsureCommandService(); return _commandService; } else if (serviceType.IsEquivalentTo(typeof(IOleCommandTarget))) { return _commandService; } else if (serviceType.IsEquivalentTo(typeof(IHelpService))) { if (_helpService == null) { _helpService = new HelpService(this); } return _helpService; } if (_provider != null) { object service = _provider.GetService(serviceType); if (service != null) { return service; } } // We should never attempt to resite the parent // if _provider is not null it will have already succeeded above. if (serviceType.IsEquivalentTo(typeof(IObjectWithSite))) return null; if (_parentProvider != null) { return _parentProvider.GetService(serviceType); } return null; }
public override bool CanConvertTo(ITypeDescriptorContext context, Type sourceType) { return sourceType.IsEquivalentTo(typeof(string)); }
public static object CreateService(IServiceContainer container, Type serviceType) { if (serviceType.IsEquivalentTo(typeof(IPythonToolsOptionsService))) { return new PythonToolsOptionsService(container); } return null; }
public static string Format(Type enumType, object value, string format) { if (enumType == null) { throw new ArgumentNullException("enumType"); } if (!enumType.IsEnum) { throw new ArgumentException(Environment.GetResourceString("Arg_MustBeEnum"), "enumType"); } if (value == null) { throw new ArgumentNullException("value"); } if (format == null) { throw new ArgumentNullException("format"); } RuntimeType eT = enumType as RuntimeType; if (eT == null) { throw new ArgumentException(Environment.GetResourceString("Arg_MustBeType"), "enumType"); } Type type = value.GetType(); Type underlyingType = GetUnderlyingType(enumType); if (type.IsEnum) { Type type4 = GetUnderlyingType(type); if (!type.IsEquivalentTo(enumType)) { throw new ArgumentException(Environment.GetResourceString("Arg_EnumAndObjectMustBeSameType", new object[] { type.ToString(), enumType.ToString() })); } type = type4; value = ((Enum)value).GetValue(); } else if (type != underlyingType) { throw new ArgumentException(Environment.GetResourceString("Arg_EnumFormatUnderlyingTypeAndObjectMustBeSameType", new object[] { type.ToString(), underlyingType.ToString() })); } if (format.Length != 1) { throw new FormatException(Environment.GetResourceString("Format_InvalidEnumFormatSpecification")); } char ch = format[0]; switch (ch) { case 'D': case 'd': return(value.ToString()); case 'X': case 'x': return(InternalFormattedHexString(value)); case 'G': case 'g': return(InternalFormat(eT, value)); } if ((ch != 'F') && (ch != 'f')) { throw new FormatException(Environment.GetResourceString("Format_InvalidEnumFormatSpecification")); } return(InternalFlagsFormat(eT, value)); }
internal static bool AreTypesEquivalent(Type typeA, Type typeB) { return (((typeA != null) && (typeB != null)) && typeA.IsEquivalentTo(typeB)); }
/// <summary> /// ICustomTypeDescriptor.GetEditor /// To enable the "Property Pages" button on the properties browser /// the browse object (project properties) need to be unmanaged /// or it needs to provide an editor of type ComponentEditor. /// </summary> /// <param name="editorBaseType">Type of the editor</param> /// <returns>Editor</returns> public override object GetEditor(Type editorBaseType) { // Override the scenario where we are asked for a ComponentEditor // as this is how the Properties Browser calls us if (editorBaseType.IsEquivalentTo(typeof(ComponentEditor))) { IOleServiceProvider sp; ErrorHandler.ThrowOnFailure(this.Node.GetSite(out sp)); return new PropertiesEditorLauncher(new ServiceProvider(sp)); } return base.GetEditor(editorBaseType); }
public static bool IsSubOrEqual(this System.Type Self, System.Type Type) { return(Self.IsEquivalentTo(Type) || Self.IsSubclassOf(Type)); }