Example #1
0
        public TemplateAsset TryGetTemplateAsset(object data, DrawAttribute drawAttribute = null, ControlType?overrideControlType = null)
        {
            ControlType controlType = ControlType.None;

            // Try get control type from method param
            if (overrideControlType.HasValue && overrideControlType != ControlType.None)
            {
                controlType = overrideControlType.Value;
            }

            // Try get from attributes
            else
            {
                // No member draw attribute -> try get ControlType from class attribute
                if ((drawAttribute == null || drawAttribute.controlType == ControlType.None) && !data.GetType().IsPrimitive&& !(data is string))
                {
                    var info = TypeInfoCache.GetExtendedTypeInfo(data.GetType());
                    info.HasTypeAttribute <DrawAttribute>();
                    drawAttribute = info.GetTypeAttribute <DrawAttribute>();
                }
                // Set ControlType from attribute (if present)
                if (drawAttribute != null)
                {
                    controlType = drawAttribute.controlType;
                }
            }
            // Didn't find in attribute
            if (controlType == ControlType.None)
            {
                controlType = GetControlTypeFromData(data);
            }

            return(TryGetTemplateAsset(controlType));
        }
Example #2
0
        public static object Build(Type interfaceWebao, IRequest req)
        {
            var typeInformation  = TypeInfoCache.Get(interfaceWebao);
            var baseUrl          = typeInformation.GetClassAttributesByName("BaseUrl");
            var parametersByName = typeInformation.GetClassAttributesByName("AddParameter");

            if (baseUrl[0] is BaseUrlAttribute baseUrlAttribute)
            {
                req.BaseUrl(baseUrlAttribute.host);
            }

            foreach (var param in parametersByName)
            {
                if (param is AddParameterAttribute parameterAttribute)
                {
                    req.AddParameter(parameterAttribute.name, parameterAttribute.val);
                }
            }


            var typeMethods       = interfaceWebao.GetMethods();
            var methodInformation = typeMethods.Select(BuilderHelper.ProcessMethod).ToList();

            return(BuildTask(interfaceWebao, req, methodInformation));
        }
Example #3
0
        private void registerType(Type type)
        {
            if (TypeInfoCache.ContainsKey(type))
            {
                return;
            }

            TypeInfoCache[type] = TypeInfoFactory.Create(type, this);
        }
        private static TypeInfoCache GetTypeInfoCache(Type type)
        {
            // null check
            if (type == null)
            {
                throw new ArgumentNullException("type");
            }
            // for thread safe
            var cacheArray = _typeInfoCacheArray;
            // get cache by index
            var cacheIndex = ObjectHeaderAccessor.GetIndex(type);

            if (cacheIndex > 0 && cacheIndex < cacheArray.Length)
            {
                var cached = cacheArray[cacheIndex];
                if (cached != null)
                {
                    // cache array may replaced by other thread,
                    // it so we need create the cache entry again
                    return(cached);
                }
            }
            // get a new cache index
            if (cacheIndex == 0)
            {
                if (_typeInfoCacheIndex > ObjectHeaderAccessor.MaxIndex)
                {
                    return(null);
                }
                cacheIndex = Interlocked.Increment(ref _typeInfoCacheIndex);
                if (cacheIndex > ObjectHeaderAccessor.MaxIndex)
                {
                    return(null);
                }
            }
            // create new cache array if size not enough
            if (cacheIndex >= cacheArray.Length)
            {
                var newCacheArray = new TypeInfoCache[
                    Math.Min(
                        Math.Max(cacheArray.Length * 2, cacheIndex + 1),
                        ObjectHeaderAccessor.MaxIndex + 1)];
                Array.Copy(cacheArray, newCacheArray, cacheArray.Length);
                cacheArray          = newCacheArray;
                _typeInfoCacheArray = newCacheArray;
            }
            // create cache entry
            var cache = new TypeInfoCache(type);

            cacheArray[cacheIndex] = cache;
            ObjectHeaderAccessor.SetIndex(type, cacheIndex);
            return(cache);
        }
        protected void MapFilterToViewData(TGetEntitiesQuery filter)
        {
            var properties = TypeInfoCache
                             .GetPublicProperties(filter.GetType())
                             .Select(x => new
            {
                x.Name,
                Value = x.GetValue(filter)
            })
                             .Where(x => x.Value != null);

            foreach (var property in properties)
            {
                ViewData[property.Name] = property.Value;
            }
        }
