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


C# ClassDataContract类代码示例

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


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

示例1: DemandSerializationFormatterPermission

 private void DemandSerializationFormatterPermission(ClassDataContract classContract)
 {
     if (!classContract.HasDataContract && !classContract.IsNonAttributedType)
     {
         this.ilg.Call(this.contextArg, XmlFormatGeneratorStatics.DemandSerializationFormatterPermissionMethod);
     }
 }
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:7,代码来源:JsonFormatWriterGenerator.cs

示例2: ConvertDictionaryToClassDataContract

        public static object ConvertDictionaryToClassDataContract(DataContractJsonSerializer serializer, ClassDataContract dataContract, Dictionary<string, object> deserialzedValue, XmlObjectSerializerReadContextComplexJson context)
        {
            if (deserialzedValue == null)
            {
                return null;
            }

            if (dataContract.UnderlyingType == Globals.TypeOfDateTimeOffsetAdapter)
            {
                var tuple = deserialzedValue["DateTime"] as Tuple<DateTime, string>;
                DateTimeOffset dto = new DateTimeOffset(tuple != null ? tuple.Item1 : (DateTime)deserialzedValue["DateTime"]);
                return dto.ToOffset(new TimeSpan(0, (int)deserialzedValue["OffsetMinutes"], 0));
            }

            object serverTypeStringValue;
            if (deserialzedValue.TryGetValue(JsonGlobals.ServerTypeString, out serverTypeStringValue))
            {
                dataContract = ResolveDataContractFromTypeInformation(serverTypeStringValue.ToString(), dataContract, context);
            }

            object o = CreateInstance(dataContract);

            CheckDuplicateNames(dataContract);
            DataContractJsonSerializer.InvokeOnDeserializing(o, dataContract, context);
            ReadClassDataContractMembers(serializer, dataContract, deserialzedValue, o, context);
            DataContractJsonSerializer.InvokeOnDeserialized(o, dataContract, context);
            if (dataContract.IsKeyValuePairAdapter)
            {
                return dataContract.GetKeyValuePairMethodInfo.Invoke(o, Array.Empty<Type>());
            }
            return o;
        }
开发者ID:er0dr1guez,项目名称:corefx,代码行数:32,代码来源:ObjectToDataContractConverterHelper.cs

示例3: CreateObject

 private void CreateObject(ClassDataContract classContract)
 {
     Type typeOfValueType = this.objectType = classContract.UnderlyingType;
     if (typeOfValueType.IsValueType && !classContract.IsNonAttributedType)
     {
         typeOfValueType = Globals.TypeOfValueType;
     }
     this.objectLocal = this.ilg.DeclareLocal(typeOfValueType, "objectDeserialized");
     if (classContract.UnderlyingType == Globals.TypeOfDBNull)
     {
         this.ilg.LoadMember(Globals.TypeOfDBNull.GetField("Value"));
         this.ilg.Stloc(this.objectLocal);
     }
     else if (classContract.IsNonAttributedType)
     {
         if (typeOfValueType.IsValueType)
         {
             this.ilg.Ldloca(this.objectLocal);
             this.ilg.InitObj(typeOfValueType);
         }
         else
         {
             this.ilg.New(classContract.GetNonAttributedTypeConstructor());
             this.ilg.Stloc(this.objectLocal);
         }
     }
     else
     {
         this.ilg.Call(null, XmlFormatGeneratorStatics.GetUninitializedObjectMethod, DataContract.GetIdForInitialization(classContract));
         this.ilg.ConvertValue(Globals.TypeOfObject, typeOfValueType);
         this.ilg.Stloc(this.objectLocal);
     }
 }
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:33,代码来源:XmlFormatReaderGenerator.cs

