internal static IEnumerable <Type> GetCustomAttribute(Type attribute) { if (!_types.ContainsKey(attribute)) { List <Type> result = new List <Type>(); foreach (Assembly assembly in AppDomain.CurrentDomain.GetAssemblies()) { try { foreach (Type type in assembly.GetTypes()) { var objectType = type.GetCustomAttributes(attribute, true); foreach (var attr in type.GetCustomAttributes(typeof(CSJsonConverterAttribute))) { CSJsonConverterAttribute ctdAttr = attr as CSJsonConverterAttribute; Trace.Assert(ctdAttr != null, "cast is null"); if (ctdAttr.isAutoloadEnable) { result.Add(type); } } } } catch (Exception ex) { } } _types[attribute] = result; } return(_types[attribute].ToArray()); }
/// <summary> /// Initializes a instance of the <see cref="ContentstackClient"/> class. /// </summary> /// <param name="options"> used to get stack details via class <see cref="ContentstackOptions"/> to create client.</param> /// <example> /// <code> /// //"blt5d4sample2633b" is a dummy Stack API key /// //"blt6d0240b5sample254090d" is dummy access token. /// var options = new ContentstackOptions() /// { /// ApiKey = "api_key", /// DeliveryToken = "delivery_token" /// Environment = "environment" /// } /// ContentstackClient stack = new ContentstackClient(options); /// ContentType contentType = stack.ContentType("contentType_name"); /// </code> /// </example> public ContentstackClient(IOptions <ContentstackOptions> options) { _options = options.Value; this.StackApiKey = _options.ApiKey; this._LocalHeaders = new Dictionary <string, object>(); this.SetHeader("api_key", _options.ApiKey); if (_options.AccessToken != null) { this.SetHeader("access_token", _options.AccessToken); } else if (_options.DeliveryToken != null) { this.SetHeader("access_token", _options.DeliveryToken); } Config cnfig = new Config(); cnfig.Environment = _options.Environment; if (_options.Host != null) { cnfig.Host = _options.Host; } if (_options.Version != null) { cnfig.Version = _options.Version; } cnfig.Region = _options.Region; this.SetConfig(cnfig); this.SerializerSettings.DateParseHandling = DateParseHandling.None; this.SerializerSettings.DateFormatHandling = DateFormatHandling.IsoDateFormat; this.SerializerSettings.DateTimeZoneHandling = DateTimeZoneHandling.Utc; this.SerializerSettings.NullValueHandling = NullValueHandling.Ignore; foreach (Type t in CSJsonConverterAttribute.GetCustomAttribute(typeof(CSJsonConverterAttribute))) { SerializerSettings.Converters.Add((JsonConverter)Activator.CreateInstance(t)); } }