Exemple #1
0
        private void GetFieldsAndMethods(Type type, out frField[] fields, out frMethod[] methods)
        {
            var fields0  = new List <frField>();
            var methods0 = new List <frMethod>();

            foreach (MemberInfo member in type.GetDeclaredMembers())
            {
                PropertyInfo property = member as PropertyInfo;
                FieldInfo    field    = member as FieldInfo;

                // Properties
                if (property != null)
                {
                    // If either the get or set methods are overridden, then the
                    // property is not considered local and will appear on a
                    // parent type.
                    var getMethod = property.GetGetMethod(/*nonPublic:*/ true);
                    var setMethod = property.GetSetMethod(/*nonPublic:*/ true);
                    if ((getMethod != null && getMethod != getMethod.GetBaseDefinition()) ||
                        (setMethod != null && setMethod != setMethod.GetBaseDefinition()))
                    {
                        continue;
                    }

                    fields0.Add(new frField(property, GetFieldAotDataFor(type, property.Name)));
                }

                // Fields
                else if (field != null)
                {
                    fields0.Add(new frField(field, GetFieldAotDataFor(type, field.Name)));
                }
            }

            foreach (MethodInfo method in type.GetDeclaredMethods())
            {
                // This is a method override. Skip it as it is not a "local"
                // property -- it will appear in a parent type.
                if (method != method.GetBaseDefinition())
                {
                    continue;
                }
                // Skip any compiler-generated methods, ie, auto-properties.
                if (method.GetCustomAttributes(typeof(CompilerGeneratedAttribute), /*inherit:*/ false).IsNullOrEmpty() == false)
                {
                    continue;
                }

                // Find correct method aot data to use. Types can define
                // multiple methods with the same name if they have different
                // parameters.
                frMethod.AotData   aotData           = default(frMethod.AotData);
                frMethod.AotData[] aotDataCandidates = GetMethodAotDataFor(type, method.Name);
                if (aotDataCandidates.Length == 1)
                {
                    aotData = aotDataCandidates[0];
                }
                else
                {
                    foreach (frMethod.AotData candidate in aotDataCandidates)
                    {
                        if (DoParamsMatch(candidate, method))
                        {
                            aotData = candidate;
                            break;
                        }
                    }
                }
                methods0.Add(new frMethod(method, aotData));
            }

            fields  = fields0.ToArray();
            methods = methods0.ToArray();
        }
Exemple #2
0
 private bool DoParamsMatch(frMethod.AotData aotData, MethodInfo method)
 {
     return(Enumerable.SequenceEqual(
                aotData.Parameters,
                method.GetParameters().Select(p => p.ParameterType)));
 }