internal XmlFormatClassWriterDelegate GenerateClassWriter(ClassDataContract classContract)
 {
     if (DataContractSerializer.Option == SerializationOption.ReflectionOnly)
     {
         return CreateReflectionXmlFormatClassWriterDelegate();
     }
     else
     {
         _ilg = new CodeGenerator();
         bool memberAccessFlag = classContract.RequiresMemberAccessForWrite(null);
         try
         {
             _ilg.BeginMethod("Write" + classContract.StableName.Name + "ToXml", Globals.TypeOfXmlFormatClassWriterDelegate, memberAccessFlag);
         }
         catch (SecurityException securityException)
         {
             if (memberAccessFlag)
             {
                 classContract.RequiresMemberAccessForWrite(securityException);
             }
             else
             {
                 throw;
             }
         }
         InitArgs(classContract.UnderlyingType);
         WriteClass(classContract);
         return (XmlFormatClassWriterDelegate)_ilg.EndMethod();
     }
 }
Esempio n. 2
0
            internal JsonFormatClassWriterDelegate GenerateClassWriter(ClassDataContract classContract)
            {
                _ilg = new CodeGenerator();
                bool memberAccessFlag = classContract.RequiresMemberAccessForWrite(null);

                try
                {
                    BeginMethod(_ilg, "Write" + DataContract.SanitizeTypeName(classContract.StableName.Name) + "ToJson", typeof(JsonFormatClassWriterDelegate), memberAccessFlag);
                }
                catch (SecurityException securityException)
                {
                    if (memberAccessFlag)
                    {
                        classContract.RequiresMemberAccessForWrite(securityException);
                    }
                    else
                    {
                        throw;
                    }
                }
                InitArgs(classContract.UnderlyingType);
                _memberNamesArg = _ilg.GetArg(4);
                WriteClass(classContract);
                return((JsonFormatClassWriterDelegate)_ilg.EndMethod());
            }
            internal JsonFormatClassWriterDelegate GenerateClassWriter(ClassDataContract classContract)
            {
                ilg = new CodeGenerator();
                bool memberAccessFlag = classContract.RequiresMemberAccessForWrite(null);

                try
                {
                    BeginMethod(ilg, "Write" + classContract.StableName.Name + "ToJson", typeof(JsonFormatClassWriterDelegate), memberAccessFlag);
                }
                catch (SecurityException securityException)
                {
                    if (memberAccessFlag && securityException.PermissionType.Equals(typeof(ReflectionPermission)))
                    {
                        classContract.RequiresMemberAccessForWrite(securityException);
                    }
                    else
                    {
                        throw;
                    }
                }
                InitArgs(classContract.UnderlyingType);
                memberNamesArg = ilg.GetArg(4);
                DemandSerializationFormatterPermission(classContract);
                DemandMemberAccessPermission(memberAccessFlag);
                if (classContract.IsReadOnlyContract)
                {
                    ThrowIfCannotSerializeReadOnlyTypes(classContract);
                }
                WriteClass(classContract);
                return((JsonFormatClassWriterDelegate)ilg.EndMethod());
            }
        static internal void InvokeOnSerialized(Object value, DataContract contract, XmlObjectSerializerWriteContextComplexJson context)
        {
            if (contract is ClassDataContract)
            {
                ClassDataContract classContract = contract as ClassDataContract;

                if (classContract.BaseContract != null)
                {
                    InvokeOnSerialized(value, classContract.BaseContract, context);
                }
                if (classContract.OnSerialized != null)
                {
                    bool memberAccessFlag = classContract.RequiresMemberAccessForWrite(null, JsonGlobals.JsonSerializationPatterns);
                    try
                    {
                        DisallowMemberAccess(memberAccessFlag);
                        classContract.OnSerialized.Invoke(value, new object[] { context.GetStreamingContext() });
                    }
                    catch (SecurityException securityException)
                    {
                        if (memberAccessFlag)
                        {
                            classContract.RequiresMemberAccessForWrite(securityException, JsonGlobals.JsonSerializationPatterns);
                        }
                        else
                        {
                            throw;
                        }
                    }
                    catch (TargetInvocationException targetInvocationException)
                    {
                        if (targetInvocationException.InnerException == null)
                        {
                            throw;
                        }
                        //We are catching the TIE here and throws the inner exception only,
                        //this is needed to have a consistent exception story in all serializers
                        throw targetInvocationException.InnerException;
                    }
                }
            }
        }
