Konstantin Koch 8287c54432 Included the Visual Studio extension and made the necessary changes to make it run.
Replaced the old VS templates with ones that offer more flexiblity.
Started replacing the Content Project for the samples with our custom project type.
Inlcuded a basic not yet working AssimpImporter.
2015-04-08 14:50:03 +02:00

40 lines
1.6 KiB
C#

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Reflection;
using System.Text;
namespace ANX.Framework.Content.Pipeline.Helpers
{
public static class PropertyExtensions
{
public static TypeConverter GetConverter(this PropertyInfo property)
{
TypeConverterAttribute typeConverterAttribute = (TypeConverterAttribute)property.GetCustomAttributes(typeof(TypeConverterAttribute), true).FirstOrDefault();
if (typeConverterAttribute != null && typeConverterAttribute.ConverterTypeName != null && typeConverterAttribute.ConverterTypeName.Length > 0)
{
Type converterType = TypeHelper.GetType(typeConverterAttribute.ConverterTypeName);
if (converterType != null && typeof(TypeConverter).IsAssignableFrom(converterType))
{
return (TypeConverter)CreateInstance(converterType, property.PropertyType);
}
}
return TypeDescriptor.GetConverter(property.PropertyType);
}
private static object CreateInstance(Type targetType, Type typeParam)
{
var parameterTypes = new Type[] { typeof(Type) };
ConstructorInfo constructor = targetType.GetConstructor(parameterTypes);
if (constructor != null)
{
return TypeDescriptor.CreateInstance(null, targetType, parameterTypes, new object[] { typeParam });
}
return TypeDescriptor.CreateInstance(null, targetType, null, null);
}
}
}