static void Main()
    {
        ObjStruct[] array = new ObjStruct[10];
        Console.WriteLine(array[0].Test);

        ObjClass[] array = new ObjClass[10];
        Console.WriteLine(array[0].Test);     //NullReferenceException
    }
Esempio n. 2
0
        /// <summary>
        /// Configure a object with the configuration node path
        /// </summary>
        /// <param name="object_guid"></param>
        /// <param name="config_path"></param>
        public void ConfigureObject(String object_guid, params String[] config_path)
        {
            ObjStruct oStr = getObjStruct(object_guid);

            JToken jConfig = oStr.config;

            foreach (String cfg_node in config_path)
            {
                jConfig = jConfig[cfg_node];
            }

            set_properties(ref oStr.obj, jConfig);
        }
Esempio n. 3
0
        /// <summary>
        /// Generic method call with optional parameter object list
        /// </summary>
        /// <param name="object_guid"></param>
        /// <param name="Method_name"></param>
        /// <returns></returns>
        public object MethodCall(String object_guid, String Method_name, object[] overwrited_parameters)
        {
            // get object struct
            ObjStruct oStr = getObjStruct(object_guid);

            // get user method
            JObject jMethod = oStr.methods[Method_name] as JObject;

            if (jMethod != null)
            {
                object  obj     = oStr.obj;
                JObject jParams = jMethod["Parameters"] as JObject;

                // search method Name from jMethod "Name"
                foreach (MethodInfo method in obj.GetType().GetMethods().Where(c => c.Name == jMethod["Name"].ToString()).ToList())
                {
                    // In case of overloaded methods, check method param number. )
                    bool method_conflict = false;
                    if (method.GetParameters().Count() == jParams.Properties().Count())
                    {
                        object[] parameters = null;
                        int      i          = 1;

                        foreach (ParameterInfo pi in method.GetParameters())
                        {
                            // Check method's param name to avoid erroneous call
                            if (jParams[pi.Name] != null)
                            {
                                // set parameters if the overwritten are null
                                if (overwrited_parameters == null)
                                {
                                    Array.Resize(ref parameters, i);
                                    parameters[i - 1] = jParams[pi.Name].ToObject(pi.ParameterType);
                                    i++;
                                }
                            }
                            else
                            {
                                method_conflict = true;
                            }
                        }
                        // Invoke method if there isn't conflicts. Send overwrited parameters if there are not null
                        if (!method_conflict)
                        {
                            return(method.Invoke(obj, (overwrited_parameters != null)? overwrited_parameters: parameters));
                        }
                    }
                }
            }
            return(null);
        }
Esempio n. 4
0
        /// <summary>
        /// Set object property
        /// </summary>
        /// <param name="object_guid"></param>
        /// <param name="property_name"></param>
        /// <param name="property_value"></param>
        public void ConfigureObjectProperty(String object_guid, String property_name, JToken property_value)
        {
            ObjStruct oStr = getObjStruct(object_guid);

            PropertyInfo pi = oStr.obj.GetType().GetProperty(property_name);

            if (pi != null)
            {
                try
                {
                    pi.SetValue(oStr.obj, property_value.ToObject(pi.PropertyType));
                }
                catch (Exception exc)
                {
                    errors.add(String.Format("Error setting property '{0}': {1}", property_name, exc.Message));
                }
            }
            else
            {
                errors.add(String.Format("Error property '{0}' not found.", property_name));
            }
        }
Esempio n. 5
0
	public IEnumerator StartImportation(string file)
	{
		fileText = file;
		allMesh.Clear();
		objStruct = new ObjStruct();
		mtlFileName = "";
		canFinish = false;

		try
		{
			InitMestStruct();
			PopulateMeshStruct();
			CreateMeshStruct();
			canFinish = true;
		}
		catch (Exception e)
		{
#if LOG
			Debug.Log(e.ToString());
#endif
		}
		yield return 0;
	}