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


C# TypeInfo.GetMember方法代码示例

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


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

示例1: Read

	public bool Read(DeserializationContext context, out Object outVal, uint id, TypeInfo typeInfo) 
	{
		bool ret = true;

    	// create instance
   		Object obj = null;
        SerializationInfo info = null;
	    
        if(typeInfo.IsISerializable)
        {
            info = typeInfo.GetSerializationInfo();

	    	// create instance
    		obj = FormatterServices.GetUninitializedObject(typeInfo.ObjectType);

	    	// read and set values
    		for(uint i = 0; i < typeInfo.NumMembers; i++) 
		    {
	    		// first get inlined data
    			Object memberValue;
			    if(typeInfo.GetTypeTag(i) == BinaryTypeTag.PrimitiveType) 
		    	{
	    			memberValue = ReadPrimitiveType(context, typeInfo.GetTypeSpecification(i).GetPrimitiveType());
    			} 
			    else 
		    	{
	    			ret &= ReadValue(context, out memberValue);
    			}

    			// set value
			    String field = typeInfo.GetFieldName(i);
		    	if(memberValue is DelayedReferenceHolder) 
	    		{
    				// this is a reference
				    DelayedReferenceHolder holder = (DelayedReferenceHolder) memberValue;
			    	context.Manager.RecordDelayedFixup(id, field, holder.ReferenceId);
		    	}
	    		else 
    			{
    		    	// this is a real value
	    	        info.AddValue(field, memberValue, typeInfo.GetTypeSpecification(i).GetObjectType(context));
	    		}
    		}
    		context.Manager.RegisterObject(obj, id, info);
        }
        else
        {
	    	// create instance
    		obj = FormatterServices.GetUninitializedObject(typeInfo.ObjectType);

	    	// read and set values
    		for(uint i = 0; i < typeInfo.NumMembers; i++) 
		    {
	    		// first get inlined data
    			Object memberValue;
			    if(typeInfo.GetTypeTag(i) == BinaryTypeTag.PrimitiveType) 
		    	{
	    			memberValue = ReadPrimitiveType(context, typeInfo.GetTypeSpecification(i).GetPrimitiveType());
    			} 
			    else 
		    	{
	    			ret &= ReadValue(context, out memberValue);
    			}

    			// set value
			    MemberInfo field = typeInfo.GetMember(i);
		    	if(memberValue is DelayedReferenceHolder) 
	    		{
    				// this is a reference
				    DelayedReferenceHolder holder = (DelayedReferenceHolder) memberValue;
			    	context.Manager.RecordFixup(id, field, holder.ReferenceId);
		    	} 
	    		else 
    			{
		    		// this is a real value
	    			if(field is FieldInfo) 
    				{
			    		FieldInfo fi = (FieldInfo) field;
		    			fi.SetValue(obj, memberValue);
	    			}
    					// TODO: i'm not sure if I have to cover that case, too!
					    // I just noticed that Mono does this
				    	//				else if(field is PropertyInfo)
			    		//				{
		    			//					PropertyInfo pi = (PropertyInfo) field;
	    				//					pi.SetValue();
    				else 
				    {
			    		throw new SerializationException("unknown memeber type:"+field.GetType());
		    		}
	    		}
    		}
    		context.Manager.RegisterObject(obj, id);
        }
		outVal = obj;
		return ret;
	}
开发者ID:jjenki11,项目名称:blaze-chem-rendering,代码行数:97,代码来源:BinaryValueReader.cs


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