当前位置: 首页>>代码示例>>C#>>正文


C# IType.GetConstructors方法代码示例

本文整理汇总了C#中IType.GetConstructors方法的典型用法代码示例。如果您正苦于以下问题:C# IType.GetConstructors方法的具体用法?C# IType.GetConstructors怎么用?C# IType.GetConstructors使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在IType的用法示例。


在下文中一共展示了IType.GetConstructors方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: CheckTypeParameterConstraints

		static bool CheckTypeParameterConstraints (IType type, IEnumerable<IType> baseTypes,
				ITypeParameter typeParameter)
		{
			if (!typeParameter.DirectBaseTypes.All (t => baseTypes.Any (t2 => t2.Equals (t))))
				return false;
			if (typeParameter.HasDefaultConstructorConstraint &&
				!type.GetConstructors (c => c.IsPublic && c.Parameters.Count == 0).Any ())
				return false;
			return true;
		}
开发者ID:Gobiner,项目名称:ILSpy,代码行数:10,代码来源:TypeCompatibilityHelper.cs

示例2: ConstructorParameterDataProvider

		public ConstructorParameterDataProvider (int startOffset, CSharpCompletionTextEditorExtension ext, IType type) : base (startOffset, ext)
		{
			this.type = type;
			
			var ctx = ext.CSharpParsedFile.GetTypeResolveContext (ext.Compilation, ext.Document.Editor.Caret.Location) as CSharpTypeResolveContext;

			var lookup = new MemberLookup (ctx.CurrentTypeDefinition, ext.Compilation.MainAssembly);
			bool isProtectedAllowed = ctx.CurrentTypeDefinition != null && type.GetDefinition () != null ? ctx.CurrentTypeDefinition.IsDerivedFrom (type.GetDefinition ()) : false;
						
			foreach (var method in type.GetConstructors ()) {
				Console.WriteLine ("constructor:" + method);
				if (!lookup.IsAccessible (method, isProtectedAllowed)) {
					Console.WriteLine ("skip !!!");
					continue;
				}
				methods.Add (method);
			}
		}
开发者ID:sparek,项目名称:monodevelop,代码行数:18,代码来源:ConstructorParameterDataProvider.cs

示例3: ConstructorParameterDataProvider

		public ConstructorParameterDataProvider (int startOffset, CSharpCompletionTextEditorExtension ext, IType type) : base (startOffset, ext)
		{
			this.type = type;
			
			var ctx = ext.CSharpParsedFile.GetTypeResolveContext (ext.Compilation, ext.Document.Editor.Caret.Location) as CSharpTypeResolveContext;

			var lookup = new MemberLookup (ctx.CurrentTypeDefinition, ext.Compilation.MainAssembly);
			bool isProtectedAllowed = false;
			var typeDefinition = type.GetDefinition ();
			if (ctx.CurrentTypeDefinition != null && typeDefinition != null) {
				isProtectedAllowed = ctx.CurrentTypeDefinition.IsDerivedFrom (ctx.CurrentTypeDefinition.Compilation.Import (typeDefinition));
			}
						
			foreach (var method in type.GetConstructors ()) {
				if (!lookup.IsAccessible (method, isProtectedAllowed)) {
					continue;
				}
				if (!method.IsBrowsable ())
					continue;
				methods.Add (method);
			}
			methods.Sort ((l, r) => l.GetEditorBrowsableState ().CompareTo (r.GetEditorBrowsableState ()));
		}
开发者ID:ariesguy22,项目名称:monodevelop,代码行数:23,代码来源:ConstructorParameterDataProvider.cs

示例4: ConstructorParameterDataProvider

		public ConstructorParameterDataProvider (int startOffset, CSharpCompletionTextEditorExtension ext, IType type, AstNode skipInitializer = null) : base (startOffset, ext)
		{
			this.type = type;
			
			var ctx = ext.CSharpUnresolvedFile.GetTypeResolveContext (ext.UnresolvedFileCompilation, ext.Editor.CaretLocation) as CSharpTypeResolveContext;

			var lookup = new MemberLookup (ctx.CurrentTypeDefinition, ext.Compilation.MainAssembly);
			bool isProtectedAllowed = false;
			var typeDefinition = type.GetDefinition ();
			if (ctx.CurrentTypeDefinition != null && typeDefinition != null) {
				isProtectedAllowed = ctx.CurrentTypeDefinition.IsDerivedFrom (ctx.CurrentTypeDefinition.Compilation.Import (typeDefinition));
			}
			foreach (var method in type.GetConstructors ()) {
				if (!lookup.IsAccessible (method, isProtectedAllowed)) {
					continue;
				}
				if (!method.IsBrowsable ())
					continue;
				if (skipInitializer != null && skipInitializer.Parent.StartLocation == method.Region.Begin)
					continue;
				methods.Add (method);
			}
			methods.Sort (MethodComparer);
		}
开发者ID:FreeBSD-DotNet,项目名称:monodevelop,代码行数:24,代码来源:ConstructorParameterDataProvider.cs

