Exemple #1
0
        public static TResult GetProperty <T, TResult>(this CodeAttribute2 attr, Expression <Func <T, TResult> > propExpr)
        {
            var    propName = ExprToString(propExpr);
            var    codeAttributeArgument = attr.GetArguments().SingleOrDefault(a => a.Name == propName);
            string propValue             = null;

            if (codeAttributeArgument != null)
            {
                propValue = codeAttributeArgument.Value;
            }
            return(ParseAttributeProperty <TResult>(propValue));
        }
Exemple #2
0
        /// <summary>
        /// Convert CodeAttribute into an actual Attribute instance
        /// </summary>
        /// <typeparam name="TAttr"></typeparam>
        /// <param name="codeAttr"></param>
        /// <returns></returns>
        public static TAttr ToAttribute <TAttr>(this CodeAttribute2 codeAttr) where TAttr : Attribute, new()
        {
            var typeCache = TypeResolver.ByType <TAttr>();
            var attr      = new TAttr();

            foreach (var arg in codeAttr.GetArguments())
            {
                var propInfo = (PropertyInfo)typeCache[arg.Name];
                propInfo.SetValue(attr, ParseAttributeProperty(propInfo.PropertyType, arg.Value));
            }
            return(attr);
        }