Пример #1
0
        IEnumerable <IMethod> GetConstructorsImpl(Predicate <IMethod> filter)
        {
            bool foundCtor = false;

            foreach (IMethod m in this.Methods)
            {
                if (m.IsConstructor && !m.IsStatic)
                {
                    foundCtor = true;
                    if (filter == null || filter(m))
                    {
                        yield return(m);
                    }
                }
            }

            if (this.AddDefaultConstructorIfRequired)
            {
                if (kind == TypeKind.Class && !foundCtor && !this.IsStatic ||
                    kind == TypeKind.Enum || kind == TypeKind.Struct)
                {
                    var m = DefaultMethod.CreateDefaultConstructor(this);
                    if (filter == null || filter(m))
                    {
                        yield return(m);
                    }
                }
            }
        }
Пример #2
0
        public virtual IEnumerable <IMethod> GetConstructors(ITypeResolveContext context, Predicate <IMethod> filter = null)
        {
            ITypeDefinition compound = GetCompoundClass();

            if (compound != this)
            {
                return(compound.GetConstructors(context, filter));
            }

            List <IMethod> methods = new List <IMethod>();

            AddFilteredRange(methods, this.Methods.Where(m => m.IsConstructor && !m.IsStatic), filter);

            if (this.AddDefaultConstructorIfRequired)
            {
                if (this.ClassType == ClassType.Class && methods.Count == 0 ||
                    this.ClassType == ClassType.Enum || this.ClassType == ClassType.Struct)
                {
                    var m = DefaultMethod.CreateDefaultConstructor(this);
                    if (filter == null || filter(m))
                    {
                        methods.Add(m);
                    }
                }
            }
            return(methods);
        }
Пример #3
0
 public IEnumerable <IMethod> GetConstructors(ITypeResolveContext context, Predicate <IMethod> filter = null)
 {
     if (HasDefaultConstructorConstraint || HasValueTypeConstraint)
     {
         DefaultMethod m = DefaultMethod.CreateDefaultConstructor(GetDummyClassForTypeParameter());
         if (filter(m))
         {
             return new [] { m }
         }
         ;
     }
     return(EmptyList <IMethod> .Instance);
 }
Пример #4
0
		DefaultMethod MakeMethod(params object[] parameterTypesOrDefaultValues)
		{
			DefaultMethod m = new DefaultMethod(dummyClass, "Method");
			foreach (var typeOrDefaultValue in parameterTypesOrDefaultValues) {
				Type type = typeOrDefaultValue as Type;
				if (type != null)
					m.Parameters.Add(new DefaultParameter(type.ToTypeReference(), string.Empty));
				else if (Type.GetTypeCode(typeOrDefaultValue.GetType()) > TypeCode.Object)
					m.Parameters.Add(new DefaultParameter(typeOrDefaultValue.GetType().ToTypeReference(), string.Empty) {
					                 	DefaultValue = new SimpleConstantValue(typeOrDefaultValue.GetType().ToTypeReference(), typeOrDefaultValue)
					                 });
				else
					throw new ArgumentException(typeOrDefaultValue.ToString());
			}
			return m;
		}
Пример #5
0
 public IEnumerable <IMethod> GetConstructors(ITypeResolveContext context, Predicate <IMethod> filter = null, GetMemberOptions options = GetMemberOptions.IgnoreInheritedMembers)
 {
     if ((options & GetMemberOptions.IgnoreInheritedMembers) == GetMemberOptions.IgnoreInheritedMembers)
     {
         if (HasDefaultConstructorConstraint || HasValueTypeConstraint)
         {
             DefaultMethod m = DefaultMethod.CreateDefaultConstructor(GetDummyClassForTypeParameter());
             if (filter(m))
             {
                 return new [] { m }
             }
             ;
         }
         return(EmptyList <IMethod> .Instance);
     }
     else
     {
         return(GetMembersHelper.GetConstructors(this, context, filter, options));
     }
 }
Пример #6
0
		public IMethod ReadMethod(MethodDefinition method, ITypeDefinition parentType, EntityType methodType = EntityType.Method)
		{
			DefaultMethod m = new DefaultMethod(parentType, method.Name);
			m.EntityType = methodType;
			if (method.HasGenericParameters) {
				for (int i = 0; i < method.GenericParameters.Count; i++) {
					if (method.GenericParameters[i].Position != i)
						throw new InvalidOperationException("g.Position != i");
					m.TypeParameters.Add(new DefaultTypeParameter(
						EntityType.Method, i, method.GenericParameters[i].Name));
				}
				for (int i = 0; i < method.GenericParameters.Count; i++) {
					AddConstraints(m, (DefaultTypeParameter)m.TypeParameters[i], method.GenericParameters[i]);
				}
			}
			
			if (method.IsConstructor)
				m.ReturnType = parentType;
			else
				m.ReturnType = ReadTypeReference(method.ReturnType, typeAttributes: method.MethodReturnType, entity: m);
			
			if (HasAnyAttributes(method))
				AddAttributes(method, m.Attributes, m.ReturnTypeAttributes);
			TranslateModifiers(method, m);
			
			if (method.HasParameters) {
				foreach (ParameterDefinition p in method.Parameters) {
					m.Parameters.Add(ReadParameter(p, parentMember: m));
				}
			}
			
			// mark as extension method if the attribute is set
			if (method.IsStatic && HasExtensionAttribute(method)) {
				m.IsExtensionMethod = true;
			}
			
			FinishReadMember(m);
			return m;
		}