示例5: CreateConstructorInvocationWithReferencedEntities

 public MethodInvocationExpression CreateConstructorInvocationWithReferencedEntities(IType type)
 {
     MethodInvocationExpression mie = CodeBuilder.CreateConstructorInvocation(type.GetConstructors().First());
     foreach (ITypedEntity entity in _referencedEntities.Keys)
         mie.Arguments.Add(CreateForeignReference(entity));
     return mie;
 }
开发者ID:Bombadil77,项目名称:boo,代码行数:7,代码来源:ForeignReferenceCollector.cs

示例6: GetCorrectConstructor

        IConstructor GetCorrectConstructor(Node sourceNode, IType type, ExpressionCollection arguments)
        {
            IConstructor[] constructors = type.GetConstructors().ToArray();
            if (constructors.Length > 0)
                return (IConstructor)GetCorrectCallableReference(sourceNode, arguments, constructors);

            if (!IsError(type))
            {
                if (type is IGenericParameter)
                    Error(CompilerErrorFactory.CannotCreateAnInstanceOfGenericParameterWithoutDefaultConstructorConstraint(sourceNode, type));
                else
                    Error(CompilerErrorFactory.NoApropriateConstructorFound(sourceNode, type, GetSignature(arguments)));
            }
            return null;
        }
开发者ID:stuman08,项目名称:boo,代码行数:15,代码来源:ProcessMethodBodies.cs

示例7: ValidateConstraints

		internal static bool ValidateConstraints(ITypeParameter typeParameter, IType typeArgument, TypeVisitor substitution, Conversions conversions)
		{
			switch (typeArgument.Kind) { // void, null, and pointers cannot be used as type arguments
				case TypeKind.Void:
				case TypeKind.Null:
				case TypeKind.Pointer:
					return false;
			}
			if (typeParameter.HasReferenceTypeConstraint) {
				if (typeArgument.IsReferenceType != true)
					return false;
			}
			if (typeParameter.HasValueTypeConstraint) {
				if (!NullableType.IsNonNullableValueType(typeArgument))
					return false;
			}
			if (typeParameter.HasDefaultConstructorConstraint) {
				ITypeDefinition def = typeArgument.GetDefinition();
				if (def != null && def.IsAbstract)
					return false;
				var ctors = typeArgument.GetConstructors(
					m => m.Parameters.Count == 0 && m.Accessibility == Accessibility.Public,
					GetMemberOptions.IgnoreInheritedMembers | GetMemberOptions.ReturnMemberDefinitions
				);
				if (!ctors.Any())
					return false;
			}
			foreach (IType constraintType in typeParameter.DirectBaseTypes) {
				IType c = constraintType;
				if (substitution != null)
					c = c.AcceptVisitor(substitution);
				if (!conversions.IsConstraintConvertible(typeArgument, c))
					return false;
			}
			return true;
		}
开发者ID:Netring,项目名称:ILSpy,代码行数:36,代码来源:OverloadResolution.cs

示例8: ResolveObjectCreation

        /// <summary>
        /// Resolves an object creation.
        /// </summary>
        /// <param name="type">Type of the object to create.</param>
        /// <param name="arguments">
        /// Arguments passed to the constructor.
        /// The resolver may mutate this array to wrap elements in <see cref="ConversionResolveResult"/>s!
        /// </param>
        /// <param name="argumentNames">
        /// The argument names. Pass the null string for positional arguments.
        /// </param>
        /// <param name="allowProtectedAccess">
        /// Whether to allow calling protected constructors.
        /// This should be false except when resolving constructor initializers.
        /// </param>
        /// <param name="initializerStatements">
        /// Statements for Objects/Collections initializer.
        /// <see cref="InvocationResolveResult.InitializerStatements"/>
        /// </param>
        /// <returns>InvocationResolveResult or ErrorResolveResult</returns>
        public ResolveResult ResolveObjectCreation(IType type, ResolveResult[] arguments, string[] argumentNames = null, bool allowProtectedAccess = false, IList<ResolveResult> initializerStatements = null)
        {
            if (type.Kind == TypeKind.Delegate && arguments.Length == 1) {
                ResolveResult input = arguments[0];
                IMethod invoke = input.Type.GetDelegateInvokeMethod();
                if (invoke != null) {
                    input = new MethodGroupResolveResult(
                        input, invoke.Name,
                        methods: new[] { new MethodListWithDeclaringType(invoke.DeclaringType) { invoke } },
                        typeArguments: EmptyList<IType>.Instance
                    );
                }
                return Convert(input, type);
            }
            OverloadResolution or = CreateOverloadResolution(arguments, argumentNames);
            MemberLookup lookup = CreateMemberLookup();
            var allApplicable = (arguments.Any(a => a.Type.Kind == TypeKind.Dynamic) ? new List<IMethod>() : null);
            foreach (IMethod ctor in type.GetConstructors()) {
                if (lookup.IsAccessible(ctor, allowProtectedAccess)) {
                    var orErrors = or.AddCandidate(ctor);
                    if (allApplicable != null && OverloadResolution.IsApplicable(orErrors))
                        allApplicable.Add(ctor);
                }
                else
                    or.AddCandidate(ctor, OverloadResolutionErrors.Inaccessible);
            }

            if (allApplicable != null && allApplicable.Count > 1) {
                // If we have dynamic arguments, we need to represent the invocation as a dynamic invocation if there is more than one applicable constructor.
                return new DynamicInvocationResolveResult(new MethodGroupResolveResult(null, allApplicable[0].Name, new[] { new MethodListWithDeclaringType(type, allApplicable) }, null), DynamicInvocationType.ObjectCreation, AddArgumentNamesIfNecessary(arguments, argumentNames), initializerStatements);
            }

            if (or.BestCandidate != null) {
                return or.CreateResolveResult(null, initializerStatements);
            } else {
                return new ErrorResolveResult(type);
            }
        }
