Example #1
0
        IEnumerable <XamlMember> DoLookupAllAttachableMembers()
        {
            // based on http://msdn.microsoft.com/en-us/library/ff184560.aspx

            var gl = new Dictionary <string, MethodInfo>();
            var sl = new Dictionary <string, MethodInfo>();
            var al = new Dictionary <string, MethodInfo>();
            //var rl = new Dictionary<string,MethodInfo> ();
            var nl = new List <string>();

            foreach (var mi in UnderlyingType.GetRuntimeMethods())
            {
                if (!mi.IsStatic)
                {
                    continue;
                }
                string name = null;
                if (mi.Name.StartsWith("Get", StringComparison.Ordinal))
                {
                    if (mi.ReturnType == typeof(void))
                    {
                        continue;
                    }
                    var args = mi.GetParameters();
                    if (args.Length != 1)
                    {
                        continue;
                    }
                    name = mi.Name.Substring(3);
                    gl.Add(name, mi);
                }
                else if (mi.Name.StartsWith("Set", StringComparison.Ordinal))
                {
                    // looks like the return type is *ignored*
                    //if (mi.ReturnType != typeof (void))
                    //	continue;
                    var args = mi.GetParameters();
                    if (args.Length != 2)
                    {
                        continue;
                    }
                    name = mi.Name.Substring(3);
                    sl.Add(name, mi);
                }
                else if (mi.Name.EndsWith("Handler", StringComparison.Ordinal))
                {
                    var args = mi.GetParameters();
                    if (args.Length != 2)
                    {
                        continue;
                    }
                    if (mi.Name.StartsWith("Add", StringComparison.Ordinal))
                    {
                        name = mi.Name.Substring(3, mi.Name.Length - 3 - 7);
                        al.Add(name, mi);
                    }                    /* else if (mi.Name.StartsWith ("Remove", StringComparison.Ordinal)) {
                                          *     name = mi.Name.Substring (6, mi.Name.Length - 6 - 7);
                                          *     rl.Add (name, mi);
                                          * }*/
                }
                if (name != null && !nl.Contains(name))
                {
                    nl.Add(name);
                }
            }

            foreach (var name in nl)
            {
                MethodInfo m;
                var        g = gl.TryGetValue(name, out m) ? m : null;
                var        s = sl.TryGetValue(name, out m) ? m : null;
                if (g != null || s != null)
                {
                    yield return(SchemaContext.GetAttachableProperty(name, g, s));
                }
                var a = al.TryGetValue(name, out m) ? m : null;
                //var r = rl.TryGetValue (name, out m) ? m : null;
                if (a != null)
                {
                    yield return(SchemaContext.GetAttachableEvent(name, a));
                }
            }
        }