//Methods //-Public public static string ArrayToString(float[] far, string str = "Printing Array:", int specialsize = 0, ArrayTypes at = ArrayTypes.Regular) { int size; string ret = ""; //Console.WriteLine(Misc.Misc.ArrayToString(quadnew.VAI.Data)); if(specialsize == 0) { size = far.Length; } else { size = specialsize; } ret += str + Environment.NewLine; for(uint ui = 0; ui < size; ui++) { if(ui > 0) { if(at == ArrayTypes.Regular) { if(ui % 10 == 0) { ret += Environment.NewLine; } } else if(at == ArrayTypes.Vertex || at == ArrayTypes.Colors) { if(ui % 3 == 0) { ret += Environment.NewLine; } } else if(at == ArrayTypes.TexCoords) { if(ui % 2 == 0) { ret += Environment.NewLine; } } } ret += far[ui].ToString() + ", "; } ret += Environment.NewLine; return ret; }
private void AddTypeExtension(ref StringBuilderWrapper sbExt, MetadataType type, bool initCollections) { //Swift doesn't support extensions on same protocol used by Base and Sub types if (type.IsAbstract()) { return; } var typeName = Type(type.Name, type.GenericArgs); typeName = typeName.LeftPart('<'); // Type<QueryResponse<T>> into correct mapping Type<QueryResponse> var typeNameOnly = typeName.LeftPart('<'); sbExt.AppendLine(); sbExt.AppendLine("extension {0} : JsonSerializable".Fmt(typeNameOnly)); sbExt.AppendLine("{"); sbExt = sbExt.Indent(); sbExt.AppendLine("public static var typeName:String {{ return \"{0}\" }}".Fmt(typeName)); //func typeConfig() var isGenericType = type.GenericArgs?.Length > 0 || type.Inherits?.GenericArgs?.Length > 0; if (!isGenericType) { sbExt.AppendLine("public static var metadata = Metadata.create(["); sbExt = sbExt.Indent(); } else { //Swift 2.0 doesn't allow stored static properties on generic types yet sbExt.AppendLine("public static var metadata:Metadata {"); sbExt = sbExt.Indent(); sbExt.AppendLine("return Metadata.create(["); } sbExt = sbExt.Indent(); foreach (var prop in GetPropertes(type)) { var propType = FindType(prop.Type, prop.TypeNamespace, prop.GenericArgs); if (propType.IsInterface() || IgnorePropertyTypeNames.Contains(prop.Type) || IgnorePropertyNames.Contains(prop.Name)) { continue; } var fnName = "property"; if (prop.IsArray() || ArrayTypes.Contains(prop.Type)) { fnName = initCollections ? "arrayProperty" : "optionalArrayProperty"; } else if (DictionaryTypes.Contains(prop.Type)) { fnName = initCollections ? "objectProperty" : "optionalObjectProperty"; } else { if (propType != null && !propType.IsEnum.GetValueOrDefault()) { fnName = "optionalObjectProperty"; } else { fnName = "optionalProperty"; } } var propName = prop.Name.SafeToken().PropertyStyle(); var unescapedName = propName.UnescapeReserved(); sbExt.AppendLine("Type<{0}>.{1}(\"{2}\", get: {{ $0.{3} }}, set: {{ $0.{3} = $1 }}),".Fmt( typeName, fnName, unescapedName, propName)); } sbExt = sbExt.UnIndent(); sbExt.AppendLine("])"); sbExt = sbExt.UnIndent(); if (isGenericType) { sbExt.AppendLine("}"); } sbExt = sbExt.UnIndent(); sbExt.AppendLine("}"); }
public void AddProperties(StringBuilderWrapper sb, MetadataType type, bool initCollections) { var wasAdded = false; var dataMemberIndex = 1; if (type.Properties != null) { foreach (var prop in type.Properties) { if (wasAdded) { sb.AppendLine(); } var propType = Type(prop.Type, prop.GenericArgs); var optional = ""; var defaultValue = ""; if (propType.EndsWith("?")) { propType = propType.Substring(0, propType.Length - 1); optional = "?"; } if (Config.MakePropertiesOptional) { optional = "?"; } if (prop.Attributes.Safe().FirstOrDefault(x => x.Name == "Required") != null) { optional = "?"; //always use optional } if (prop.IsArray()) { optional = ""; defaultValue = " = []"; } else if (initCollections && !prop.GenericArgs.IsEmpty()) { if (ArrayTypes.Contains(prop.Type)) { optional = ""; defaultValue = " = []"; } if (DictionaryTypes.Contains(prop.Type)) { optional = ""; defaultValue = " = [:]"; } } wasAdded = AppendDataMember(sb, prop.DataMember, dataMemberIndex++); wasAdded = AppendAttributes(sb, prop.Attributes) || wasAdded; if (type.IsInterface()) { sb.AppendLine("var {0}:{1}{2} {{ get set }}".Fmt( prop.Name.SafeToken().PropertyStyle(), propType, optional)); } else { sb.AppendLine("public var {0}:{1}{2}{3}".Fmt( prop.Name.SafeToken().PropertyStyle(), propType, optional, defaultValue)); } } } if (Config.AddResponseStatus && (type.Properties == null || type.Properties.All(x => x.Name != "ResponseStatus"))) { if (wasAdded) { sb.AppendLine(); } AppendDataMember(sb, null, dataMemberIndex++); sb.AppendLine("public var {0}:ResponseStatus".Fmt("ResponseStatus".PropertyStyle())); } }
private void AddTypeExtension(ref StringBuilderWrapper sbExt, MetadataType type, bool initCollections) { //Swift doesn't support extensions on same protocol used by Base and Sub types if (Config.FlattenAbstractTypes && type.IsAbstract()) { return; } var typeProperties = type.Properties.Safe().ToList(); if (Config.FlattenAbstractTypes) { var baseType = FindType(type.Inherits); if (baseType != null && baseType.IsAbstract()) { typeProperties.InsertRange(0, baseType.Properties.Safe()); } } var typeName = Type(type.Name, type.GenericArgs); var typeNameOnly = typeName.SplitOnFirst('<')[0]; sbExt.AppendLine(); sbExt.AppendLine("extension {0} : JsonSerializable".Fmt(typeNameOnly)); sbExt.AppendLine("{"); sbExt = sbExt.Indent(); //func typeConfig() sbExt.AppendLine("public class func typeConfig() -> JsConfigType<{0}>".Fmt(typeName)); sbExt.AppendLine("{"); sbExt = sbExt.Indent(); sbExt.AppendLine( "return JsConfig.typeConfig() ?? JsConfig.configure(JsConfigType<{0}>(".Fmt(typeName)); sbExt = sbExt.Indent(); sbExt.AppendLine("writers: ["); sbExt = sbExt.Indent(); foreach (var prop in typeProperties) { var isOptional = !(initCollections && (prop.IsArray() || (!prop.GenericArgs.IsEmpty() && (ArrayTypes.Contains(prop.Type) || DictionaryTypes.Contains(prop.Type))) )); var fn = isOptional ? "setOptionalValue" : "setValue"; sbExt.AppendLine("(\"{1}\", {{ (x:{0}, map:NSDictionary) in {2}(&x.{1}, map, \"{1}\") }}),".Fmt( typeName, prop.Name.SafeToken().PropertyStyle(), fn)); } sbExt = sbExt.UnIndent(); sbExt.AppendLine("],"); sbExt.AppendLine("readers: ["); sbExt = sbExt.Indent(); foreach (var prop in typeProperties) { sbExt.AppendLine("(\"{1}\", Type<{0}>.value {{ $0.{1} }}),".Fmt( typeName, prop.Name.SafeToken().PropertyStyle())); } sbExt = sbExt.UnIndent(); sbExt.AppendLine("]"); sbExt = sbExt.UnIndent(); sbExt.AppendLine("))"); sbExt = sbExt.UnIndent(); sbExt.AppendLine("}"); //toJson() sbExt.AppendLine(); sbExt.AppendLine("public func toJson() -> String"); sbExt.AppendLine("{"); sbExt = sbExt.Indent(); sbExt.AppendLine("return serializeToJson(self, {0}.typeConfig())".Fmt(typeName)); sbExt = sbExt.UnIndent(); sbExt.AppendLine("}"); //fromDictionary() sbExt.AppendLine(); sbExt.AppendLine("public class func fromDictionary(map:NSDictionary) -> {0}".Fmt(typeName)); sbExt.AppendLine("{"); sbExt = sbExt.Indent(); sbExt.AppendLine("return populate({0}(), map, {0}.typeConfig())".Fmt(typeName)); sbExt = sbExt.UnIndent(); sbExt.AppendLine("}"); //fromJson() sbExt.AppendLine(); sbExt.AppendLine("public class func fromJson(json:String) -> {0}".Fmt(typeName)); sbExt.AppendLine("{"); sbExt = sbExt.Indent(); sbExt.AppendLine("return populate({0}(), json, {0}.typeConfig())".Fmt(typeName)); sbExt = sbExt.UnIndent(); sbExt.AppendLine("}"); sbExt = sbExt.UnIndent(); sbExt.AppendLine("}"); }
public void AddProperties(StringBuilderWrapper sb, MetadataType type, bool initCollections, bool includeResponseStatus) { var wasAdded = false; var dataMemberIndex = 1; foreach (var prop in type.Properties.Safe()) { if (wasAdded) { sb.AppendLine(); } var propTypeName = Type(prop.Type, prop.GenericArgs); var propType = FindType(prop.Type, prop.TypeNamespace, prop.GenericArgs); var optional = ""; var defaultValue = ""; if (propTypeName.EndsWith("?")) { propTypeName = propTypeName.Substring(0, propTypeName.Length - 1); optional = "?"; } if (Config.MakePropertiesOptional) { optional = "?"; } if (prop.Attributes.Safe().FirstOrDefault(x => x.Name == "Required") != null) { optional = "?"; //always use optional } if (prop.IsArray()) { optional = ""; defaultValue = " = []"; } else if (initCollections && !prop.GenericArgs.IsEmpty()) { if (ArrayTypes.Contains(prop.Type)) { optional = ""; defaultValue = " = []"; } if (DictionaryTypes.Contains(prop.Type)) { optional = ""; defaultValue = " = [:]"; } } if (propType.IsInterface() || IgnorePropertyNames.Contains(prop.Name)) { sb.AppendLine("//{0}:{1} ignored. Swift doesn't support interface properties" .Fmt(prop.Name.SafeToken().PropertyStyle(), propTypeName)); continue; } else if (IgnorePropertyTypeNames.Contains(propTypeName)) { sb.AppendLine("//{0}:{1} ignored. Type could not be extended in Swift" .Fmt(prop.Name.SafeToken().PropertyStyle(), propTypeName)); continue; } wasAdded = AppendComments(sb, prop.Description); wasAdded = AppendDataMember(sb, prop.DataMember, dataMemberIndex++) || wasAdded; wasAdded = AppendAttributes(sb, prop.Attributes) || wasAdded; if (type.IsInterface()) { sb.AppendLine("var {0}:{1}{2} {{ get set }}".Fmt( prop.Name.SafeToken().PropertyStyle(), propTypeName, optional)); } else { sb.AppendLine("public var {0}:{1}{2}{3}".Fmt( prop.Name.SafeToken().PropertyStyle(), propTypeName, optional, defaultValue)); } } if (includeResponseStatus) { if (wasAdded) { sb.AppendLine(); } AppendDataMember(sb, null, dataMemberIndex++); sb.AppendLine("public var {0}:ResponseStatus?".Fmt(typeof(ResponseStatus).Name.PropertyStyle())); } }
private void AddTypeExtension(ref StringBuilderWrapper sbExt, MetadataType type, bool initCollections) { //Swift doesn't support extensions on same protocol used by Base and Sub types if (type.IsAbstract()) { return; } var typeName = Type(type.Name, type.GenericArgs); var typeNameOnly = typeName.SplitOnFirst('<')[0]; sbExt.AppendLine(); sbExt.AppendLine("extension {0} : JsonSerializable".Fmt(typeNameOnly)); sbExt.AppendLine("{"); sbExt = sbExt.Indent(); sbExt.AppendLine("public static var typeName:String {{ return \"{0}\" }}".Fmt(typeName)); //func typeConfig() sbExt.AppendLine("public static func reflect() -> Type<{0}> {{".Fmt(typeName)); sbExt = sbExt.Indent(); sbExt.AppendLine( "return TypeConfig.config() ?? TypeConfig.configure(Type<{0}>(".Fmt(typeName)); sbExt = sbExt.Indent(); sbExt.AppendLine("properties: [".Fmt(typeName)); sbExt = sbExt.Indent(); foreach (var prop in GetPropertes(type)) { var propType = FindType(prop.Type, prop.TypeNamespace, prop.GenericArgs); if (propType.IsInterface() || IgnorePropertyTypeNames.Contains(prop.Type) || IgnorePropertyNames.Contains(prop.Name)) { continue; } var fnName = "property"; if (prop.IsArray() || ArrayTypes.Contains(prop.Type)) { fnName = initCollections ? "arrayProperty" : "optionalArrayProperty"; } else if (DictionaryTypes.Contains(prop.Type)) { fnName = initCollections ? "objectProperty" : "optionalObjectProperty"; } else { if (propType != null && !propType.IsEnum.GetValueOrDefault()) { fnName = "optionalObjectProperty"; } else { fnName = "optionalProperty"; } } sbExt.AppendLine("Type<{0}>.{1}(\"{2}\", get: {{ $0.{2} }}, set: {{ $0.{2} = $1 }}),".Fmt( typeName, fnName, prop.Name.SafeToken().PropertyStyle())); } sbExt = sbExt.UnIndent(); sbExt.AppendLine("]))"); sbExt = sbExt.UnIndent(); sbExt = sbExt.UnIndent(); sbExt.AppendLine("}"); //toJson() sbExt.AppendLine("public func toJson() -> String {"); sbExt = sbExt.Indent(); sbExt.AppendLine("return {0}.reflect().toJson(self)".Fmt(typeName)); sbExt = sbExt.UnIndent(); sbExt.AppendLine("}"); //fromJson() sbExt.AppendLine("public static func fromJson(json:String) -> {0}? {{".Fmt(typeName)); sbExt = sbExt.Indent(); sbExt.AppendLine("return {0}.reflect().fromJson({0}(), json: json)".Fmt(typeName)); sbExt = sbExt.UnIndent(); sbExt.AppendLine("}"); //fromObject() sbExt.AppendLine("public static func fromObject(any:AnyObject) -> {0}? {{".Fmt(typeName)); sbExt = sbExt.Indent(); sbExt.AppendLine("return {0}.reflect().fromObject({0}(), any:any)".Fmt(typeName)); sbExt = sbExt.UnIndent(); sbExt.AppendLine("}"); //toString() sbExt.AppendLine("public func toString() -> String {"); sbExt = sbExt.Indent(); sbExt.AppendLine("return {0}.reflect().toString(self)".Fmt(typeName)); sbExt = sbExt.UnIndent(); sbExt.AppendLine("}"); //fromString() sbExt.AppendLine("public static func fromString(string:String) -> {0}? {{".Fmt(typeName)); sbExt = sbExt.Indent(); sbExt.AppendLine("return {0}.reflect().fromString({0}(), string: string)".Fmt(typeName)); sbExt = sbExt.UnIndent(); sbExt.AppendLine("}"); sbExt = sbExt.UnIndent(); sbExt.AppendLine("}"); }
public ArrayRow(int[] _row, ArrayTypes _arrayType, int _rowIndex) { row = _row; arrayType = _arrayType; rowIndex = _rowIndex; }
public ArrayClass(ArrayTypes t, GameObject o) { this.Type = t; this.Obj = o; }