开发者ID:CSRedRat,项目名称:NRefactory,代码行数:58,代码来源:CSharpResolver.cs

示例9: ParseConstructors

 internal void ParseConstructors(SDType sdType, IType type)
 {
     var constructors = type.GetConstructors(null, GetMemberOptions.IgnoreInheritedMembers);
     constructors = constructors.Where(o => !o.DeclaringType.FullName.StartsWith("System.Object"));
     ParseMethodList(sdType.Constructors, constructors, true);
 }
开发者ID:JoeHosman,项目名称:sharpDox,代码行数:6,代码来源:MethodParser.cs

示例10: GetCorrectConstructor

 IConstructor GetCorrectConstructor(Node sourceNode, IType type, ExpressionCollection arguments)
 {
     IConstructor[] constructors = type.GetConstructors();
     if (null != constructors && constructors.Length > 0)
     {
         return (IConstructor)GetCorrectCallableReference(sourceNode, arguments, constructors);
     }
     else
     {
         if (!TypeSystemServices.IsError(type))
         {
             if (null == (type as IGenericParameter))
             {
                 Error(CompilerErrorFactory.NoApropriateConstructorFound(sourceNode, type.ToString(), GetSignature(arguments)));
             }
             else
             {
                 Error(CompilerErrorFactory.CannotCreateAnInstanceOfGenericParameterWithoutDefaultConstructorConstraint(sourceNode, type.ToString()));
             }
         }
     }
     return null;
 }
开发者ID:w4x,项目名称:boolangstudio,代码行数:23,代码来源:ProcessMethodBodies.cs

示例11: Constructors

 /// <summary>
 /// </summary>
 /// <param name="type">
 /// </param>
 /// <returns>
 /// </returns>
 public static IEnumerable<IConstructor> Constructors(IType type)
 {
     return type.GetConstructors(BindingFlags.DeclaredOnly | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.Instance);
 }
开发者ID:SperoSophia,项目名称:il2bc,代码行数:10,代码来源:IlReader.cs

示例12: CollectMembers

		internal static IEnumerable<IEntity> CollectMembers (IType type)
		{
			yield return (IEntity)type;
			foreach (var c in type.GetConstructors ()) {
				if (!c.IsSynthetic)
					yield return c;
			}

			foreach (var m in type.GetMethods (m  => m.IsDestructor)) {
				yield return m;
			}
		}
开发者ID:nocache,项目名称:monodevelop,代码行数:12,代码来源:ReferencesFinder.cs

示例13: GetDefaultConstructor

 public IConstructor GetDefaultConstructor(IType type)
 {
     IConstructor[] constructors = type.GetConstructors();
     for (int i=0; i<constructors.Length; ++i)
     {
         IConstructor constructor = constructors[i];
         if (0 == constructor.GetParameters().Length)
         {
             return constructor;
         }
     }
     return null;
 }
开发者ID:boo,项目名称:boo-lang,代码行数:13,代码来源:TypeSystemServices.cs

示例14: CreateTypeCompletionData

 public ICompletionData CreateTypeCompletionData(IType type, bool showFullName, bool isInAttributeContext)
 {
     if (!type.Name.IsValidCompletionFor(_partialWord))
     {
         return new CompletionData("~~");
     }
     var completion = new CompletionData(type.Name);
     if (_instantiating)
     {
         foreach (var constructor in type.GetConstructors())
         {
             if (type.TypeParameterCount > 0)
             {
                 GenerateGenericMethodSignature(constructor);
                 ICompletionData completionData = CompletionData(constructor);
                 completion.AddOverload(completionData);
             }
             else
             {
                 completion.AddOverload(CreateEntityCompletionData(constructor));
             }
         }
     }
     else
     {
         completion.AddOverload(completion);
     }
     return completion;
 }
开发者ID:dykim07,项目名称:vim-ide,代码行数:29,代码来源:CompletionDataFactory.cs

示例15: HasDefaultConstructor

		private bool HasDefaultConstructor(IType argument)
		{
			if (argument.IsValueType)
				return true;
			return argument.GetConstructors().Any(ctor => ctor.GetParameters().Length == 0);
		}
开发者ID:0xb1dd1e,项目名称:boo,代码行数:6,代码来源:GenericConstructionChecker.cs


注:本文中的IType.GetConstructors方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。