浏览代码

Simplify checks in TypeMapper

/main
Peter Bay Bastian 7 年前
当前提交
b174415a
共有 1 个文件被更改,包括 3 次插入3 次删除
  1. 6
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Util/TypeMapper.cs

6
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Util/TypeMapper.cs


public TypeMapper(Type fromBaseType = null, Type toBaseType = null, Type fallbackType = null)
{
if (fallbackType != null && toBaseType != null && !fallbackType.IsSubclassOf(toBaseType))
if (fallbackType != null && toBaseType != null && !toBaseType.IsAssignableFrom(fallbackType))
throw new ArgumentException(string.Format("{0} does not implement or derive from {1}.", fallbackType.Name, toBaseType.Name), "fallbackType");
m_FromBaseType = fromBaseType ?? typeof(object);
m_ToBaseType = toBaseType;

public void Add(Type fromType, Type toType)
{
if (m_FromBaseType != typeof(object) && !fromType.IsSubclassOf(m_FromBaseType) && !fromType.GetInterfaces().Contains(m_FromBaseType))
if (m_FromBaseType != typeof(object) && !m_FromBaseType.IsAssignableFrom(fromType))
if (m_ToBaseType != null && !toType.IsSubclassOf(m_ToBaseType))
if (m_ToBaseType != null && !m_ToBaseType.IsAssignableFrom(toType))
{
throw new ArgumentException(string.Format("{0} does not derive from {1}.", toType.Name, m_ToBaseType.Name), "toType");
}

正在加载...
取消
保存