using System; using System.Collections; using System.Reflection; namespace System.ComponentModel.Design.Serialization { /// Provides the information necessary to create an instance of an object. This class cannot be inherited. // Token: 0x0200003C RID: 60 public sealed class InstanceDescriptor { /// Initializes a new instance of the class using the specified member information and arguments. /// The member information for the descriptor. This can be a , , , or . If this is a , , or , it must represent a static member. /// The collection of arguments to pass to the member. This parameter can be null or an empty collection if there are no arguments. The collection can also consist of other instances of . /// /// is of type , , or , and it does not represent a static member. is of type and is not readable. is of type or , and the number of arguments in does not match the signature of is of type and represents a static member. is of type , and the number of arguments in is not zero. // Token: 0x06000294 RID: 660 RVA: 0x000092DC File Offset: 0x000074DC public InstanceDescriptor(MemberInfo member, ICollection arguments) : this(member, arguments, true) { } /// Initializes a new instance of the class using the specified member information, arguments, and value indicating whether the specified information completely describes the instance. /// The member information for the descriptor. This can be a , , , or . If this is a , , or , it must represent a static member. /// The collection of arguments to pass to the member. This parameter can be null or an empty collection if there are no arguments. The collection can also consist of other instances of . /// true if the specified information completely describes the instance; otherwise, false. /// /// is of type , , or , and it does not represent a static member is of type and is not readable. is of type or and the number of arguments in does not match the signature of . is of type and represents a static member is of type , and the number of arguments in is not zero. // Token: 0x06000295 RID: 661 RVA: 0x000092E8 File Offset: 0x000074E8 public InstanceDescriptor(MemberInfo member, ICollection arguments, bool isComplete) { this.isComplete = isComplete; this.ValidateMember(member, arguments); this.member = member; this.arguments = arguments; } // Token: 0x06000296 RID: 662 RVA: 0x00009310 File Offset: 0x00007510 private void ValidateMember(MemberInfo member, ICollection arguments) { if (member == null) { return; } MemberTypes memberType = member.MemberType; switch (memberType) { case MemberTypes.Constructor: { ConstructorInfo constructorInfo = (ConstructorInfo)member; if (arguments == null && constructorInfo.GetParameters().Length != 0) { throw new ArgumentException("Invalid number of arguments for this constructor"); } if (arguments.Count != constructorInfo.GetParameters().Length) { throw new ArgumentException("Invalid number of arguments for this constructor"); } break; } default: if (memberType != MemberTypes.Method) { if (memberType == MemberTypes.Property) { PropertyInfo propertyInfo = (PropertyInfo)member; if (!propertyInfo.CanRead) { throw new ArgumentException("Parameter must be readable"); } MethodInfo getMethod = propertyInfo.GetGetMethod(); if (!getMethod.IsStatic) { throw new ArgumentException("Parameter must be static"); } } } else { MethodInfo methodInfo = (MethodInfo)member; if (!methodInfo.IsStatic) { throw new ArgumentException("InstanceDescriptor only describes static (VB.Net: shared) members", "member"); } if (arguments == null && methodInfo.GetParameters().Length != 0) { throw new ArgumentException("Invalid number of arguments for this method", "arguments"); } if (arguments.Count != methodInfo.GetParameters().Length) { throw new ArgumentException("Invalid number of arguments for this method"); } } break; case MemberTypes.Field: { FieldInfo fieldInfo = (FieldInfo)member; if (!fieldInfo.IsStatic) { throw new ArgumentException("Parameter must be static"); } if (arguments != null && arguments.Count != 0) { throw new ArgumentException("Field members do not take any arguments"); } break; } } } /// Gets the collection of arguments that can be used to reconstruct an instance of the object that this instance descriptor represents. /// An of arguments that can be used to create the object. // Token: 0x170000B9 RID: 185 // (get) Token: 0x06000297 RID: 663 RVA: 0x0000948C File Offset: 0x0000768C public ICollection Arguments { get { if (this.arguments == null) { return new object[0]; } return this.arguments; } } /// Gets a value indicating whether the contents of this completely identify the instance. /// true if the instance is completely described; otherwise, false. // Token: 0x170000BA RID: 186 // (get) Token: 0x06000298 RID: 664 RVA: 0x000094A8 File Offset: 0x000076A8 public bool IsComplete { get { return this.isComplete; } } /// Gets the member information that describes the instance this descriptor is associated with. /// A that describes the instance that this object is associated with. // Token: 0x170000BB RID: 187 // (get) Token: 0x06000299 RID: 665 RVA: 0x000094B0 File Offset: 0x000076B0 public MemberInfo MemberInfo { get { return this.member; } } /// Invokes this instance descriptor and returns the object the descriptor describes. /// The object this instance descriptor describes. // Token: 0x0600029A RID: 666 RVA: 0x000094B8 File Offset: 0x000076B8 public object Invoke() { if (this.member == null) { return null; } object[] array; if (this.arguments == null) { array = new object[0]; } else { array = new object[this.arguments.Count]; this.arguments.CopyTo(array, 0); } MemberTypes memberType = this.member.MemberType; switch (memberType) { case MemberTypes.Constructor: { ConstructorInfo constructorInfo = (ConstructorInfo)this.member; return constructorInfo.Invoke(array); } default: { if (memberType == MemberTypes.Method) { MethodInfo methodInfo = (MethodInfo)this.member; return methodInfo.Invoke(null, array); } if (memberType != MemberTypes.Property) { return null; } PropertyInfo propertyInfo = (PropertyInfo)this.member; return propertyInfo.GetValue(null, array); } case MemberTypes.Field: { FieldInfo fieldInfo = (FieldInfo)this.member; return fieldInfo.GetValue(null); } } } // Token: 0x040000B5 RID: 181 private MemberInfo member; // Token: 0x040000B6 RID: 182 private ICollection arguments; // Token: 0x040000B7 RID: 183 private bool isComplete; } }