Esempio n. 5
0
            internal XmlFormatClassWriterDelegate GenerateClassWriter(ClassDataContract classContract)
            {
                if (DataContractSerializer.Option == SerializationOption.ReflectionOnly)
                {
                    return(new ReflectionXmlFormatWriter().ReflectionWriteClass);
                }
#if uapaot
                else if (DataContractSerializer.Option == SerializationOption.ReflectionAsBackup)
                {
                    return(new ReflectionXmlFormatWriter().ReflectionWriteClass);
                }
#endif
                else
                {
#if USE_REFEMIT || uapaot
                    throw new InvalidOperationException("Cannot generate class writer");
#else
                    _ilg = new CodeGenerator();
                    bool memberAccessFlag = classContract.RequiresMemberAccessForWrite(null);
                    try
                    {
                        _ilg.BeginMethod("Write" + classContract.StableName.Name + "ToXml", Globals.TypeOfXmlFormatClassWriterDelegate, memberAccessFlag);
                    }
                    catch (SecurityException securityException)
                    {
                        if (memberAccessFlag)
                        {
                            classContract.RequiresMemberAccessForWrite(securityException);
                        }
                        else
                        {
                            throw;
                        }
                    }
                    InitArgs(classContract.UnderlyingType);
                    WriteClass(classContract);
                    return((XmlFormatClassWriterDelegate)_ilg.EndMethod());
#endif
                }
            }
Esempio n. 6
0
            internal XmlFormatClassWriterDelegate GenerateClassWriter(ClassDataContract classContract)
            {
                ilg = new CodeGenerator();
                bool memberAccessFlag = classContract.RequiresMemberAccessForWrite(null);

                ilg.BeginMethod("Write" + classContract.StableName.Name + "ToXml", Globals.TypeOfXmlFormatClassWriterDelegate, memberAccessFlag);
                InitArgs(classContract.UnderlyingType);
                if (classContract.IsReadOnlyContract)
                {
                    ThrowIfCannotSerializeReadOnlyTypes(classContract);
                }
                WriteClass(classContract);
                return((XmlFormatClassWriterDelegate)ilg.EndMethod());
            }
 internal JsonFormatClassWriterDelegate GenerateClassWriter(ClassDataContract classContract)
 {
     this.ilg = new CodeGenerator();
     bool allowPrivateMemberAccess = classContract.RequiresMemberAccessForWrite(null);
     try
     {
         this.BeginMethod(this.ilg, "Write" + classContract.StableName.Name + "ToJson", typeof(JsonFormatClassWriterDelegate), allowPrivateMemberAccess);
     }
     catch (SecurityException exception)
     {
         if (!allowPrivateMemberAccess || !exception.PermissionType.Equals(typeof(ReflectionPermission)))
         {
             throw;
         }
         classContract.RequiresMemberAccessForWrite(exception);
     }
     this.InitArgs(classContract.UnderlyingType);
     this.memberNamesArg = this.ilg.GetArg(4);
     this.DemandSerializationFormatterPermission(classContract);
     this.DemandMemberAccessPermission(allowPrivateMemberAccess);
     this.WriteClass(classContract);
     return (JsonFormatClassWriterDelegate) this.ilg.EndMethod();
 }
            internal XmlFormatClassWriterDelegate GenerateClassWriter(ClassDataContract classContract)
            {
                this.ilg = new CodeGenerator();
                bool allowPrivateMemberAccess = classContract.RequiresMemberAccessForWrite(null);

                try
                {
                    this.ilg.BeginMethod("Write" + classContract.StableName.Name + "ToXml", Globals.TypeOfXmlFormatClassWriterDelegate, allowPrivateMemberAccess);
                }
                catch (SecurityException exception)
                {
                    if (!allowPrivateMemberAccess || !exception.PermissionType.Equals(typeof(ReflectionPermission)))
                    {
                        throw;
                    }
                    classContract.RequiresMemberAccessForWrite(exception);
                }
                this.InitArgs(classContract.UnderlyingType);
                this.DemandSerializationFormatterPermission(classContract);
                this.DemandMemberAccessPermission(allowPrivateMemberAccess);
                this.WriteClass(classContract);
                return((XmlFormatClassWriterDelegate)this.ilg.EndMethod());
            }
 internal JsonFormatClassWriterDelegate GenerateClassWriter(ClassDataContract classContract)
 {
     _ilg = new CodeGenerator();
     bool memberAccessFlag = classContract.RequiresMemberAccessForWrite(null, JsonGlobals.JsonSerializationPatterns);
     try
     {
         BeginMethod(_ilg, "Write" + DataContract.SanitizeTypeName(classContract.StableName.Name) + "ToJson", typeof(JsonFormatClassWriterDelegate), memberAccessFlag);
     }
     catch (SecurityException securityException)
     {
         if (memberAccessFlag)
         {
             classContract.RequiresMemberAccessForWrite(securityException, JsonGlobals.JsonSerializationPatterns);
         }
         else
         {
             throw;
         }
     }
     InitArgs(classContract.UnderlyingType);
     _memberNamesArg = _ilg.GetArg(4);
     WriteClass(classContract);
     return (JsonFormatClassWriterDelegate)_ilg.EndMethod();
 }
