public static MemberInfo GetMemberFromSelector <TItem, TKey>(this Expression <Func <TItem, TKey> > referencingPropertySelector)
        {
            var memberSelectorEvaluator = new MemberSelectorEvaluator <TItem, TKey>();
            var project = ICsProjectFactory.create(project_namespace.pn_project_namespace);
            var code    = referencingPropertySelector.ToString();
            var snippet = ICsSnippetFactory.create(code.ToCharArray(), null);

            MemberSelectorEvaluator <TItem, TKey> .MemberResult result;
            CsNode rootNode;

            try
            {
                project.parseSnippet(snippet, CsExpectedSnippet.cses_statement, null, true);
            }
            catch
            {
                Debugger.Break();
            }

            rootNode = snippet.getNodes()[0];

            result = memberSelectorEvaluator.ProcessRoot(rootNode);

            return(result.MemberInfo);
        }
Beispiel #2
0
        public static string GetDebuggerDisplay(this object obj)
        {
            var type = obj.GetType();

            if (type.HasCustomAttribute <DebuggerDisplayAttribute>())
            {
                var attr      = type.GetCustomAttribute <DebuggerDisplayAttribute>();
                var attrValue = attr.Value;
                var builder   = new StringBuilder();
                var regex     = new Regex("{[^}]*}");
                var project   = ICsProjectFactory.create(project_namespace.pn_project_namespace);

                if (regex.IsMatch(attrValue))
                {
                    var matches      = regex.Matches(attrValue);
                    var x            = 0;
                    var index        = 0;
                    var matchStrings = new List <string>();
                    //var evaluator = new BracedAttributeArgumentEvaluator(obj.GetType(), @"C:\Projects\RazorViewsDesigner\TestEval\DebuggerDisplayEvaluator.dll");
                    var evaluator = new BracedAttributeArgumentEvaluator(obj.GetType());

                    foreach (Match match in matches)
                    {
                        var leftString  = attrValue.Substring(index, match.Index - index);
                        var matchString = match.Value;

                        builder.Append(leftString);
                        builder.AppendFormat("{{{0}}}", x);

                        matchStrings.Add(matchString);

                        index = match.Index + match.Length;
                        x++;
                    }

                    evaluator.ProcessFormat(builder.ToString());

                    for (var y = 0; y < matchStrings.Count; y++)
                    {
                        var    matchString = matchStrings[y];
                        var    snippet     = ICsSnippetFactory.create(matchString.ToCharArray(), null);
                        CsNode rootNode;

                        try
                        {
                            project.parseSnippet(snippet, CsExpectedSnippet.cses_statement, null, true);
                        }
                        catch
                        {
                            Debugger.Break();
                        }

                        rootNode = snippet.getNodes()[0];

                        evaluator.ProcessArg(rootNode, matchString);
                    }

                    evaluator.PostProcess(x);

                    try
                    {
                        return(evaluator.Evaluate(obj));
                    }
                    catch (Exception ex)
                    {
                        Debugger.Break();
                    }
                }
            }

            return(obj.ToString());
        }