mirror of
https://github.com/dcronqvist/DotTiled.git
synced 2025-02-05 17:02:49 +02:00
Make use of generic type parameter in generic methods
This commit is contained in:
parent
64f66421c2
commit
58b0ad3493
3 changed files with 16 additions and 2 deletions
|
@ -111,7 +111,15 @@ public class CustomClassDefinition : HasPropertiesBase, ICustomTypeDefinition
|
||||||
if (type == typeof(string) || !type.IsClass)
|
if (type == typeof(string) || !type.IsClass)
|
||||||
throw new ArgumentException("Type must be a class.", nameof(type));
|
throw new ArgumentException("Type must be a class.", nameof(type));
|
||||||
|
|
||||||
return FromClass(() => Activator.CreateInstance(type));
|
var instance = Activator.CreateInstance(type);
|
||||||
|
var properties = type.GetProperties();
|
||||||
|
|
||||||
|
return new CustomClassDefinition
|
||||||
|
{
|
||||||
|
Name = type.Name,
|
||||||
|
UseAs = CustomClassUseAs.All,
|
||||||
|
Members = properties.Select(p => ConvertPropertyInfoToIProperty(instance, p)).ToList()
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
@ -130,7 +138,7 @@ public class CustomClassDefinition : HasPropertiesBase, ICustomTypeDefinition
|
||||||
public static CustomClassDefinition FromClass<T>(Func<T> factory) where T : class
|
public static CustomClassDefinition FromClass<T>(Func<T> factory) where T : class
|
||||||
{
|
{
|
||||||
var instance = factory();
|
var instance = factory();
|
||||||
var type = instance.GetType();
|
var type = typeof(T);
|
||||||
var properties = type.GetProperties();
|
var properties = type.GetProperties();
|
||||||
|
|
||||||
return new CustomClassDefinition
|
return new CustomClassDefinition
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
|
||||||
namespace DotTiled;
|
namespace DotTiled;
|
||||||
|
@ -44,4 +45,9 @@ public class CustomEnumDefinition : ICustomTypeDefinition
|
||||||
/// Whether the value should be treated as flags.
|
/// Whether the value should be treated as flags.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public bool ValueAsFlags { get; set; }
|
public bool ValueAsFlags { get; set; }
|
||||||
|
|
||||||
|
// public CustomEnumDefinition FromEnum(Type enumType)
|
||||||
|
// {
|
||||||
|
// if (!enumType.Is)
|
||||||
|
// }
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue