Esempio n. 1
0
 private string InArgumentAssignment(Argument argument)
 {
     if (argument.RelatedStateVariable.Type == typeof (string) && argument.RelatedStateVariable.AllowedValues == null) {
         return ToCamelCase (argument.Name);
     } else {
         return ToCamelCase (argument.Name) + ".ToString ()";
     }
 }
Esempio n. 2
0
 private void WriteArgumentAttribute(CodeMonkey monkey, Argument argument)
 {
     if (argument == null) {
         return;
     }
     bool writen = false;
     if (argument.RelatedStateVariable.DefaultValue != null) {
         string value;
         if (argument.RelatedStateVariable.Type == typeof (string)) {
             if (argument.RelatedStateVariable.AllowedValues != null) {
                 value = String.Format (@"""{0}""", argument.RelatedStateVariable.DefaultValue);
             } else {
                 value = String.Format ("{0}.{1}", argument.RelatedStateVariable.Name + "AllowedValues", argument.RelatedStateVariable.DefaultValue);
             }
         } else {
             value = argument.RelatedStateVariable.DefaultValue;
         }
         monkey.Write ("[UpnpArgument (DefaultValue = {0}", value);
         writen = true;
     }
     if (argument.RelatedStateVariable.AllowedValueRange != null) {
         if (!writen) {
             monkey.Write ("[UpnpArgument (");
         } else {
             monkey.Write (", ");
         }
         monkey.Write ("AllowedValueRange = new AllowedValueRange ({0}, {1}, {2})", argument.RelatedStateVariable.AllowedValueRange.Minimum, argument.RelatedStateVariable.AllowedValueRange.Maximum, argument.RelatedStateVariable.AllowedValueRange.Step);
         writen = true;
     }
     if (!IsCamelCase (argument.Name)) {
         if (!writen) {
             monkey.Write (@"[UpnpArgument (""{0}"")]", argument.Name);
         } else {
             monkey.Write (@", Name = ""{0}""", argument.Name);
         }
     }
     if (writen) {
         monkey.Write (")]");
     }
 }
Esempio n. 3
0
 private void WriteMethodParameter(CodeMonkey monkey, Argument argument)
 {
     if (argument.Direction == ArgumentDirection.Out) {
         monkey.Write ("out ");
     }
     if (argument.RelatedStateVariable.AllowedValues != null) {
         monkey.Write ("{0}AllowedValues {1}", argument.RelatedStateVariable.Name, ToCamelCase (argument.Name));
     } else {
         monkey.Write ("{0} {1}", GetTypeName (argument.RelatedStateVariable.Type), ToCamelCase (argument.Name));
     }
 }
 public static void AssertEquality (Argument sourceArgument, Argument targetArgument)
 {
     Assert.AreEqual (sourceArgument.Name, targetArgument.Name);
     Assert.AreEqual (sourceArgument.Direction, targetArgument.Direction);
     Assert.AreEqual (sourceArgument.IsReturnValue, targetArgument.IsReturnValue);
     Assert.AreEqual (sourceArgument.RelatedStateVariable, targetArgument.RelatedStateVariable);
 }
Esempio n. 5
0
 private void WriteArgumentParameterDefinition(CodeMonkey monkey, Argument argument)
 {
     if (argument.RelatedStateVariable.AllowedValues != null) {
         monkey.Write ("{0} {1}", EnumerationNames[argument.RelatedStateVariable], ToCamelCase (argument.Name));
     } else {
         monkey.Write ("{0} {1}", GetTypeName (argument.RelatedStateVariable.Type), ToCamelCase (argument.Name));
     }
 }
        void VerifyArgumentValue(Argument argument, string value)
        {
            if (argument.RelatedStateVariable == null) {
                return;
            }

            var type = argument.RelatedStateVariable.Type;
            var values = argument.RelatedStateVariable.AllowedValues;
            if (values != null && type == typeof (string) && !values.Contains (value)) {
                throw new ArgumentException (
                    string.Format ("The value {0} is not allowed for the argument {1}.", value, argument.Name));
            }

            var range = argument.RelatedStateVariable.AllowedValueRange;
            if (range != null && type is IComparable) {
                var parse = type.GetMethod ("Parse", BindingFlags.Public | BindingFlags.Static);
                var arg = parse.Invoke (null, new object[] { value });
                if (range.Min == null) {
                    range.Min = (IComparable)parse.Invoke (null, new object[] { range.Minimum });
                    range.Max = (IComparable)parse.Invoke (null, new object[] { range.Maximum });
                }
                if (range.Min.CompareTo (arg) > 0) {
                    throw new ArgumentOutOfRangeException (argument.Name, value, string.Format (
                        "The value is less than {0}.", range.Minimum));
                } else if (range.Max.CompareTo (arg) < 0) {
                    throw new ArgumentOutOfRangeException (argument.Name, value, string.Format (
                        "The value is greater than {0}.", range.Maximum));
                }
            }
        }
        protected void AddArgument(Argument argument)
        {
            if (argument == null) throw new ArgumentNullException ("argument");

            if (argument.Direction == ArgumentDirection.In) {
                in_arguments.SetItem (argument.Name, argument);
            } else {
                if (argument.IsReturnValue && !bypass_return_argument) {
                    if (ReturnArgument == null) {
                        ReturnArgument = argument;
                    } else {
                        out_arguments.SetItem (ReturnArgument.Name, ReturnArgument);
                        out_arguments.SetItem (argument.Name, argument);
                        ReturnArgument = null;
                        bypass_return_argument = true;
                        Log.Exception (new UpnpDeserializationException (
                            string.Format ("{0} has multiple return values.", ToString ())));
                    }
                } else {
                    out_arguments.SetItem (argument.Name, argument);
                }
            }
        }
 void VerifyRelatedStateVariable(Argument argument)
 {
     if (argument.RelatedStateVariable == null) {
         Log.Exception (new UpnpDeserializationException (
             string.Format ("{0} does not have a related state variable.", argument)));
     }
 }