System.Runtime.Serialization.CodeGenerator.LoadMember C# (CSharp) Method

LoadMember() private method

private LoadMember ( MemberInfo memberInfo ) : Type
memberInfo MemberInfo
return System.Type
        internal Type LoadMember(MemberInfo memberInfo)
        {
            Type memberType = null;
            if (memberInfo is FieldInfo)
            {
                FieldInfo fieldInfo = (FieldInfo)memberInfo;
                memberType = fieldInfo.FieldType;
                if (fieldInfo.IsStatic)
                {
                    if (_codeGenTrace != CodeGenTrace.None)
                        EmitSourceInstruction("Ldsfld " + fieldInfo + " on type " + fieldInfo.DeclaringType);
                    _ilGen.Emit(OpCodes.Ldsfld, fieldInfo);
                }
                else
                {
                    if (_codeGenTrace != CodeGenTrace.None)
                        EmitSourceInstruction("Ldfld " + fieldInfo + " on type " + fieldInfo.DeclaringType);
                    _ilGen.Emit(OpCodes.Ldfld, fieldInfo);
                }
            }
            else if (memberInfo is PropertyInfo)
            {
                PropertyInfo property = memberInfo as PropertyInfo;
                memberType = property.PropertyType;
                if (property != null)
                {
                    MethodInfo getMethod = property.GetMethod;
                    if (getMethod == null)
                        throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperError(XmlObjectSerializer.CreateSerializationException(SR.Format(SR.NoGetMethodForProperty, property.DeclaringType, property)));
                    Call(getMethod);
                }
            }
            else if (memberInfo is MethodInfo)
            {
                MethodInfo method = (MethodInfo)memberInfo;
                memberType = method.ReturnType;
                Call(method);
            }
            else
                throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperError(XmlObjectSerializer.CreateSerializationException(SR.Format(SR.CannotLoadMemberType, "Unknown", memberInfo.DeclaringType, memberInfo.Name)));

            EmitStackTop(memberType);
            return memberType;
        }

Usage Example

コード例 #1
0
 private void ThrowIfCannotSerializeReadOnlyTypes(PropertyInfo serializationExceptionMessageProperty)
 {
     _ilg.Load(_contextArg);
     _ilg.LoadMember(XmlFormatGeneratorStatics.SerializeReadOnlyTypesProperty);
     _ilg.IfNot();
     _ilg.Load(_dataContractArg);
     _ilg.LoadMember(serializationExceptionMessageProperty);
     _ilg.Load(null);
     _ilg.Call(XmlFormatGeneratorStatics.ThrowInvalidDataContractExceptionMethod);
     _ilg.EndIf();
 }
All Usage Examples Of System.Runtime.Serialization.CodeGenerator::LoadMember