Пример #1
0
        /// <summary>
        /// For an indexed property, the type of the property. Null if not indexed.
        /// </summary>
        /// <returns></returns>
        public MrType GetItemType(bool publicishOnly)
        {
            // This could be a getter or a setter method
            MrMethod etterMethod;

            var getterHandle = Definition.GetAccessors().Getter;

            etterMethod = MrMethod.TryGetMethod(getterHandle, this.DeclaringType, publicishOnly);
            if (etterMethod == null)
            {
                var setterHandle = Definition.GetAccessors().Getter;
                etterMethod = MrMethod.TryGetMethod(setterHandle, this.DeclaringType, publicishOnly);
                if (etterMethod == null)
                {
                    // Not an indexed property
                    return(null);
                }
            }

            var parameters = etterMethod.GetParameters();

            if (parameters.Length == 0)
            {
                // Not an indexed property
                return(null);
            }

            return(parameters[0].GetParameterType());
        }
Пример #2
0
        public void GetAccessors(out MrMethod adder, out MrMethod remover, bool publicishOnly = true)
        {
            var eventAccessors = Definition.GetAccessors();

            adder   = MrMethod.TryGetMethod(eventAccessors.Adder, DeclaringType, publicishOnly);
            remover = MrMethod.TryGetMethod(eventAccessors.Remover, DeclaringType, publicishOnly);
        }
        /// <summary>
        /// The methods and constructors for this type. This is one method rather than two to be more efficient
        /// (fewer allocations).
        /// </summary>
        /// <param name="publicishOnly">If true, only return public or protected methods (for an unsealed type)</param>
        public void GetMethodsAndConstructors(
            out ImmutableArray <MrMethod> methods,
            out ImmutableArray <MrMethod> constructors,
            bool publicishOnly = true)
        {
            if (IsFakeType || IsTypeCode)
            {
                methods = constructors = ImmutableArray <MrMethod> .Empty;
                return;
            }

            var             methodDefinitionHandles = TypeDefinition.GetMethods();
            List <MrMethod> mrMethods      = null;
            List <MrMethod> mrConstructors = null;

            foreach (var methodDefinitionHandle in methodDefinitionHandles)
            {
                var methodDefinition = Assembly.Reader.GetMethodDefinition(methodDefinitionHandle);

                var mrMethod = MrMethod.TryGetMethod(methodDefinitionHandle, this, publicishOnly);
                if (mrMethod == null)
                {
                    continue;
                }

                var isConstructor = mrMethod.GetIsConstructor();

                // Ignore things like the get_/set_ methods for properties.
                // Don't ignore constructors though; SpecialName is set for the static constructor
                if (mrMethod.MethodDefinition.Attributes.HasFlag(MethodAttributes.SpecialName) && !isConstructor)
                {
                    continue;
                }

                if (isConstructor)
                {
                    if (mrConstructors == null)
                    {
                        mrConstructors = new List <MrMethod>(methodDefinitionHandles.Count);
                    }
                    mrConstructors.Add(mrMethod);
                }
                else
                {
                    if (mrMethods == null)
                    {
                        mrMethods = new List <MrMethod>(methodDefinitionHandles.Count);
                    }
                    mrMethods.Add(mrMethod);
                }
            }

            methods      = mrMethods == null ? ImmutableArray <MrMethod> .Empty : mrMethods.ToImmutableArray();
            constructors = mrConstructors == null ? ImmutableArray <MrMethod> .Empty : mrConstructors.ToImmutableArray();
        }
Пример #4
0
        /// <summary>
        /// The property's getter and setter, either of which could be null
        /// </summary>
        static void GetGetterAndSetter(
            PropertyDefinition propertyDefinition,
            MrType declaringType,
            bool publicishOnly,
            out MrMethod getter, out MrMethod setter)
        {
            var propertyAccessors = propertyDefinition.GetAccessors();

            getter = MrMethod.TryGetMethod(propertyAccessors.Getter, declaringType, publicishOnly);
            setter = MrMethod.TryGetMethod(propertyAccessors.Setter, declaringType, publicishOnly);
        }
        /// <summary>
        /// Get a method named "Invoke". This is intended to be called on delegate types.
        /// </summary>
        /// <returns></returns>
        public MrMethod GetInvokeMethod()
        {
            if (IsFakeType)
            {
                return(null);
            }

            // Don't use this.GetMethods, because it filters out SpecialType methods like Delegate.Invoke
            foreach (var methodDefinitionHandle in this.TypeDefinition.GetMethods())
            {
                var methodDefinition = this.Assembly.Reader.GetMethodDefinition(methodDefinitionHandle);
                var name             = methodDefinition.Name.AsString(this.Assembly);
                if (name == "Invoke")
                {
                    return(MrMethod.TryGetMethod(methodDefinitionHandle, this, publicishOnly: false));
                }
            }

            return(null);
        }