Ejemplo n.º 1
0
        public bool TryGetMethod(string name, TypeData[] parameters, out MethodBaseData method)
        {
            const string constructor = ".ctor";

            if (name == null)
            {
                method = null;
                return(false);
            }

            if (parameters == null)
            {
                parameters = new TypeData[0];
            }

            method = name == constructor?SelectMethod(Constructors) : SelectMethod(Methods);

            return(method != null);

            MethodBaseData SelectMethod <TMethodBaseData>(IEnumerable <TMethodBaseData> methods) where TMethodBaseData : MethodBaseData
            {
                return(methods.Where(methodBaseData => name == methodBaseData.Name).Where(methodBaseData => parameters.Length == methodBaseData.Parameters.Count)
                       .FirstOrDefault(methodBaseData => !methodBaseData.Parameters.Where((parameter, index) => parameter.ParameterType != parameters[index]).Any()));
            }
        }
Ejemplo n.º 2
0
        internal ParameterData(ParameterInfo parameterInfo, MethodBaseData declaringMethod) : base(parameterInfo)
        {
            _parameterInfo = parameterInfo;
            _parameterType = new Lazy <TypeData>(() => _parameterInfo.ParameterType.GetTypeData());

            DeclaringMethod = declaringMethod;
            IsOut           = parameterInfo.IsOut;
            IsOptional      = parameterInfo.IsOptional;
            DefaultValue    = parameterInfo.HasDefaultValue ? parameterInfo.DefaultValue : null;
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Creates a new instance of <see cref="ParameterData"/>.
        /// </summary>
        /// <param name="parameterInfo">Parameter info.</param>
        /// <param name="declaringMethod">Declaring method.</param>
        internal ParameterData(ParameterInfo parameterInfo, MethodBaseData declaringMethod) : base(parameterInfo.Name, declaringMethod)
        {
            _parameterInfo = parameterInfo;
            _attributes    = new Lazy <IReadOnlyList <AttributeData> >(() => _parameterInfo.GetCustomAttributes(true).Select(value => new AttributeData(value, value.GetType(), this)).ToArray());
            _defaultValue  = new Lazy <object>(() => _parameterInfo.DefaultValue);
            _description   = new Lazy <string>(() => DeclaringMethod.DeclaringType.Assembly.XmlDocumentation.GetSummary(this));

            DeclaringMethod = declaringMethod;
            ParameterType   = parameterInfo.ParameterType.GetTypeData();
            IsOut           = parameterInfo.IsOut;
            IsOptional      = parameterInfo.IsOptional;
        }
Ejemplo n.º 4
0
 /// <summary>
 /// Does the specified left hand side <see cref="MethodBaseData"/> equal the specified right hand side <see cref="MethodBaseData"/>?
 /// </summary>
 /// <param name="lhs">Left hand side <see cref="MethodBaseData"/>.</param>
 /// <param name="rhs">Right hand side <see cref="MethodBaseData"/>.</param>
 /// <returns>True if the specified left hand side <see cref="MethodBaseData"/> equals the specified right hand side <see cref="MethodBaseData"/>; otherwise, false.</returns>
 protected static bool Equals(MethodBaseData lhs, MethodBaseData rhs)
 {
     return(lhs.Path == rhs.Path &&
            lhs.Parameters.Count == rhs.Parameters.Count &&
            !lhs.Parameters.Where((parameter, index) => parameter.ParameterType != rhs.Parameters[index].ParameterType).Any());
 }