Example #6
0
 public CsvReader(CsvColumn[] columns) : base()
 {
     _columns = columns ?? throw new ArgumentNullException("columns");
     _columns = _columns.OrderBy(c => c.OrdinalPosition).ToArray();
     for (var i = 0; i < _columns.Length; ++i)
     {
         var column = _columns[i];
         if (column.PropertyInfo == null)
         {
             if (string.IsNullOrEmpty(column.PropertyName))
             {
                 throw new InvalidOperationException($"PropertyInfo or PropertyName must be set on column index {i}.");
             }
             column.PropertyInfo = TypeInfoCache <T> .GetReadWriteProperty(column.PropertyName);
         }
     }
 }
Example #7
0
        public static AbstractAccessObject Build(Type webao, IRequest req)
        {
            var typeInformation  = TypeInfoCache.Get(webao);
            var baseUrl          = typeInformation.GetClassAttributesByName("BaseUrl");
            var parametersByName = typeInformation.GetClassAttributesByName("AddParameter");

            if (baseUrl[0] is BaseUrlAttribute baseUrlAttribute)
            {
                req.BaseUrl(baseUrlAttribute.host);
            }

            foreach (var param in parametersByName)
            {
                if (param is AddParameterAttribute parameterAttribute)
                {
                    req.AddParameter(parameterAttribute.name, parameterAttribute.val);
                }
            }
            return((AbstractAccessObject)Activator.CreateInstance(webao, req));
        }
Example #8
0
        private static string CalcOrderBy(Type type)
        {
            var orderByProps = TypeInfoCache.GetPublicProperties(type)
                               .Select(x => new
            {
                Property         = x,
                OrderByAttribute = x.GetCustomAttribute(typeof(OrderByAttribute)) as OrderByAttribute
            })
                               .Where(x => x.OrderByAttribute != null)
                               .ToArray();

            string orderBy = null;

            if (orderByProps.Length == 1)
            {
                orderBy = orderByProps[0].OrderByAttribute.IsDesc ?
                          $"{orderByProps[0].Property.Name}.DESC" :
                          orderByProps[0].Property.Name;
            }

            return(orderBy);
        }
Example #9
0
        public static object Build(Type interfaceWebao, IRequest req)
        {
            var typeInformation  = TypeInfoCache.Get(interfaceWebao);
            var baseUrl          = typeInformation.GetClassAttributesByName("BaseUrl");
            var parametersByName = typeInformation.GetClassAttributesByName("AddParameter");

            if (baseUrl[0] is BaseUrlAttribute baseUrlAttribute)
            {
                req.BaseUrl(baseUrlAttribute.host);
            }

            foreach (var param in parametersByName)
            {
                if (param is AddParameterAttribute parameterAttribute)
                {
                    req.AddParameter(parameterAttribute.name, parameterAttribute.val);
                }
            }

            builderHelper.SetModuleBuilder(interfaceWebao.Name.Remove(0, 1));
            builderHelper.SetTypeBuilder(interfaceWebao);
            emitter.EmitConstructor(builderHelper.TypeBuilder, builderHelper.GetBaseCtor());

            var methods = interfaceWebao.GetMethods();

            foreach (var method in methods)
            {
                var info = builderHelper.ProcessMethod(method);
                emitter.EmitMethod(builderHelper.TypeBuilder, info);
            }

            var type = builderHelper.TypeBuilder.CreateType();

            builderHelper.Save();
            return(Activator.CreateInstance(type, req));
        }
 public ObjectNavigationContext()
 {
     NameTable     = new NameTable();
     TypeInfoCache = new TypeInfoCache();
 }
		public ObjectNavigationContext()
		{
			NameTable = new NameTable();
			TypeInfoCache = new TypeInfoCache();
		}