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


C# ClassDataContract.RequiresMemberAccessForRead方法代码示例

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


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

示例1: GenerateClassReader

            public JsonFormatClassReaderDelegate GenerateClassReader(ClassDataContract classContract)
            {
                _ilg = new CodeGenerator();
                bool memberAccessFlag = classContract.RequiresMemberAccessForRead(null);
                try
                {
                    BeginMethod(_ilg, "Read" + DataContract.SanitizeTypeName(classContract.StableName.Name) + "FromJson", typeof(JsonFormatClassReaderDelegate), memberAccessFlag);
                }
                catch (SecurityException securityException)
                {
                    if (memberAccessFlag)
                    {
                        classContract.RequiresMemberAccessForRead(securityException);
                    }
                    else
                    {
                        throw;
                    }
                }
                InitArgs();
                CreateObject(classContract);
                _ilg.Call(_contextArg, XmlFormatGeneratorStatics.AddNewObjectMethod, _objectLocal);
                InvokeOnDeserializing(classContract);
                if (classContract.IsISerializable)
                    ReadISerializable(classContract);
                else
                    ReadClass(classContract);

                if (Globals.TypeOfIDeserializationCallback.IsAssignableFrom(classContract.UnderlyingType))
                {
                    _ilg.Call(_objectLocal, JsonFormatGeneratorStatics.OnDeserializationMethod, null);
                }

                InvokeOnDeserialized(classContract);
                if (!InvokeFactoryMethod(classContract))
                {
                    _ilg.Load(_objectLocal);
                    // Do a conversion back from DateTimeOffsetAdapter to DateTimeOffset after deserialization.
                    // DateTimeOffsetAdapter is used here for deserialization purposes to bypass the ISerializable implementation
                    // on DateTimeOffset; which does not work in partial trust.

                    if (classContract.UnderlyingType == Globals.TypeOfDateTimeOffsetAdapter)
                    {
                        _ilg.ConvertValue(_objectLocal.LocalType, Globals.TypeOfDateTimeOffsetAdapter);
                        _ilg.Call(XmlFormatGeneratorStatics.GetDateTimeOffsetMethod);
                        _ilg.ConvertValue(Globals.TypeOfDateTimeOffset, _ilg.CurrentMethod.ReturnType);
                    }
                    //Copy the KeyValuePairAdapter<K,T> to a KeyValuePair<K,T>. 
                    else if (classContract.IsKeyValuePairAdapter)
                    {
                        _ilg.Call(classContract.GetKeyValuePairMethodInfo);
                        _ilg.ConvertValue(Globals.TypeOfKeyValuePair.MakeGenericType(classContract.KeyValuePairGenericArguments), _ilg.CurrentMethod.ReturnType);
                    }
                    else
                    {
                        _ilg.ConvertValue(_objectLocal.LocalType, _ilg.CurrentMethod.ReturnType);
                    }
                }
                return (JsonFormatClassReaderDelegate)_ilg.EndMethod();
            }
开发者ID:dotnet,项目名称:corefx,代码行数:60,代码来源:JsonFormatReaderGenerator.cs

