Пример #1
0
        public override object ReadJson(JsonReader reader, Type objectType, object existingValue,
                                        JsonSerializer serializer)
        {
            // Load the JSON for the OpticalProperties into a JObject
            JObject jo = JObject.Load(reader);

            // Read the properties which will be used as constructor parameters
            double mua = (double)jo["Mua"];
            double g = (double)jo["G"];
            double n = (double)jo["N"];
            double mus = 0, musp = 0; // possible trouble setting these to 0

            // check Musp last so that it forces Mus as the code used to
            if (jo["Mus"] != null) // Mus in OPs
            {
                mus = (double)jo["Mus"];
                if (g == 1)
                {
                    musp = mus;
                }
                else
                {
                    musp = mus * (1 - g);
                }
            }
            if (jo["Musp"] != null) // Musp in OPs
            {
                musp = (double)jo["Musp"];
            }

            // Construct the OpticalProperties using the non-default constructor
            OpticalProperties opticalProperties = new OpticalProperties(mua, musp, g, n);

            // (If anything else needs to be populated on the result object, do that here)

            return(opticalProperties);
        }
Пример #2
0
 /// <summary>
 /// Creates a new instance based on values from a previous instance
 /// </summary>
 /// <param name="op">optical properties of the medium</param>
 public OpticalProperties(OpticalProperties op)
     : this(op.Mua, op.Musp, op.G, op.N)
 {
 }