private static String RequiredAttrToString(OpDef.Types.AttrDef a) { String funcName = "SetAttr"; if (a.Type == "shape") { funcName = "SetAttrShape"; } else if (a.Type == "list(shape)") { funcName = "SetAttrShapeList"; } return(String.Format("{2}desc.{1}(\"{0}\", {0});", a.Name, funcName, _nineSpaces)); }
private static String OptionalAttrToString(OpDef.Types.AttrDef a) { String funcName = "SetAttr"; if (a.Type == "shape") { funcName = "SetAttrShape"; } else if (a.Type == "list(shape)") { funcName = "SetAttrShapeList"; } if (!String.IsNullOrEmpty(IsTypeList(a.Type))) { //if this is a list return(String.Format( "{2}if ({0} != null) desc.{1}(\"{0}\", {0});", a.Name, funcName, _nineSpaces)); } if (_typeIsStruct[a.Type]) { if (a.Type.Equals("int")) { return(String.Format("{3}if ({0} != {1}) desc.{2}(\"{0}\", {0});", a.Name, a.DefaultValue.I, funcName, _nineSpaces)); } else if (a.Type.Equals("bool")) { return(String.Format("{3}if ({0} != {1}) desc.{2}(\"{0}\", {0});", a.Name, a.DefaultValue.B ? "true" : "false", funcName, _nineSpaces)); } else if (a.Type.Equals("float")) { String valueString = a.DefaultValue.F.ToString(); if (Single.IsPositiveInfinity(a.DefaultValue.F)) { valueString = "Single.PositiveInfinity"; } else if (Single.IsNegativeInfinity(a.DefaultValue.F)) { valueString = "Single.NegativeInfinity"; } else { valueString = valueString + "f"; } return(String.Format( "{3}if ({0} != {1}) desc.{2}(\"{0}\", {0});", a.Name, valueString, funcName, _nineSpaces)); } else { return(String.Format( "{2}if ({0}.HasValue) desc.{1}(\"{0}\", {0}.Value);", a.Name, funcName, _nineSpaces)); } } else { return(String.Format("{3}if ({0}{1}) desc.{2}(\"{0}\", {0});", a.Name, " != null", funcName, _nineSpaces)); } }