示例2: GenerateClassReader

            public XmlFormatClassReaderDelegate GenerateClassReader(ClassDataContract classContract)
            {
                ilg = new CodeGenerator();
                bool memberAccessFlag = classContract.RequiresMemberAccessForRead(null);
                try
                {
                    ilg.BeginMethod("Read" + classContract.StableName.Name + "FromXml", Globals.TypeOfXmlFormatClassReaderDelegate, memberAccessFlag);
                }
                catch (SecurityException securityException)
                {
                    if (memberAccessFlag && securityException.PermissionType.Equals(typeof(ReflectionPermission)))
                    {
                        classContract.RequiresMemberAccessForRead(securityException);
                    }
                    else
                    {
                        throw;
                    }
                }

                InitArgs();
                DemandSerializationFormatterPermission(classContract);
                DemandMemberAccessPermission(memberAccessFlag);
                CreateObject(classContract);
                ilg.Call(contextArg, XmlFormatGeneratorStatics.AddNewObjectMethod, objectLocal);
                InvokeOnDeserializing(classContract);
                LocalBuilder objectId = null;
                if (HasFactoryMethod(classContract))
                {
                    objectId = ilg.DeclareLocal(Globals.TypeOfString, "objectIdRead");
                    ilg.Call(contextArg, XmlFormatGeneratorStatics.GetObjectIdMethod);
                    ilg.Stloc(objectId);
                }
                if (classContract.IsISerializable)
                    ReadISerializable(classContract);
                else
                    ReadClass(classContract);
                bool isFactoryType = InvokeFactoryMethod(classContract, objectId);
                if (Globals.TypeOfIDeserializationCallback.IsAssignableFrom(classContract.UnderlyingType))
                    ilg.Call(objectLocal, XmlFormatGeneratorStatics.OnDeserializationMethod, null);
                InvokeOnDeserialized(classContract);
                if (objectId == null || !isFactoryType)
                {
                    ilg.Load(objectLocal);

                    // Do a conversion back from DateTimeOffsetAdapter to DateTimeOffset after deserialization.
                    // DateTimeOffsetAdapter is used here for deserialization purposes to bypass the ISerializable implementation
                    // on DateTimeOffset; which does not work in partial trust.

                    if (classContract.UnderlyingType == Globals.TypeOfDateTimeOffsetAdapter)
                    {
                        ilg.ConvertValue(objectLocal.LocalType, Globals.TypeOfDateTimeOffsetAdapter);
                        ilg.Call(XmlFormatGeneratorStatics.GetDateTimeOffsetMethod);
                        ilg.ConvertValue(Globals.TypeOfDateTimeOffset, ilg.CurrentMethod.ReturnType);
                    }
                    else
                    {
                        ilg.ConvertValue(objectLocal.LocalType, ilg.CurrentMethod.ReturnType);
                    }
                }
                return (XmlFormatClassReaderDelegate)ilg.EndMethod();
            }
开发者ID:nlh774,项目名称:DotNetReferenceSource,代码行数:62,代码来源:XmlFormatReaderGenerator.cs

示例3: GenerateClassReader

 public XmlFormatClassReaderDelegate GenerateClassReader(ClassDataContract classContract)
 {
     this.ilg = new CodeGenerator();
     bool allowPrivateMemberAccess = classContract.RequiresMemberAccessForRead(null);
     try
     {
         this.ilg.BeginMethod("Read" + classContract.StableName.Name + "FromXml", Globals.TypeOfXmlFormatClassReaderDelegate, allowPrivateMemberAccess);
     }
     catch (SecurityException exception)
     {
         if (!allowPrivateMemberAccess || !exception.PermissionType.Equals(typeof(ReflectionPermission)))
         {
             throw;
         }
         classContract.RequiresMemberAccessForRead(exception);
     }
     this.InitArgs();
     this.DemandSerializationFormatterPermission(classContract);
     this.DemandMemberAccessPermission(allowPrivateMemberAccess);
     this.CreateObject(classContract);
     this.ilg.Call(this.contextArg, XmlFormatGeneratorStatics.AddNewObjectMethod, this.objectLocal);
     this.InvokeOnDeserializing(classContract);
     LocalBuilder local = null;
     if (this.HasFactoryMethod(classContract))
     {
         local = this.ilg.DeclareLocal(Globals.TypeOfString, "objectIdRead");
         this.ilg.Call(this.contextArg, XmlFormatGeneratorStatics.GetObjectIdMethod);
         this.ilg.Stloc(local);
     }
     if (classContract.IsISerializable)
     {
         this.ReadISerializable(classContract);
     }
     else
     {
         this.ReadClass(classContract);
     }
     if (Globals.TypeOfIDeserializationCallback.IsAssignableFrom(classContract.UnderlyingType))
     {
         this.ilg.Call(this.objectLocal, XmlFormatGeneratorStatics.OnDeserializationMethod, null);
     }
     this.InvokeOnDeserialized(classContract);
     if ((local == null) || !this.InvokeFactoryMethod(classContract, local))
     {
         this.ilg.Load(this.objectLocal);
         if (classContract.UnderlyingType == Globals.TypeOfDateTimeOffsetAdapter)
         {
             this.ilg.ConvertValue(this.objectLocal.LocalType, Globals.TypeOfDateTimeOffsetAdapter);
             this.ilg.Call(XmlFormatGeneratorStatics.GetDateTimeOffsetMethod);
             this.ilg.ConvertValue(Globals.TypeOfDateTimeOffset, this.ilg.CurrentMethod.ReturnType);
         }
         else
         {
             this.ilg.ConvertValue(this.objectLocal.LocalType, this.ilg.CurrentMethod.ReturnType);
         }
     }
     return (XmlFormatClassReaderDelegate) this.ilg.EndMethod();
 }
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:58,代码来源:XmlFormatReaderGenerator.cs

