Ejemplo n.º 1
0
        protected virtual bool LookupConstructionRequiresArguments()
        {
            if (UnderlyingType == null)
            {
                return(false);
            }

            // not sure if it is required, but MemberDefinition return true while they are abstract and it makes no sense.
            if (UnderlyingType.IsAbstract)
            {
                return(true);
            }

            // FIXME: probably some primitive types are treated as special.
            switch (Type.GetTypeCode(UnderlyingType))
            {
            case TypeCode.String:
                return(true);

            case TypeCode.Object:
                if (UnderlyingType == typeof(TimeSpan))
                {
                    return(false);
                }
                break;

            default:
                return(false);
            }

            return(UnderlyingType.GetConstructor(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance, null, Type.EmptyTypes, null) == null);
        }
Ejemplo n.º 2
0
        private ConstructorInfo?GetConstructor()
        {
            if (UnderlyingType.IsValueType)
            {
                return(null);
            }

            ConstructorInfo?ctor = UnderlyingType.GetConstructor(BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public, Type.EmptyTypes);

            if (ctor == null)
            {
                throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidDataContractException(SR.Format(SR.IXmlSerializableMustHaveDefaultConstructor, DataContract.GetClrTypeFullName(UnderlyingType))));
            }

            return(ctor);
        }