示例4: AddClassDataContract

 private void AddClassDataContract(ClassDataContract classDataContract)
 {
     if (classDataContract.BaseContract != null)
     {
         this.Add(classDataContract.BaseContract.StableName, classDataContract.BaseContract);
     }
     if (!classDataContract.IsISerializable && (classDataContract.Members != null))
     {
         for (int i = 0; i < classDataContract.Members.Count; i++)
         {
             DataMember dataMember = classDataContract.Members[i];
             DataContract memberTypeDataContract = this.GetMemberTypeDataContract(dataMember);
             if ((this.dataContractSurrogate != null) && (dataMember.MemberInfo != null))
             {
                 object obj2 = DataContractSurrogateCaller.GetCustomDataToExport(this.dataContractSurrogate, dataMember.MemberInfo, memberTypeDataContract.UnderlyingType);
                 if (obj2 != null)
                 {
                     this.SurrogateDataTable.Add(dataMember, obj2);
                 }
             }
             this.Add(memberTypeDataContract.StableName, memberTypeDataContract);
         }
     }
     this.AddKnownDataContracts(classDataContract.KnownDataContracts);
 }
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:25,代码来源:DataContractSet.cs

示例5: GenerateClassWriter

 internal XmlFormatClassWriterDelegate GenerateClassWriter(ClassDataContract classContract)
 {
     if (_useReflection)
     {
         return new ReflectionXmlFormatWriter().ReflectionWriteClass;
     }
     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();
     }
 }
开发者ID:SGuyGe,项目名称:corefx,代码行数:30,代码来源:XmlFormatWriterGenerator.cs

示例6: 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

示例7: ReflectionWriteMembers

        internal int ReflectionWriteMembers(XmlWriterDelegator xmlWriter, object obj, XmlObjectSerializerWriteContext context, ClassDataContract classContract, ClassDataContract derivedMostClassContract)
        {
            int memberCount = (classContract.BaseContract == null) ? 0 :
                ReflectionWriteMembers(xmlWriter, obj, context, classContract.BaseContract, derivedMostClassContract);

            Type classType = classContract.UnadaptedClassType;
            XmlDictionaryString[] memberNames = classContract.MemberNames;
            XmlDictionaryString ns = classContract.Namespace;
            context.IncrementItemCount(classContract.Members.Count);
            for (int i = 0; i < classContract.Members.Count; i++, memberCount++)
            {
                DataMember member = classContract.Members[i];
                Type memberType = member.MemberType;
                if (member.IsGetOnlyCollection)
                {
                    context.StoreIsGetOnlyCollection();
                }
                bool writeXsiType = CheckIfMemberHasConflict(member, classContract, derivedMostClassContract);
                MemberInfo memberInfo = member.MemberInfo;
                object memberValue = ReflectionGetMemberValue(obj, memberInfo);
                if (writeXsiType || !ReflectionTryWritePrimitive(xmlWriter, context, memberType, memberValue, member.MemberInfo, null /*arrayItemIndex*/, ns, memberNames[i] /*nameLocal*/, i + _childElementIndex))
                {
                    ReflectionWriteStartElement(memberType, ns, ns.Value, member.Name, 0);
                    if (classContract.ChildElementNamespaces[i + _childElementIndex] != null)
                    {
                        var nsChildElement = classContract.ChildElementNamespaces[i + _childElementIndex];
                        _arg0XmlWriter.WriteNamespaceDecl(nsChildElement);
                    }
                    ReflectionWriteValue(memberType, memberValue, writeXsiType);
                    ReflectionWriteEndElement();
                }
            }

            return 0;
        }
开发者ID:SGuyGe,项目名称:corefx,代码行数:35,代码来源:ReflectionXmlFormatWriter.cs

示例8: ReflectionWriteClass

 public void ReflectionWriteClass(XmlWriterDelegator xmlWriter, object obj, XmlObjectSerializerWriteContext context, ClassDataContract classContract, XmlDictionaryString[] memberNames)
 {
     InvokeOnSerializing(obj, context, classContract);
     obj = ResolveAdapterType(obj, classContract);
     ReflectionWriteMembers(xmlWriter, obj, context, classContract, classContract, 0 /*childElementIndex*/, memberNames);
     InvokeOnSerialized(obj, context, classContract);
 }
