Skip to content

Commit

Permalink
Merge pull request #2661 from cwensley/curtis/remove-type-helper
Browse files Browse the repository at this point in the history
Remove TypeHelper which was used for netstandard1.0 support
  • Loading branch information
cwensley authored Jun 3, 2024
2 parents 36ca020 + 258515c commit 6a80f14
Show file tree
Hide file tree
Showing 19 changed files with 33 additions and 126 deletions.
2 changes: 1 addition & 1 deletion src/Eto.Serialization.Json/DefaultNamespaceManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
Expand Down
1 change: 0 additions & 1 deletion src/Eto.Serialization.Json/Eto.Serialization.Json.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ https://github.com/picoe/Eto/wiki
</PropertyGroup>

<ItemGroup>
<Compile Include="..\Eto\TypeHelper.cs" />
<None Remove="Eto.Serialization.Json.targets" />
<None Include="Eto.Serialization.Json.targets" Pack="true" PackagePath="build" />
</ItemGroup>
Expand Down
4 changes: 2 additions & 2 deletions src/Eto.Serialization.Json/JsonReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -106,7 +106,7 @@ public static void Load<T>(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<T>(stream, instance, namespaceManager);
}
Expand Down
1 change: 0 additions & 1 deletion src/Eto.Serialization.Xaml/Eto.Serialization.Xaml.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ https://github.com/picoe/Eto/wiki
</PropertyGroup>

<ItemGroup>
<Compile Include="..\Eto\TypeHelper.cs" />
<None Remove="Eto.Serialization.Xaml.targets" />
<None Include="Eto.Serialization.Xaml.targets" Pack="true" PackagePath="build" />
</ItemGroup>
Expand Down
12 changes: 6 additions & 6 deletions src/Eto.Serialization.Xaml/XamlReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

/// <summary>
Expand Down Expand Up @@ -115,7 +115,7 @@ public static void Load<T>(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<T>(stream, instance);
}
Expand Down Expand Up @@ -146,7 +146,7 @@ public static T Load<T>(Stream stream, T instance)
{
var readerSettings = new XamlXmlReaderSettings();
if (!DesignMode)
readerSettings.LocalAssembly = typeof(T).GetAssembly();
readerSettings.LocalAssembly = typeof(T).Assembly;
return Load<T>(new XamlXmlReader(stream, context, readerSettings), instance);
}

Expand All @@ -161,7 +161,7 @@ public static T Load<T>(TextReader reader, T instance)
{
var readerSettings = new XamlXmlReaderSettings();
if (!DesignMode)
readerSettings.LocalAssembly = typeof(T).GetAssembly();
readerSettings.LocalAssembly = typeof(T).Assembly;
return Load<T>(new XamlXmlReader(reader, context, readerSettings), instance);
}

Expand All @@ -176,7 +176,7 @@ public static T Load<T>(XmlReader reader, T instance)
{
var readerSettings = new XamlXmlReaderSettings();
if (!DesignMode)
readerSettings.LocalAssembly = typeof(T).GetAssembly();
readerSettings.LocalAssembly = typeof(T).Assembly;
return Load<T>(new XamlXmlReader(reader, context, readerSettings), instance);
}

Expand Down
2 changes: 1 addition & 1 deletion src/Eto/DefaultStyleProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ IList<Action<object>> 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();
Expand Down
2 changes: 1 addition & 1 deletion src/Eto/Drawing/Bitmap.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

/// <summary>
Expand Down
2 changes: 1 addition & 1 deletion src/Eto/Drawing/Icon.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

/// <summary>
Expand Down
12 changes: 6 additions & 6 deletions src/Eto/EventLookup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ namespace Eto;
static class EventLookup
{
static readonly Dictionary<Type, List<EventDeclaration>> registeredEvents = new Dictionary<Type, List<EventDeclaration>>();
static readonly Assembly etoAssembly = typeof(EventLookup).GetAssembly();
static readonly Assembly etoAssembly = typeof(EventLookup).Assembly;
static readonly Dictionary<Type, string[]> externalEvents = new Dictionary<Type, string[]>();

struct EventDeclaration
Expand All @@ -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)
Expand All @@ -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;
Expand All @@ -68,14 +68,14 @@ static IEnumerable<string> 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++)
{
Expand All @@ -91,7 +91,7 @@ static IEnumerable<string> FindTypeEvents(Type type)
{
externalTypes.Add(current);
}
current = current.GetBaseType();
current = current.BaseType;
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/Eto/Forms/Binding/BindingExtensionsNonGeneric.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion src/Eto/Forms/Binding/IndirectBinding.cs
Original file line number Diff line number Diff line change
Expand Up @@ -379,7 +379,7 @@ public IndirectBinding<TNewValue> Child<TNewValue>(IndirectBinding<TNewValue> bi
public IndirectBinding<string> 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<object, string>(
m => System.Convert.ToString(GetValue(m)),
Expand Down
4 changes: 2 additions & 2 deletions src/Eto/Forms/Cells/PropertyCell.cs
Original file line number Diff line number Diff line change
Expand Up @@ -676,7 +676,7 @@ public class PropertyCellTypeEnum : PropertyCellType<object>
/// <param name="itemType">Item type.</param>
public override bool CanDisplay(object itemType)
{
return (itemType as Type)?.IsEnum() == true;
return (itemType as Type)?.IsEnum == true;
}

/// <summary>
Expand Down Expand Up @@ -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))
Expand Down
2 changes: 1 addition & 1 deletion src/Eto/Forms/Controls/EnumCheckBoxList.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion src/Eto/Forms/Controls/EnumDropDown.cs
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ protected virtual void OnAddValue(AddValueEventArgs<T> e)
protected override IEnumerable<object> 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();
Expand Down
2 changes: 1 addition & 1 deletion src/Eto/Forms/Controls/EnumRadioButtonList.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ protected virtual void OnAddValue(AddValueEventArgs<T> 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();
Expand Down
2 changes: 1 addition & 1 deletion src/Eto/Forms/Cursor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

/// <summary>
Expand Down
12 changes: 6 additions & 6 deletions src/Eto/Platform.cs
Original file line number Diff line number Diff line change
Expand Up @@ -554,7 +554,7 @@ public Func<object> 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);
Expand All @@ -563,7 +563,7 @@ public Func<object> 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);
Expand Down Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/Eto/PlatformExtension.cs
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ public virtual bool Supports(Platform platform)
{
if (type.AssemblyQualifiedName == PlatformID)
return true;
type = type.GetBaseType();
type = type.BaseType;
}
return false;
}
Expand Down
91 changes: 0 additions & 91 deletions src/Eto/TypeHelper.cs

This file was deleted.

0 comments on commit 6a80f14

Please sign in to comment.