コード例 #1
0
        T GetReturnValue <T> (ScriptParmCategory parmCategory, object result)
        {
            Type type = typeof(T);

            if (result == null)
            {
                return(default(T));
            }

            else if (parmCategory == ScriptParmCategory.ScriptObjectCollection)
            {
                var objArray = result as object[];
                if (objArray == null)
                {
                    return(default(T));
                }

                try
                {
                    var array = Array.CreateInstance(type.GetGenericArguments()[0], objArray.Length);
                    for (int a = 0; a < array.Length; a++)
                    {
                        array.SetValue(Activator.CreateInstance(type.GetGenericArguments()[0], BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic, null, new object[] { objArray[a] }, null), a);
                    }
                    return((T)Activator.CreateInstance(type, BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic, null, new object[] { array }, null));
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                    return(default(T));
                }
            }
            else if (parmCategory == ScriptParmCategory.ScriptableType)
            {
                return(ScriptObjectHelper.AnonymousObjectToScriptableType <T>(result));
            }
            else if (parmCategory == ScriptParmCategory.ScriptableTypeArray)
            {
                try
                {
                    var objArray  = result as object[];
                    var arrayType = type.GetElementType();
                    var array     = Array.CreateInstance(arrayType, objArray.Length);
                    for (int a = 0; a < array.Length; a++)
                    {
                        array.SetValue(ScriptObjectHelper.AnonymousObjectToScriptableType(arrayType, objArray[a]), a);
                    }
                    return((T)(object)array);
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                }
                return((T)Activator.CreateInstance(type, BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic, null, new object[] { result }, null));
            }
            else
            {
                return((T)Activator.CreateInstance(type, BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic, null, new object[] { result }, null));
            }
        }
コード例 #2
0
        internal static object MapToType(ScriptParmCategory category, int arrayFlag, object toMap, Type type = null)
        {
            if (toMap == null)
            {
                return(null);
            }

            switch (category)
            {
            case ScriptParmCategory.ScriptableType:
                return(ScriptObjectHelper.AnonymousObjectToScriptableType(type, toMap));

            case ScriptParmCategory.ScriptObject:
                return(ScriptObjectHelper.AnonymousObjectToScriptObjectProxy(toMap));

            default:
                return(toMap);
            }
        }
コード例 #3
0
        internal static object MapToType(ScriptParmCategory category, int arrayFlag, object toMap, Type type = null, Action preventDefaultAction = null)
        {
            if (toMap == null)
            {
                return(null);
            }

            switch (category)
            {
            case ScriptParmCategory.ScriptableType:
                return(ScriptObjectHelper.AnonymousObjectToScriptableType(type, toMap, preventDefaultAction));

            case ScriptParmCategory.ScriptObject:
                return(ScriptObjectHelper.AnonymousObjectToScriptObjectType(type, toMap));

            case ScriptParmCategory.ScriptableTypeArray:
                try
                {
                    var objArray  = toMap as object[];
                    var arrayType = type.GetElementType();
                    var array     = Array.CreateInstance(arrayType, objArray.Length);
                    for (int a = 0; a < array.Length; a++)
                    {
                        array.SetValue(ScriptObjectHelper.AnonymousObjectToScriptableType(arrayType, objArray[a]), a);
                    }
                    return(array);
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                }
                return(toMap);

            default:
                return(toMap);
            }
        }