Exemplo n.º 1
0
 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());
 }
Exemplo n.º 2
0
        /// <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>
        ///     //&quot;blt5d4sample2633b&quot; is a dummy Stack API key
        ///     //&quot;blt6d0240b5sample254090d&quot; is dummy access token.
        ///     var options = new ContentstackOptions()
        ///     {
        ///        ApiKey = &quot;api_key&quot;,
        ///        DeliveryToken = &quot;delivery_token&quot;
        ///        Environment = &quot;environment&quot;
        ///      }
        ///     ContentstackClient stack = new ContentstackClient(options);
        ///     ContentType contentType = stack.ContentType(&quot;contentType_name&quot;);
        /// </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));
            }
        }