public virtual string GetCustomTypeName(TypeDefinition type, IEmitter emitter) { var name = this.GetAttributeValue(type.CustomAttributes, Translator.Bridge_ASSEMBLY + ".NameAttribute"); if (!string.IsNullOrEmpty(name)) { FixBridgePrefix(ref name); return(name); } var nsAtrr = this.GetAttribute(type.CustomAttributes, Translator.Bridge_ASSEMBLY + ".NamespaceAttribute"); if (nsAtrr != null && nsAtrr.ConstructorArguments.Count > 0) { var arg = nsAtrr.ConstructorArguments[0]; name = ""; if (arg.Value is string) { name = arg.Value.ToString(); } if (arg.Value is bool && ((bool)arg.Value)) { return(null); } if (type.IsNested) { name = (string.IsNullOrEmpty(name) ? "" : (name + ".")) + BridgeTypes.GetParentNames(type); } name = (string.IsNullOrEmpty(name) ? "" : (name + ".")) + BridgeTypes.ConvertName(type.Name); FixBridgePrefix(ref name); return(name); } if (this.HasAttribute(type.CustomAttributes, Translator.Bridge_ASSEMBLY + ".ObjectLiteralAttribute")) { return("Object"); } return(null); }
public static string ToCorrectTypeName(string keyName) { return(BridgeTypes.ConvertName(keyName)); }
public virtual string GetCustomTypeName(TypeDefinition type, IEmitter emitter, bool excludeNs) { if (this._stack.Contains(type)) { return(null); } var nsAtrr = excludeNs ? null : this.GetAttribute(type.CustomAttributes, Translator.Bridge_ASSEMBLY + ".NamespaceAttribute"); bool hasNs = nsAtrr != null && nsAtrr.ConstructorArguments.Count > 0; var nameAttr = this.GetAttribute(type.CustomAttributes, Translator.Bridge_ASSEMBLY + ".NameAttribute"); string name = null; bool changeCase = false; if (nameAttr != null && nameAttr.ConstructorArguments.Count > 0) { if (nameAttr.ConstructorArguments[0].Value is string) { name = Helpers.ConvertNameTokens((string)nameAttr.ConstructorArguments[0].Value, type.Name); } else if (nameAttr.ConstructorArguments[0].Value is bool) { var boolValue = (bool)nameAttr.ConstructorArguments[0].Value; if (boolValue) { if (hasNs) { changeCase = true; } else { this._stack.Push(type); name = BridgeTypes.ToJsName(type, emitter); var i = name.LastIndexOf("."); if (i > -1) { char[] chars = name.ToCharArray(); chars[i + 1] = Char.ToLowerInvariant(chars[i + 1]); name = new string(chars); } else { name = name.ToLowerCamelCase(); } this._stack.Pop(); return(name); } } } } if (!string.IsNullOrEmpty(name)) { return(name); } if (hasNs) { var arg = nsAtrr.ConstructorArguments[0]; name = ""; if (arg.Value is string) { name = arg.Value.ToString(); } if (arg.Value is bool && ((bool)arg.Value)) { return(null); } if (type.IsNested) { name = (string.IsNullOrEmpty(name) ? "" : (name + ".")) + BridgeTypes.GetParentNames(emitter, type); } var typeName = emitter.GetTypeName(emitter.BridgeTypes.Get(type).Type.GetDefinition(), type); name = (string.IsNullOrEmpty(name) ? "" : (name + ".")) + BridgeTypes.ConvertName(changeCase ? typeName.ToLowerCamelCase() : typeName); return(name); } if (this.HasAttribute(type.CustomAttributes, Translator.Bridge_ASSEMBLY + ".ObjectLiteralAttribute")) { var mode = this.GetObjectCreateMode(type); if (emitter.Validator.IsExternalType(type) && mode == 0) { return(JS.Types.System.Object.NAME); } } return(null); }
public virtual string GetCustomTypeName(TypeDefinition type, IEmitter emitter) { if (this._stack.Contains(type)) { return(null); } var nsAtrr = this.GetAttribute(type.CustomAttributes, Translator.Bridge_ASSEMBLY + ".NamespaceAttribute"); bool hasNs = nsAtrr != null && nsAtrr.ConstructorArguments.Count > 0; var nameAttr = this.GetAttribute(type.CustomAttributes, Translator.Bridge_ASSEMBLY + ".NameAttribute"); string name = null; bool changeCase = false; if (nameAttr != null && nameAttr.ConstructorArguments.Count > 0) { if (nameAttr.ConstructorArguments[0].Value is string) { name = (string)nameAttr.ConstructorArguments[0].Value; } else if (nameAttr.ConstructorArguments[0].Value is bool) { var boolValue = (bool)nameAttr.ConstructorArguments[0].Value; if (boolValue) { if (hasNs) { changeCase = true; } else { this._stack.Push(type); name = BridgeTypes.ToJsName(type, emitter); var i = name.LastIndexOf("."); if (i > -1) { char[] chars = name.ToCharArray(); chars[i + 1] = Char.ToLowerInvariant(chars[i + 1]); name = new string(chars); } else { name = name.ToLowerCamelCase(); } this._stack.Pop(); return(name); } } } } if (!string.IsNullOrEmpty(name)) { return(name); } if (hasNs) { var arg = nsAtrr.ConstructorArguments[0]; name = ""; if (arg.Value is string) { name = arg.Value.ToString(); } if (arg.Value is bool && ((bool)arg.Value)) { return(null); } if (type.IsNested) { name = (string.IsNullOrEmpty(name) ? "" : (name + ".")) + BridgeTypes.GetParentNames(type); } name = (string.IsNullOrEmpty(name) ? "" : (name + ".")) + BridgeTypes.ConvertName(changeCase ? type.Name.ToLowerCamelCase() : type.Name); return(name); } if (this.HasAttribute(type.CustomAttributes, Translator.Bridge_ASSEMBLY + ".ObjectLiteralAttribute")) { var mode = this.GetObjectCreateMode(type); var ignore = mode == 0 && !type.Methods.Any(m => !m.IsConstructor && !m.IsGetter && !m.IsSetter && !m.IsRemoveOn && !m.IsAddOn); if (emitter.Validator.IsIgnoreType(type) || ignore) { return("Object"); } } return(null); }