开发者ID:swaroop-sridhar,项目名称:corefx,代码行数:7,代码来源:ReflectionClassWriter.cs

示例9: ProcessClassDataContract

 static DataContract ProcessClassDataContract(ClassDataContract contract, ExportContext context, MemberInfo memberNode)
 {
     string prefix = context.SetNamespace(contract.Namespace.Value);
     foreach (DataMember member in GetDataMembers(contract))
     {
         if (member.MemberInfo.Name == memberNode.Name && member.MemberInfo.DeclaringType.IsAssignableFrom(memberNode.DeclaringType))
         {
             context.WriteChildToContext(member, prefix);
             return member.MemberTypeContract;
         }
     }
     throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(XmlObjectSerializer.CreateSerializationException(SR.GetString(SR.QueryGeneratorPathToMemberNotFound)));
 }
开发者ID:krytht,项目名称:DotNetReferenceSource,代码行数:13,代码来源:XPathQueryGenerator.cs

示例10: CheckDuplicateNames

 private static void CheckDuplicateNames(ClassDataContract dataContract)
 {
     if (dataContract.MemberNames != null)
     {
         Dictionary<string, object> memberTable = new Dictionary<string, object>();
         for (int i = 0; i < dataContract.MemberNames.Length; i++)
         {
             if (memberTable.ContainsKey(dataContract.MemberNames[i].Value))
             {
                 throw new SerializationException(SR.Format(SR.JsonDuplicateMemberInInput, dataContract.MemberNames[i].Value));
             }
             memberTable.Add(dataContract.MemberNames[i].Value, null);
         }
     }
 }
开发者ID:er0dr1guez,项目名称:corefx,代码行数:15,代码来源:ObjectToDataContractConverterHelper.cs

示例11: ReadClassDataContractMembers

        private static void ReadClassDataContractMembers(DataContractJsonSerializer serializer, ClassDataContract dataContract, Dictionary<string, object> deserialzedValue, object newInstance, XmlObjectSerializerReadContextComplexJson context)
        {
            if (dataContract.BaseContract != null)
            {
                ReadClassDataContractMembers(serializer, dataContract.BaseContract, deserialzedValue, newInstance, context);
            }
            for (int i = 0; i < dataContract.Members.Count; i++)
            {
                DataMember member = dataContract.Members[i];
                object currentMemberValue;
                if (deserialzedValue.TryGetValue(XmlConvert.DecodeName(dataContract.Members[i].Name), out currentMemberValue) ||
                    dataContract.IsKeyValuePairAdapter && deserialzedValue.TryGetValue(XmlConvert.DecodeName(dataContract.Members[i].Name.ToLowerInvariant()), out currentMemberValue))
                {
                    if (member.MemberType.GetTypeInfo().IsPrimitive || currentMemberValue == null)
                    {
                        SetMemberValue(newInstance, serializer.ConvertObjectToDataContract(member.MemberTypeContract, currentMemberValue, context), dataContract.Members[i].MemberInfo, dataContract.UnderlyingType);
                    }
                    else
                    {
                        context.PushKnownTypes(dataContract);
                        object subMemberValue = serializer.ConvertObjectToDataContract(member.MemberTypeContract, currentMemberValue, context);
                        Type declaredType = (member.MemberType.GetTypeInfo().IsGenericType && member.MemberType.GetGenericTypeDefinition() == Globals.TypeOfNullable)
                            ? Nullable.GetUnderlyingType(member.MemberType)
                            : member.MemberType;

                        if (!(declaredType == Globals.TypeOfObject && subMemberValue.GetType() == Globals.TypeOfObjectArray) && declaredType != subMemberValue.GetType())
                        {
                            DataContract memberValueContract = DataContract.GetDataContract(subMemberValue.GetType());
                            context.CheckIfTypeNeedsVerifcation(member.MemberTypeContract, memberValueContract);
                        }

                        if (member.IsGetOnlyCollection)
                        {
                            PopulateReadOnlyCollection(newInstance, member, (IEnumerable)subMemberValue);
                        }
                        else
                        {
                            SetMemberValue(newInstance, subMemberValue, dataContract.Members[i].MemberInfo, dataContract.UnderlyingType);
                        }
                        context.PopKnownTypes(dataContract);
                    }
                }
                else if (member.IsRequired)
                {
                    XmlObjectSerializerWriteContext.ThrowRequiredMemberMustBeEmitted(dataContract.MemberNames[i].Value, dataContract.UnderlyingType);
                }
            }
        }
