System.MonoType.GetDefaultConstructor C# (CSharp) Method

GetDefaultConstructor() private method

private GetDefaultConstructor ( ) : ConstructorInfo
return System.Reflection.ConstructorInfo
		internal ConstructorInfo GetDefaultConstructor () {
			ConstructorInfo ctor = null;
			
			if (type_info == null)
				type_info = new MonoTypeInfo ();
			if ((ctor = type_info.default_ctor) == null) {
				const BindingFlags flags = BindingFlags.Public | BindingFlags.Instance | BindingFlags.NonPublic;
	
				ctor = type_info.default_ctor = GetConstructor (flags,  null, CallingConventions.Any, Type.EmptyTypes, null);
			}

			return ctor;
		}

Usage Example

Esempio n. 1
0
        public static object CreateInstance(Type type, bool nonPublic)
        {
            CheckType(type);
#if NET_2_0
            if (type.ContainsGenericParameters)
            {
                throw new ArgumentException(type + " is an open generic type", "type");
            }
#endif
            CheckAbstractType(type);

            ConstructorInfo ctor;
            MonoType        monoType = type as MonoType;

            if (monoType != null)
            {
                ctor = monoType.GetDefaultConstructor();
                if (!nonPublic && ctor != null && !ctor.IsPublic)
                {
                    ctor = null;
                }
            }
            else
            {
                BindingFlags flags = BindingFlags.Public | BindingFlags.Instance;
                if (nonPublic)
                {
                    flags |= BindingFlags.NonPublic;
                }
                ctor = type.GetConstructor(flags, null, CallingConventions.Any, Type.EmptyTypes, null);
            }

            if (ctor == null)
            {
                if (type.IsValueType)
                {
                    return(CreateInstanceInternal(type));
                }

                throw new MissingMethodException(Locale.GetText("Default constructor not found."),
                                                 ".ctor() of " + type.FullName);
            }

            return(ctor.Invoke(null));
        }
All Usage Examples Of System.MonoType::GetDefaultConstructor