Exemplo n.º 1
0
        private UnityHttpResponse CreateHttpResponse()
        {
            Type downloadHandlerType = unityWebRequest.downloadHandler.GetType();
            Type responseType        = responseTypeMaps[downloadHandlerType];

            return((UnityHttpResponse)UnityReflectionUtil.CreateInstance(responseType.FullName, BindingFlags.Instance | BindingFlags.NonPublic,
                                                                         new object[] { unityWebRequest, request.StateObject }));
        }
Exemplo n.º 2
0
        /// <summary>
        /// Generates the data table row collection.
        /// </summary>
        /// <param name="table">The data table.</param>
        /// <param name="className">Name of the class.</param>
        /// <param name="rowInfos">The list of DataTableRow.</param>
        /// <returns>The data collection of data table row.</returns>
        private static List <DataTableRow> GenerateDataTableRowCollection(DataTable table, string namespaceString, string className, List <DataTableRowInfo> rowInfos)
        {
            List <DataTableRow> dataCollection = new List <DataTableRow>();
            string classFullName = className;

            if (!string.IsNullOrEmpty(namespaceString))
            {
                classFullName = string.Format("{0}.{1}", namespaceString, classFullName);
            }

            DataTablePreferences preferencesData = DataTablePreferencesWindow.LoadPreferencesData();

            if (preferencesData)
            {
                int rowCount = table.Rows.Count;

                for (int i = preferencesData.DataRowsStartRow - 1; i < rowCount; ++i)
                {
                    DataTableRow rowData = (DataTableRow)UnityReflectionUtil.CreateInstance(classFullName);

                    for (int j = 0, propertiesCount = rowInfos.Count; j < propertiesCount; ++j)
                    {
                        string cellValue = table.Rows[i][j].ToString().Trim();

                        if (!string.IsNullOrEmpty(cellValue))
                        {
                            DataTableRowInfo rowInfo    = rowInfos[j];
                            ITypeParser      typeParser = GetTypeParser(rowInfo.Type);

                            if (typeParser != null)
                            {
                                object value = typeParser.Parse(cellValue);
                                ReflectionUtil.SetObjectPropertyValue(rowData, rowInfo.PropertyName, value);
                            }
                            else
                            {
                                Debug.LogWarningFormat("Type '{0}' is not supported!", rowInfo.Type);
                            }
                        }
                    }

                    dataCollection.Add(rowData);
                }
            }

            return(dataCollection);
        }