From 258515cafd3eea31cd4c1262a6329a8d72e457cc Mon Sep 17 00:00:00 2001 From: Curtis Wensley Date: Sat, 1 Jun 2024 15:10:23 -0700 Subject: [PATCH] Remove TypeHelper which was used for netstandard1.0 support --- .../DefaultNamespaceManager.cs | 2 +- .../Eto.Serialization.Json.csproj | 1 - src/Eto.Serialization.Json/JsonReader.cs | 4 +- .../Eto.Serialization.Xaml.csproj | 1 - src/Eto.Serialization.Xaml/XamlReader.cs | 12 +-- src/Eto/DefaultStyleProvider.cs | 2 +- src/Eto/Drawing/Bitmap.cs | 2 +- src/Eto/Drawing/Icon.cs | 2 +- src/Eto/EventLookup.cs | 12 +-- .../Binding/BindingExtensionsNonGeneric.cs | 2 +- src/Eto/Forms/Binding/IndirectBinding.cs | 2 +- src/Eto/Forms/Cells/PropertyCell.cs | 4 +- src/Eto/Forms/Controls/EnumCheckBoxList.cs | 2 +- src/Eto/Forms/Controls/EnumDropDown.cs | 2 +- src/Eto/Forms/Controls/EnumRadioButtonList.cs | 2 +- src/Eto/Forms/Cursor.cs | 2 +- src/Eto/Platform.cs | 12 +-- src/Eto/PlatformExtension.cs | 2 +- src/Eto/TypeHelper.cs | 91 ------------------- 19 files changed, 33 insertions(+), 126 deletions(-) delete mode 100644 src/Eto/TypeHelper.cs diff --git a/src/Eto.Serialization.Json/DefaultNamespaceManager.cs b/src/Eto.Serialization.Json/DefaultNamespaceManager.cs index 110c422ec0..d08af447ff 100644 --- a/src/Eto.Serialization.Json/DefaultNamespaceManager.cs +++ b/src/Eto.Serialization.Json/DefaultNamespaceManager.cs @@ -4,7 +4,7 @@ public class DefaultNamespaceManager : NamespaceManager { public DefaultNamespaceManager () { - var asm = typeof(Eto.Forms.Application).GetAssembly(); + var asm = typeof(Eto.Forms.Application).Assembly; DefaultNamespace = new NamespaceInfo("Eto.Forms", asm); Namespaces.Add ("drawing", new NamespaceInfo("Eto.Drawing", asm)); } diff --git a/src/Eto.Serialization.Json/Eto.Serialization.Json.csproj b/src/Eto.Serialization.Json/Eto.Serialization.Json.csproj index ecadda5da9..c79a13a5f3 100644 --- a/src/Eto.Serialization.Json/Eto.Serialization.Json.csproj +++ b/src/Eto.Serialization.Json/Eto.Serialization.Json.csproj @@ -19,7 +19,6 @@ https://github.com/picoe/Eto/wiki - diff --git a/src/Eto.Serialization.Json/JsonReader.cs b/src/Eto.Serialization.Json/JsonReader.cs index 4e2859d641..0c6f262108 100644 --- a/src/Eto.Serialization.Json/JsonReader.cs +++ b/src/Eto.Serialization.Json/JsonReader.cs @@ -11,7 +11,7 @@ static Stream GetStream(Type type) GetStream(type, type.FullName + ".jeto") ?? GetStream(type, type.FullName + ".json") ?? GetStream(type, type.Name + ".jeto") // for f# projects - ?? throw new InvalidOperationException($"Embedded resource '{type.FullName}.jeto' not found in assembly '{type.GetAssembly()}'"); + ?? throw new InvalidOperationException($"Embedded resource '{type.FullName}.jeto' not found in assembly '{type.Assembly}'"); } static Stream GetStream(Type type, string resourceName) @@ -106,7 +106,7 @@ public static void Load(T instance, string resourceName, NamespaceManager nam using (var stream = GetStream(typeof(T), resourceName)) { if (stream == null) - throw new ArgumentException(nameof(resourceName), $"Embedded resource '{resourceName}' not found in assembly '{typeof(T).GetAssembly()}'"); + throw new ArgumentException(nameof(resourceName), $"Embedded resource '{resourceName}' not found in assembly '{typeof(T).Assembly}'"); Load(stream, instance, namespaceManager); } diff --git a/src/Eto.Serialization.Xaml/Eto.Serialization.Xaml.csproj b/src/Eto.Serialization.Xaml/Eto.Serialization.Xaml.csproj index 4e8da49fe4..a6e0cf6759 100644 --- a/src/Eto.Serialization.Xaml/Eto.Serialization.Xaml.csproj +++ b/src/Eto.Serialization.Xaml/Eto.Serialization.Xaml.csproj @@ -19,7 +19,6 @@ https://github.com/picoe/Eto/wiki - diff --git a/src/Eto.Serialization.Xaml/XamlReader.cs b/src/Eto.Serialization.Xaml/XamlReader.cs index cd7bfca50a..0a33c5972d 100644 --- a/src/Eto.Serialization.Xaml/XamlReader.cs +++ b/src/Eto.Serialization.Xaml/XamlReader.cs @@ -27,12 +27,12 @@ static Stream GetStream(Type type) GetStream(type, type.FullName + ".xeto") ?? GetStream(type, type.FullName + ".xaml") ?? GetStream(type, type.Name + ".xeto") // for F#/VB.NET projects - ?? throw new InvalidOperationException($"Embedded resource '{type.FullName}.xeto' not found in assembly '{type.GetAssembly()}'"); + ?? throw new InvalidOperationException($"Embedded resource '{type.FullName}.xeto' not found in assembly '{type.Assembly}'"); } static Stream GetStream(Type type, string resourceName) { - return type.GetAssembly().GetManifestResourceStream(resourceName); + return type.Assembly.GetManifestResourceStream(resourceName); } /// @@ -115,7 +115,7 @@ public static void Load(T instance, string resourceName) using (var stream = GetStream(typeof(T), resourceName)) { if (stream == null) - throw new ArgumentException(nameof(resourceName), $"Embedded resource '{resourceName}' not found in assembly '{typeof(T).GetAssembly()}'"); + throw new ArgumentException(nameof(resourceName), $"Embedded resource '{resourceName}' not found in assembly '{typeof(T).Assembly}'"); Load(stream, instance); } @@ -146,7 +146,7 @@ public static T Load(Stream stream, T instance) { var readerSettings = new XamlXmlReaderSettings(); if (!DesignMode) - readerSettings.LocalAssembly = typeof(T).GetAssembly(); + readerSettings.LocalAssembly = typeof(T).Assembly; return Load(new XamlXmlReader(stream, context, readerSettings), instance); } @@ -161,7 +161,7 @@ public static T Load(TextReader reader, T instance) { var readerSettings = new XamlXmlReaderSettings(); if (!DesignMode) - readerSettings.LocalAssembly = typeof(T).GetAssembly(); + readerSettings.LocalAssembly = typeof(T).Assembly; return Load(new XamlXmlReader(reader, context, readerSettings), instance); } @@ -176,7 +176,7 @@ public static T Load(XmlReader reader, T instance) { var readerSettings = new XamlXmlReaderSettings(); if (!DesignMode) - readerSettings.LocalAssembly = typeof(T).GetAssembly(); + readerSettings.LocalAssembly = typeof(T).Assembly; return Load(new XamlXmlReader(reader, context, readerSettings), instance); } diff --git a/src/Eto/DefaultStyleProvider.cs b/src/Eto/DefaultStyleProvider.cs index c26f85e9e2..66999bca1f 100644 --- a/src/Eto/DefaultStyleProvider.cs +++ b/src/Eto/DefaultStyleProvider.cs @@ -114,7 +114,7 @@ IList> GetCascadingStyleList(Type type) if (styleMap.TryGetValue(currentType, out var typeStyles) && typeStyles != null) styleHandlers = typeStyles.Concat(styleHandlers); } - while ((currentType = currentType.GetBaseType()) != null); + while ((currentType = currentType.BaseType) != null); // create a cached list, but if its empty don't store it childHandlers = styleHandlers.ToList(); diff --git a/src/Eto/Drawing/Bitmap.cs b/src/Eto/Drawing/Bitmap.cs index c54a5db20d..9e797a8c40 100644 --- a/src/Eto/Drawing/Bitmap.cs +++ b/src/Eto/Drawing/Bitmap.cs @@ -108,7 +108,7 @@ public static Bitmap FromResource(string resourceName, Type type) { if (type == null) throw new ArgumentNullException("type"); - return FromResource(resourceName, type.GetAssembly()); + return FromResource(resourceName, type.Assembly); } /// diff --git a/src/Eto/Drawing/Icon.cs b/src/Eto/Drawing/Icon.cs index 8099912d05..0b02103568 100644 --- a/src/Eto/Drawing/Icon.cs +++ b/src/Eto/Drawing/Icon.cs @@ -176,7 +176,7 @@ public static Icon FromResource(string resourceName, Type type) { if (type == null) throw new ArgumentNullException("type"); - return FromResource(resourceName, type.GetAssembly()); + return FromResource(resourceName, type.Assembly); } /// diff --git a/src/Eto/EventLookup.cs b/src/Eto/EventLookup.cs index 78eca9b5e7..226e239a78 100644 --- a/src/Eto/EventLookup.cs +++ b/src/Eto/EventLookup.cs @@ -3,7 +3,7 @@ namespace Eto; static class EventLookup { static readonly Dictionary> registeredEvents = new Dictionary>(); - static readonly Assembly etoAssembly = typeof(EventLookup).GetAssembly(); + static readonly Assembly etoAssembly = typeof(EventLookup).Assembly; static readonly Dictionary externalEvents = new Dictionary(); struct EventDeclaration @@ -29,7 +29,7 @@ public static void HookupEvents(Widget widget) { var type = widget.GetType(); - if (type.GetAssembly() == etoAssembly) + if (type.Assembly == etoAssembly) return; if (widget.Handler is Widget.IHandler handler) @@ -46,7 +46,7 @@ public static bool IsDefault(Widget widget, string identifier) { var type = widget.GetType(); - if (type.GetAssembly() == etoAssembly) + if (type.Assembly == etoAssembly) return false; var events = GetEvents(type); return Array.IndexOf(events, identifier) >= 0; @@ -68,14 +68,14 @@ static IEnumerable FindTypeEvents(Type type) var current = type; while (current != null) { - if (current.GetAssembly() == etoAssembly) + if (current.Assembly == etoAssembly) { if (registeredEvents.TryGetValue(current, out var declarations)) { for (int i = 0; i < externalTypes.Count; i++) { var externalType = externalTypes[i]; - foreach (var method in externalType.GetTypeInfo().DeclaredMethods) + foreach (var method in externalType.GetMethods(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.DeclaredOnly)) { for (int j = 0; j < declarations.Count; j++) { @@ -91,7 +91,7 @@ static IEnumerable FindTypeEvents(Type type) { externalTypes.Add(current); } - current = current.GetBaseType(); + current = current.BaseType; } } diff --git a/src/Eto/Forms/Binding/BindingExtensionsNonGeneric.cs b/src/Eto/Forms/Binding/BindingExtensionsNonGeneric.cs index d97b9bfea1..531846fb52 100644 --- a/src/Eto/Forms/Binding/BindingExtensionsNonGeneric.cs +++ b/src/Eto/Forms/Binding/BindingExtensionsNonGeneric.cs @@ -24,7 +24,7 @@ static PropertyInfo GetFirstDeclaredProperty(Type type, string propertyName) var property = type.GetTypeInfo().GetDeclaredProperty(propertyName); if (property != null) return property; - type = type.GetBaseType(); + type = type.BaseType; } return null; } diff --git a/src/Eto/Forms/Binding/IndirectBinding.cs b/src/Eto/Forms/Binding/IndirectBinding.cs index 0d92836c57..32a08e5389 100644 --- a/src/Eto/Forms/Binding/IndirectBinding.cs +++ b/src/Eto/Forms/Binding/IndirectBinding.cs @@ -379,7 +379,7 @@ public IndirectBinding Child(IndirectBinding bi public IndirectBinding EnumToString(T defaultValue = default(T)) { var enumType = Nullable.GetUnderlyingType(typeof(T)) ?? typeof(T); - if (!enumType.IsEnum()) + if (!enumType.IsEnum) throw new ArgumentException(string.Format(CultureInfo.CurrentCulture, "Type of T ({0}) must be an enumeration type", typeof(T))); return new DelegateBinding( m => System.Convert.ToString(GetValue(m)), diff --git a/src/Eto/Forms/Cells/PropertyCell.cs b/src/Eto/Forms/Cells/PropertyCell.cs index 2e67cd4368..65af8edc7b 100644 --- a/src/Eto/Forms/Cells/PropertyCell.cs +++ b/src/Eto/Forms/Cells/PropertyCell.cs @@ -676,7 +676,7 @@ public class PropertyCellTypeEnum : PropertyCellType /// Item type. public override bool CanDisplay(object itemType) { - return (itemType as Type)?.IsEnum() == true; + return (itemType as Type)?.IsEnum == true; } /// @@ -720,7 +720,7 @@ public override void OnConfigure(CellEventArgs args, Control control) Control CreateDropDown(CellEventArgs args, Control current) { var type = ItemTypeBinding?.GetValue(args.Item) ?? ItemBinding?.GetValue(args.Item).GetType(); - if (type == null || !type.IsEnum()) + if (type == null || !type.IsEnum) return null; var enumType = typeof(EnumDropDown<>).MakeGenericType(type); if (enumType.IsInstanceOfType(current)) diff --git a/src/Eto/Forms/Controls/EnumCheckBoxList.cs b/src/Eto/Forms/Controls/EnumCheckBoxList.cs index 591c0cb40f..69bfb97645 100644 --- a/src/Eto/Forms/Controls/EnumCheckBoxList.cs +++ b/src/Eto/Forms/Controls/EnumCheckBoxList.cs @@ -79,7 +79,7 @@ public EnumCheckBoxList() protected override ListItemCollection CreateDefaultItems() { var type = typeof(T); - if (!type.IsEnum()) + if (!type.IsEnum) throw new ArgumentException(string.Format(CultureInfo.CurrentCulture, "T must be an enumeration")); var items = new ListItemCollection(); diff --git a/src/Eto/Forms/Controls/EnumDropDown.cs b/src/Eto/Forms/Controls/EnumDropDown.cs index 1d129f71e6..6d61fb0272 100644 --- a/src/Eto/Forms/Controls/EnumDropDown.cs +++ b/src/Eto/Forms/Controls/EnumDropDown.cs @@ -102,7 +102,7 @@ protected virtual void OnAddValue(AddValueEventArgs e) protected override IEnumerable CreateDefaultDataStore() { var type = EnumType; - if (!type.IsEnum()) + if (!type.IsEnum) throw new ArgumentException(string.Format(CultureInfo.CurrentCulture, "T must be an enumeration")); var items = new ListItemCollection(); diff --git a/src/Eto/Forms/Controls/EnumRadioButtonList.cs b/src/Eto/Forms/Controls/EnumRadioButtonList.cs index e41c15fba1..240f2a946b 100644 --- a/src/Eto/Forms/Controls/EnumRadioButtonList.cs +++ b/src/Eto/Forms/Controls/EnumRadioButtonList.cs @@ -61,7 +61,7 @@ protected virtual void OnAddValue(AddValueEventArgs e) protected override ListItemCollection CreateDefaultItems() { var type = typeof(T); - if (!type.IsEnum()) + if (!type.IsEnum) throw new ArgumentException(string.Format(CultureInfo.CurrentCulture, "T must be an enumeration")); var items = new ListItemCollection(); diff --git a/src/Eto/Forms/Cursor.cs b/src/Eto/Forms/Cursor.cs index edd7b74a10..9baedc3bf0 100644 --- a/src/Eto/Forms/Cursor.cs +++ b/src/Eto/Forms/Cursor.cs @@ -167,7 +167,7 @@ public static Cursor FromResource(string resourceName, Type type) { if (type == null) throw new ArgumentNullException(nameof(type)); - return FromResource(resourceName, type.GetAssembly()); + return FromResource(resourceName, type.Assembly); } /// diff --git a/src/Eto/Platform.cs b/src/Eto/Platform.cs index be2b012f8c..5b36fcfa33 100644 --- a/src/Eto/Platform.cs +++ b/src/Eto/Platform.cs @@ -554,7 +554,7 @@ public Func Find(Type type) } // load the handler type assembly and try again (as type could be a derived class) - var handlerAssembly = handler?.Type.GetAssembly(); + var handlerAssembly = handler?.Type.Assembly; if (handlerAssembly != null && !loadedAssemblies.Contains(handlerAssembly)) { LoadAssembly(handlerAssembly); @@ -563,7 +563,7 @@ public Func Find(Type type) } // finally, try the assembly of the current type if we still can't find it - var typeAssembly = type.GetAssembly(); + var typeAssembly = type.Assembly; if (!loadedAssemblies.Contains(typeAssembly)) { LoadAssembly(typeAssembly); @@ -601,17 +601,17 @@ internal HandlerInfo FindHandler(Type type) return info; } // load the assembly of the handler type (needed when type is a subclass) - if (!loadedAssemblies.Contains(handler.Type.GetAssembly())) + if (!loadedAssemblies.Contains(handler.Type.Assembly)) { - LoadAssembly(handler.Type.GetAssembly()); + LoadAssembly(handler.Type.Assembly); return FindHandler(type); } } // load the assembly of the target type (can be a subclass) - if (!loadedAssemblies.Contains(type.GetAssembly())) + if (!loadedAssemblies.Contains(type.Assembly)) { - LoadAssembly(type.GetAssembly()); + LoadAssembly(type.Assembly); return FindHandler(type); } return null; diff --git a/src/Eto/PlatformExtension.cs b/src/Eto/PlatformExtension.cs index 4195bf280c..18797a7bfa 100644 --- a/src/Eto/PlatformExtension.cs +++ b/src/Eto/PlatformExtension.cs @@ -154,7 +154,7 @@ public virtual bool Supports(Platform platform) { if (type.AssemblyQualifiedName == PlatformID) return true; - type = type.GetBaseType(); + type = type.BaseType; } return false; } diff --git a/src/Eto/TypeHelper.cs b/src/Eto/TypeHelper.cs deleted file mode 100644 index 7edd21e862..0000000000 --- a/src/Eto/TypeHelper.cs +++ /dev/null @@ -1,91 +0,0 @@ -namespace Eto -{ - /// - /// Extension methods to provide a consistent . - /// - /// Some of these are from https://gist.github.com/jeffwilcox/2432351 (no attribution requested.) - /// - static class TypeHelper - { - public static Assembly GetAssembly(this Type type) - { - return type.Assembly; - } - - public static Type GetBaseType(this Type type) - { - return type.BaseType; - } - - public static bool IsEnum(this Type type) - { - return type.IsEnum; - } - - public static MethodInfo GetGetMethod(this PropertyInfo propertyInfo) - { - return propertyInfo.GetGetMethod(true); - } - - public static MethodInfo GetSetMethod(this PropertyInfo propertyInfo) - { - return propertyInfo.GetSetMethod(true); - } - - public static T GetCustomAttribute(this Type type, bool inherit) - where T : Attribute - { - return (T)type.GetCustomAttributes(typeof(T), inherit).FirstOrDefault(); - } - - /// - /// Returns a PropertyInfo for the specified property of the current type. - /// The property may be declared on the current type or an ancestor type. - /// - /// - public static PropertyInfo GetRuntimeProperty(this Type type, string propertyName) - { - return type.GetProperty(propertyName); - } - - public static FieldInfo GetRuntimeField(this Type type, string fieldName) - { - return type.GetField(fieldName); - } - - public static EventInfo GetRuntimeEvent(this Type type, string eventName) - { - return type.GetEvent(eventName); - } - - public static IEnumerable GetRuntimeEvents(this Type type) - { - return type.GetEvents(BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic); - } - - public static Delegate CreateDelegate(this MethodInfo method, Type objectType, object instance) - { - return Delegate.CreateDelegate(objectType, instance, method); - } - - public static MethodInfo GetRuntimeMethod(this Type type, string methodName, Type[] parameters) - { - return type.GetMethod(methodName, parameters); - } - - public static IEnumerable GetRuntimeMethods(this Type type) - { - return type.GetMethods(BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic); - } - - public static IEnumerable GetRuntimeProperties(this Type type) - { - return type.GetProperties(BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic); - } - - public static IEnumerable GetRuntimeFields(this Type type) - { - return type.GetFields(BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic); - } - } -} \ No newline at end of file