Пример #1
0
            internal EnumDataContractCriticalHelper(
                [DynamicallyAccessedMembers(ClassDataContract.DataContractPreserveMemberTypes)]
                Type type) : base(type)
            {
                this.StableName = DataContract.GetStableName(type, out _hasDataContract);
                Type baseType = Enum.GetUnderlyingType(type);

                ImportBaseType(baseType);
                IsFlags = type.IsDefined(Globals.TypeOfFlagsAttribute, false);
                ImportDataMembers();

                XmlDictionary dictionary = new XmlDictionary(2 + Members.Count);

                Name               = dictionary.Add(StableName.Name);
                Namespace          = dictionary.Add(StableName.Namespace);
                _childElementNames = new XmlDictionaryString[Members.Count];
                for (int i = 0; i < Members.Count; i++)
                {
                    _childElementNames[i] = dictionary.Add(Members[i].Name);
                }
                DataContractAttribute?dataContractAttribute;

                if (TryGetDCAttribute(type, out dataContractAttribute))
                {
                    if (dataContractAttribute.IsReference)
                    {
                        DataContract.ThrowInvalidDataContractException(
                            SR.Format(SR.EnumTypeCannotHaveIsReference,
                                      DataContract.GetClrTypeFullName(type),
                                      dataContractAttribute.IsReference,
                                      false),
                            type);
                    }
                }
            }
Пример #2
0
            internal EnumDataContractCriticalHelper(Type type) : base(type)
            {
                DataContractAttribute attribute;

                base.StableName = DataContract.GetStableName(type, out this.hasDataContract);
                Type underlyingType = Enum.GetUnderlyingType(type);

                this.baseContractName = GetBaseContractName(underlyingType);
                this.ImportBaseType(underlyingType);
                this.IsFlags = type.IsDefined(Globals.TypeOfFlagsAttribute, false);
                this.ImportDataMembers();
                XmlDictionary dictionary = new XmlDictionary(2 + this.Members.Count);

                base.Name              = dictionary.Add(base.StableName.Name);
                base.Namespace         = dictionary.Add(base.StableName.Namespace);
                this.childElementNames = new XmlDictionaryString[this.Members.Count];
                for (int i = 0; i < this.Members.Count; i++)
                {
                    this.childElementNames[i] = dictionary.Add(this.Members[i].Name);
                }
                if (DataContract.TryGetDCAttribute(type, out attribute) && attribute.IsReference)
                {
                    DataContract.ThrowInvalidDataContractException(System.Runtime.Serialization.SR.GetString("EnumTypeCannotHaveIsReference", new object[] { DataContract.GetClrTypeFullName(type), attribute.IsReference, false }), type);
                }
            }
        public void WriteCollectionToXml(XmlWriterDelegator xmlWriter, object obj, XmlObjectSerializerWriteContext context, CollectionDataContract collectionContract)
        {
            this.writer       = xmlWriter;
            this.obj          = obj;
            this.ctx          = context;
            this.dataContract = collectionContract;

            InitArgs(collectionContract.UnderlyingType);

            // DemandMemberAccessPermission(memberAccessFlag);
            if (collectionContract.IsReadOnlyContract)
            {
                DataContract.ThrowInvalidDataContractException(collectionContract.SerializationExceptionMessage, null);
            }

            WriteCollection(collectionContract);
        }
Пример #4
0
        private static void CheckAndAddMember(List <DataMember> members, DataMember memberContract, Dictionary <string, DataMember> memberNamesTable)
        {
            DataMember existingMemberContract;

            if (memberNamesTable.TryGetValue(memberContract.Name, out existingMemberContract))
            {
                Type declaringType = memberContract.MemberInfo.DeclaringType;
                DataContract.ThrowInvalidDataContractException(
                    SR.Format(SR.DupMemberName,
                              existingMemberContract.MemberInfo.Name,
                              memberContract.MemberInfo.Name,
                              DataContract.GetClrTypeFullName(declaringType),
                              memberContract.Name),
                    declaringType);
            }
            memberNamesTable.Add(memberContract.Name, memberContract);
            members.Add(memberContract);
        }
        public void WriteToXml(XmlWriterDelegator xmlWriter, object obj, XmlObjectSerializerWriteContext context, ClassDataContract dataContract)
        {
            this.writer       = xmlWriter;
            this.obj          = obj;
            this.ctx          = context;
            this.dataContract = dataContract;

            InitArgs(classContract.UnderlyingType);

            // DemandSerializationFormatterPermission (classContract) - irrelevant
            // DemandMemberAccessPermission (memberAccessFlag) - irrelevant

            if (classContract.IsReadOnlyContract)
            {
                DataContract.ThrowInvalidDataContractException(classContract.SerializationExceptionMessage, null);
            }

            WriteClass(classContract);
        }