Esempio n. 10
0
            internal XmlFormatClassWriterDelegate GenerateClassWriter(ClassDataContract classContract)
            {
                if (DataContractSerializer.Option == SerializationOption.ReflectionOnly)
                {
                    return new ReflectionXmlFormatWriter().ReflectionWriteClass;
                }
#if NET_NATIVE
                else if (DataContractSerializer.Option == SerializationOption.ReflectionAsBackup)
                {
                    return new ReflectionXmlFormatWriter().ReflectionWriteClass;
                }
#endif
                else
                {
#if USE_REFEMIT || NET_NATIVE
                    throw new InvalidOperationException("Cannot generate class writer");
#else
                    _ilg = new CodeGenerator();
                    bool memberAccessFlag = classContract.RequiresMemberAccessForWrite(null);
                    try
                    {
                        _ilg.BeginMethod("Write" + classContract.StableName.Name + "ToXml", Globals.TypeOfXmlFormatClassWriterDelegate, memberAccessFlag);
                    }
                    catch (SecurityException securityException)
                    {
                        if (memberAccessFlag)
                        {
                            classContract.RequiresMemberAccessForWrite(securityException);
                        }
                        else
                        {
                            throw;
                        }
                    }
                    InitArgs(classContract.UnderlyingType);
                    WriteClass(classContract);
                    return (XmlFormatClassWriterDelegate)_ilg.EndMethod();
#endif
                }
            }
Esempio n. 11
0
 internal XmlFormatClassWriterDelegate GenerateClassWriter(ClassDataContract classContract)
 {
     _ilg = new CodeGenerator();
     bool memberAccessFlag = classContract.RequiresMemberAccessForWrite(null, Globals.DataContractSerializationPatterns);
     try
     {
         _ilg.BeginMethod("Write" + classContract.StableName.Name + "ToXml", Globals.TypeOfXmlFormatClassWriterDelegate, memberAccessFlag);
     }
     catch (SecurityException securityException)
     {
         if (memberAccessFlag)
         {
             classContract.RequiresMemberAccessForWrite(securityException, Globals.DataContractSerializationPatterns);
         }
         else
         {
             throw;
         }
     }
     InitArgs(classContract.UnderlyingType);
     WriteClass(classContract);
     return (XmlFormatClassWriterDelegate)_ilg.EndMethod();
 }
 internal JsonFormatClassWriterDelegate GenerateClassWriter(ClassDataContract classContract)
 {
     ilg = new CodeGenerator();
     bool memberAccessFlag = classContract.RequiresMemberAccessForWrite(null);
     try
     {
         BeginMethod(ilg, "Write" + classContract.StableName.Name + "ToJson", typeof(JsonFormatClassWriterDelegate), memberAccessFlag);
     }
     catch (SecurityException securityException)
     {
         if (memberAccessFlag && securityException.PermissionType.Equals(typeof(ReflectionPermission)))
         {
             classContract.RequiresMemberAccessForWrite(securityException);
         }
         else
         {
             throw;
         }
     }
     InitArgs(classContract.UnderlyingType);
     memberNamesArg = ilg.GetArg(4);
     DemandSerializationFormatterPermission(classContract);
     DemandMemberAccessPermission(memberAccessFlag);
     if (classContract.IsReadOnlyContract)
     {
         ThrowIfCannotSerializeReadOnlyTypes(classContract);
     }
     WriteClass(classContract);
     return (JsonFormatClassWriterDelegate)ilg.EndMethod();
 }