예제 #1
0
        public T getValue <T>()
        {
            //callbackMethod
            _update();

            ValueSpecification vSpec = null;

            if (values.Count == 1)
            {
                foreach (ValueSpecification valueSpec in values.Values)
                {
                    vSpec = valueSpec;
                }
            }

            // Check if value exist
            if (vSpec == null)
            {
                return(default(T));
            }

            // Check if value is a Litteral Specification
            if (vSpec.GetType().IsSubclassOf(typeof(LiteralSpecification)))
            {
                // The value exist now get the Classifier
                Type         type  = typeof(T);
                IConvertible value = null;
                if (type.Equals(typeof(System.Boolean)))
                {
                    value = vSpec.getBoolFromValue();
                }
                else if (type.Equals(typeof(System.Int32)))
                {
                    value = vSpec.getIntFromValue();
                }
                else if (type.Equals(typeof(System.Double)) || type.Equals(typeof(System.Single)))
                {
                    value = vSpec.getDoubleFromValue();
                }
                else
                {
                    value = vSpec.getStringFromValue();
                }

                return((T)value);
            }
            else
            {
                throw new Exception("Can not use this method with this kind of Value");
            }
        }
예제 #2
0
 public void _addValue(ValueSpecification element)
 {
     if (definingProperty.MaximumNumber == 1 && values.Keys.Count == 1)
     {
         values.Clear();
     }
     else if (values.Keys.Count > definingProperty.MaximumNumber && definingProperty.MaximumNumber != -1)
     {
         System.Console.WriteLine("Slot::addValue Error : " + definingProperty.name + " number of value is " + values.Keys.Count + " maximum is " + definingProperty.MaximumNumber);
     }
     if (element != null)
     {
         values.Add(element.getStringFromValue(), element);
     }
     //calbakcs functions call
 }
예제 #3
0
        public Dictionary <string, T> getValues <T> ()
        {
            //callbackMethod
            _update();

            Dictionary <string, T> dict = new Dictionary <string, T>();

            foreach (KeyValuePair <string, ValueSpecification> pair in values)
            {
                // Check if value is a Litteral Specification
                ValueSpecification vSpec = pair.Value;
                if (vSpec.GetType().IsSubclassOf(typeof(LiteralSpecification)))
                {
                    // The value exist now get the Classifier
                    Type         type  = typeof(T);
                    IConvertible value = null;
                    if (type.Equals(typeof(System.Boolean)))
                    {
                        value = vSpec.getBoolFromValue();
                    }
                    else if (type.Equals(typeof(System.Int32)))
                    {
                        value = vSpec.getIntFromValue();
                    }
                    else if (type.Equals(typeof(System.Double)) || type.Equals(typeof(System.Single)))
                    {
                        value = vSpec.getDoubleFromValue();
                    }
                    else
                    {
                        value = vSpec.getStringFromValue();
                    }

                    dict.Add(pair.Key, (T)value);
                }
            }

            return(dict);
        }