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


C# DataType.ToActualType方法代码示例

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


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

示例1: ReadMemberInfo


//.........这里部分代码省略.........
						string[] paramTypeStrings = new string[paramCount];
						for (int i = 0; i < paramCount; i++)
							paramTypeStrings[i] = this.reader.ReadString();

						Type declaringType = this.ResolveType(declaringTypeString);
						Type propertyType = this.ResolveType(propertyTypeString);
						Type[] paramTypes = new Type[paramCount];
						for (int i = 0; i < paramCount; i++)
							paramTypes[i] = this.ResolveType(paramTypeStrings[i]);

						PropertyInfo property = declaringType.GetProperty(
							propertyName, 
							isStatic ? ReflectionHelper.BindStaticAll : ReflectionHelper.BindInstanceAll, 
							null, 
							propertyType, 
							paramTypes, 
							null);

						result = property;
					}
					else if (dataType == DataType.MethodInfo)
					{
						bool isStatic = this.reader.ReadBoolean();
						string declaringTypeString = this.reader.ReadString();
						string methodName = this.reader.ReadString();

						int paramCount = this.reader.ReadInt32();
						string[] paramTypeStrings = new string[paramCount];
						for (int i = 0; i < paramCount; i++)
							paramTypeStrings[i] = this.reader.ReadString();

						Type declaringType = this.ResolveType(declaringTypeString);
						Type[] paramTypes = new Type[paramCount];
						for (int i = 0; i < paramCount; i++)
							paramTypes[i] = this.ResolveType(paramTypeStrings[i]);

						MethodInfo method = declaringType.GetMethod(methodName, isStatic ? ReflectionHelper.BindStaticAll : ReflectionHelper.BindInstanceAll, null, paramTypes, null);
						result = method;
					}
					else if (dataType == DataType.ConstructorInfo)
					{
						bool isStatic = this.reader.ReadBoolean();
						string declaringTypeString = this.reader.ReadString();

						int paramCount = this.reader.ReadInt32();
						string[] paramTypeStrings = new string[paramCount];
						for (int i = 0; i < paramCount; i++)
							paramTypeStrings[i] = this.reader.ReadString();

						Type declaringType = this.ResolveType(declaringTypeString);
						Type[] paramTypes = new Type[paramCount];
						for (int i = 0; i < paramCount; i++)
							paramTypes[i] = this.ResolveType(paramTypeStrings[i]);

						ConstructorInfo method = declaringType.GetConstructor(isStatic ? ReflectionHelper.BindStaticAll : ReflectionHelper.BindInstanceAll, null, paramTypes, null);
						result = method;
					}
					else if (dataType == DataType.EventInfo)
					{
						bool isStatic = this.reader.ReadBoolean();
						string declaringTypeString = this.reader.ReadString();
						string eventName = this.reader.ReadString();

						Type declaringType = this.ResolveType(declaringTypeString);
						EventInfo e = declaringType.GetEvent(eventName, isStatic ? ReflectionHelper.BindStaticAll : ReflectionHelper.BindInstanceAll);
						result = e;
					}
					else
						throw new ApplicationException(string.Format("Invalid DataType '{0}' in ReadMemberInfo method.", dataType));
				}
				#endregion
				else if (this.dataVersion >= 2)
				{
					if (dataType == DataType.Type)
					{
						string typeString = this.reader.ReadString();
						result = this.ResolveType(typeString, objId);
					}
					else
					{
						string memberString = this.reader.ReadString();
						result = this.ResolveMember(memberString, objId);
					}
				}
			}
			catch (Exception e)
			{
				result = null;
				this.SerializationLog.WriteError(
					"An error occurred in deserializing MemberInfo object Id {0} of type '{1}': {2}",
					objId,
					Log.Type(dataType.ToActualType()),
					Log.Exception(e));
			}
			
			// Prepare object reference
			this.idManager.Inject(result, objId);

			return result;
		}
开发者ID:Banbury,项目名称:duality,代码行数:101,代码来源:BinaryFormatter.cs

示例2: ReadMemberInfo

        /// <summary>
        /// Reads a <see cref="System.Reflection.MemberInfo"/>, including referenced objects.
        /// </summary>
        /// <param name="dataType">The <see cref="Duality.Serialization.DataType"/> of the object to read.</param>
        /// <returns>The object that has been read.</returns>
        protected MemberInfo ReadMemberInfo(DataType dataType)
        {
            string	objIdString		= this.reader.GetAttribute("id");
            uint	objId			= objIdString == null ? 0 : XmlConvert.ToUInt32(objIdString);
            MemberInfo result;

            try
            {
                if (dataType == DataType.Type)
                {
                    string typeString = this.reader.GetAttribute("value");
                    result = this.ResolveType(typeString, objId);
                }
                else
                {
                    string memberString = this.reader.GetAttribute("value");
                    result = this.ResolveMember(memberString, objId);
                }
            }
            catch (Exception e)
            {
                result = null;
                this.SerializationLog.WriteError(
                    "An error occurred in deserializing MemberInfo object Id {0} of type '{1}': {2}",
                    objId,
                    Log.Type(dataType.ToActualType()),
                    Log.Exception(e));
            }

            // Prepare object reference
            this.idManager.Inject(result, objId);

            return result;
        }
开发者ID:hbcameleon,项目名称:duality,代码行数:39,代码来源:XmlFormatter.cs


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