开发者ID:er0dr1guez,项目名称:corefx,代码行数:48,代码来源:ObjectToDataContractConverterHelper.cs

示例12: ReflectionInitArgs

        private void ReflectionInitArgs(XmlWriterDelegator xmlWriter, object obj, XmlObjectSerializerWriteContext context, ClassDataContract classContract)
        {
            if (obj.GetType() == typeof(DateTimeOffset))
            {
                obj = DateTimeOffsetAdapter.GetDateTimeOffsetAdapter((DateTimeOffset)obj);
            }
            else if (obj.GetType().GetTypeInfo().IsGenericType && obj.GetType().GetGenericTypeDefinition() == typeof(KeyValuePair<,>))
            {
                obj = classContract.KeyValuePairAdapterConstructorInfo.Invoke(new object[] { obj });
            }

            _arg0XmlWriter = xmlWriter;
            _arg1Object = obj;
            _arg2Context = context;
            _arg3ClassDataContract = classContract;
        }
开发者ID:SGuyGe,项目名称:corefx,代码行数:16,代码来源:ReflectionXmlFormatWriter.cs

示例13: ProcessClassDataContract

 private static DataContract ProcessClassDataContract(ClassDataContract contract, ExportContext context, MemberInfo memberNode)
 {
     string prefix = context.SetNamespace(contract.Namespace.Value);
     if (contract.Members != null)
     {
         foreach (DataMember member in contract.Members)
         {
             if (member.MemberInfo == memberNode)
             {
                 context.WriteChildToContext(member, prefix);
                 return member.MemberTypeContract;
             }
         }
     }
     throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(XmlObjectSerializer.CreateSerializationException(System.Runtime.Serialization.SR.GetString("QueryGeneratorPathToMemberNotFound")));
 }
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:16,代码来源:XPathQueryGenerator.cs

示例14: GetDataMembers

 static IEnumerable<DataMember> GetDataMembers(ClassDataContract contract)
 {
     if (contract.BaseContract != null)
     {
         foreach (DataMember baseClassMember in GetDataMembers(contract.BaseContract))
         {
             yield return baseClassMember;
         }
     }
     if (contract.Members != null)
     {
         foreach (DataMember member in contract.Members)
         {
             yield return member;
         }
     }
 }
开发者ID:krytht,项目名称:DotNetReferenceSource,代码行数:17,代码来源:XPathQueryGenerator.cs

示例15: GenerateClassWriter

        internal JsonFormatClassWriterDelegate GenerateClassWriter(ClassDataContract classContract)
        {
            try
            {
                if (TD.DCJsonGenWriterStartIsEnabled())
                {
                    TD.DCJsonGenWriterStart("Class", classContract.UnderlyingType.FullName);
                }

                return helper.GenerateClassWriter(classContract);
            }
            finally
            {
                if (TD.DCJsonGenWriterStopIsEnabled())
                {
                    TD.DCJsonGenWriterStop();
                }
            }
        }
开发者ID:nlh774,项目名称:DotNetReferenceSource,代码行数:19,代码来源:JsonFormatWriterGenerator.cs


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