static void GenerateScript(StringBuilder proxy, GenerateScriptTypeAttribute gsta, List <string> registeredNamespaces) { string className = gsta.Type.FullName.Replace('+', '_'); string ns = gsta.Type.Namespace; string scriptTypeDeclaration = EnsureNamespaceRegistered(ns, className, proxy, registeredNamespaces); proxy.AppendFormat( @" if (typeof({0}) === 'undefined') {{", className); if (gsta.Type.IsEnum) { proxy.AppendFormat( @" {0} = function() {{ throw Error.invalidOperation(); }} {0}.prototype = {1} {0}.registerEnum('{0}', {2});", className, JSSerializer.Serialize(GetEnumPrototypeDictionary(gsta.Type)), Attribute.GetCustomAttribute(gsta.Type, typeof(FlagsAttribute)) != null ? "true" : "false"); } else { string typeId = String.IsNullOrEmpty(gsta.ScriptTypeId) ? gsta.Type.FullName : gsta.ScriptTypeId; proxy.AppendFormat( @" " + scriptTypeDeclaration + @"=gtc(""{1}""); {0}.registerClass('{0}');", className, typeId); } proxy.Append('}'); }
private void ProcessIncludeAttributes(GenerateScriptTypeAttribute[] attributes) { foreach (GenerateScriptTypeAttribute attribute in attributes) { if (!String.IsNullOrEmpty(attribute.ScriptTypeId)) _typeResolverSpecials[attribute.Type.FullName] = attribute.ScriptTypeId; Type t = attribute.Type; if (t.IsPrimitive || t == typeof(object) || t == typeof(string) || t == typeof(DateTime) || t == typeof(Guid) || typeof(IEnumerable).IsAssignableFrom(t) || typeof(IDictionary).IsAssignableFrom(t) || (t.IsGenericType && t.GetGenericArguments().Length > 1) || !ObjectConverter.IsClientInstantiatableType(t, _serializer)) throw new InvalidOperationException(String.Format(CultureInfo.InvariantCulture, AtlasWeb.WebService_InvalidGenerateScriptType, t.FullName)); ProcessClientType(t, true); } }
static void GenerateScript (StringBuilder proxy, GenerateScriptTypeAttribute gsta, List<string> registeredNamespaces) { string className = gsta.Type.FullName.Replace ('+', '_'); string ns = gsta.Type.Namespace; string scriptTypeDeclaration = EnsureNamespaceRegistered (ns, className, proxy, registeredNamespaces); proxy.AppendFormat ( @" if (typeof({0}) === 'undefined') {{", className); if (gsta.Type.IsEnum) { proxy.AppendFormat ( @" {0} = function() {{ throw Error.invalidOperation(); }} {0}.prototype = {1} {0}.registerEnum('{0}', {2});", className, JSSerializer.Serialize(GetEnumPrototypeDictionary (gsta.Type)), Attribute.GetCustomAttribute (gsta.Type, typeof (FlagsAttribute)) != null ? "true" : "false"); } else { string typeId = String.IsNullOrEmpty (gsta.ScriptTypeId) ? gsta.Type.FullName : gsta.ScriptTypeId; proxy.AppendFormat ( @" " + scriptTypeDeclaration + @"=gtc(""{1}""); {0}.registerClass('{0}');", className, typeId); } proxy.Append ('}'); }
private void ProcessIncludeAttributes(GenerateScriptTypeAttribute[] attributes) { foreach (GenerateScriptTypeAttribute attribute in attributes) { if (!string.IsNullOrEmpty(attribute.ScriptTypeId)) _typeResolverSpecials[attribute.Type.FullName] = attribute.ScriptTypeId; Type t = attribute.Type; if (t.IsPrimitive || t == typeof(object) || t == typeof(string) || t == typeof(DateTime) || t == typeof(Guid) || typeof(IEnumerable).IsAssignableFrom(t) || typeof(IDictionary).IsAssignableFrom(t) || (t.IsGenericType && t.GetGenericArguments().Length > 1) || !IsClientInstantiatableType(t, _serializer)) throw new InvalidOperationException("Invalid type: " + t.Name); ProcessClientType(t, true); } }