示例4: GenerateClassReader

            public XmlFormatClassReaderDelegate GenerateClassReader(ClassDataContract classContract)
            {
                if (DataContractSerializer.Option == SerializationOption.ReflectionOnly)
                {
                    return new ReflectionXmlClassReader(classContract).ReflectionReadClass;
                }
#if NET_NATIVE
                else if (DataContractSerializer.Option == SerializationOption.ReflectionAsBackup)
                {
                    return new ReflectionXmlClassReader(classContract).ReflectionReadClass;
                }
#endif
                else
                {
#if NET_NATIVE
                    throw new InvalidOperationException("Cannot generate class reader");
#else
                    _ilg = new CodeGenerator();
                    bool memberAccessFlag = classContract.RequiresMemberAccessForRead(null);
                    try
                    {
                        _ilg.BeginMethod("Read" + classContract.StableName.Name + "FromXml", Globals.TypeOfXmlFormatClassReaderDelegate, memberAccessFlag);
                    }
                    catch (SecurityException securityException)
                    {
                        if (memberAccessFlag)
                        {
                            classContract.RequiresMemberAccessForRead(securityException);
                        }
                        else
                        {
                            throw;
                        }
                    }

                    InitArgs();
                    CreateObject(classContract);
                    _ilg.Call(_contextArg, XmlFormatGeneratorStatics.AddNewObjectMethod, _objectLocal);
                    InvokeOnDeserializing(classContract);
                    LocalBuilder objectId = null;
                    if (classContract.IsISerializable)
                    {
                        ReadISerializable(classContract);
                    }
                    else
                    {
                        ReadClass(classContract);
                    }

                    if (Globals.TypeOfIDeserializationCallback.IsAssignableFrom(classContract.UnderlyingType))
                    {
                        _ilg.Call(_objectLocal, XmlFormatGeneratorStatics.OnDeserializationMethod, null);
                    }

                    InvokeOnDeserialized(classContract);
                    if (objectId == null)
                    {
                        _ilg.Load(_objectLocal);

                        // Do a conversion back from DateTimeOffsetAdapter to DateTimeOffset after deserialization.
                        // DateTimeOffsetAdapter is used here for deserialization purposes to bypass the ISerializable implementation
                        // on DateTimeOffset; which does not work in partial trust.

                        if (classContract.UnderlyingType == Globals.TypeOfDateTimeOffsetAdapter)
                        {
                            _ilg.ConvertValue(_objectLocal.LocalType, Globals.TypeOfDateTimeOffsetAdapter);
                            _ilg.Call(XmlFormatGeneratorStatics.GetDateTimeOffsetMethod);
                            _ilg.ConvertValue(Globals.TypeOfDateTimeOffset, _ilg.CurrentMethod.ReturnType);
                        }
                        //Copy the KeyValuePairAdapter<K,T> to a KeyValuePair<K,T>. 
                        else if (classContract.IsKeyValuePairAdapter)
                        {
                            _ilg.Call(classContract.GetKeyValuePairMethodInfo);
                            _ilg.ConvertValue(Globals.TypeOfKeyValuePair.MakeGenericType(classContract.KeyValuePairGenericArguments), _ilg.CurrentMethod.ReturnType);
                        }
                        else
                        {
                            _ilg.ConvertValue(_objectLocal.LocalType, _ilg.CurrentMethod.ReturnType);
                        }
                    }
                    return (XmlFormatClassReaderDelegate)_ilg.EndMethod();
#endif
                }
            }
开发者ID:rajansingh10,项目名称:corefx,代码行数:84,代码来源:XmlFormatReaderGenerator.cs


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