public void CtorTest() { ConstructorArgumentAttribute attr = new ConstructorArgumentAttribute("argName"); Assert.AreEqual("argName", attr.ArgumentName); attr = new ConstructorArgumentAttribute(null); Assert.IsNull(attr.ArgumentName); }
internal override IEnumerable <MarkupProperty> GetProperties(bool mapToConstructorArgs) { ValueSerializer valueSerializer = ValueSerializer.GetSerializerFor(ObjectType, Context); if (valueSerializer != null && valueSerializer.CanConvertToString(_instance, Context)) { yield return(new ElementStringValueProperty(this)); if (_key != null) { yield return(_key); } } else { Dictionary <string, string> constructorArguments = null; // if this markup item is the value of property in attribute form and the instance // it represents is a MarkupExtension, then we return any properties that are // constructor arguments as ElementConstructorArgument markup properties if (mapToConstructorArgs && _instance is MarkupExtension) { ParameterInfo[] parameters; ICollection arguments; if (TryGetConstructorInfoArguments(_instance, out parameters, out arguments)) { int i = 0; foreach (object value in arguments) { if (constructorArguments == null) { constructorArguments = new Dictionary <string, string>(); } // store a list of the parameters that are constructor arguments // so that we don't return those properties again constructorArguments.Add(parameters[i].Name, parameters[i].Name); yield return(new ElementConstructorArgument(value, parameters[i++].ParameterType, this)); } } } foreach (PropertyDescriptor descriptor in TypeDescriptor.GetProperties(_instance)) { DesignerSerializationVisibility visibility = descriptor.SerializationVisibility; if (visibility != DesignerSerializationVisibility.Hidden && (!descriptor.IsReadOnly || visibility == DesignerSerializationVisibility.Content) && ShouldSerialize(descriptor, _instance, _manager)) { if (visibility == DesignerSerializationVisibility.Content) { // Ensure the collection has content object value = descriptor.GetValue(_instance); if (value == null) { continue; } else { ICollection collection = value as ICollection; if (collection != null && collection.Count < 1) { continue; } IEnumerable enumerable = value as IEnumerable; if (enumerable != null && !enumerable.GetEnumerator().MoveNext()) { continue; } } } if (constructorArguments != null) { ConstructorArgumentAttribute constructorArgumentAttribute = descriptor.Attributes[typeof(ConstructorArgumentAttribute)] as ConstructorArgumentAttribute; if (constructorArgumentAttribute != null && constructorArguments.ContainsKey(constructorArgumentAttribute.ArgumentName)) { // Skip this property, it has already been represented by a constructor parameter continue; } } yield return(new ElementProperty(this, descriptor)); } } IDictionary dictionary = _instance as IDictionary; if (dictionary != null) { yield return(new ElementDictionaryItemsPseudoProperty(dictionary, typeof(IDictionary), this)); } else { IEnumerable enumerable = _instance as IEnumerable; if (enumerable != null && enumerable.GetEnumerator().MoveNext()) { yield return(new ElementItemsPseudoProperty(enumerable, typeof(IEnumerable), this)); } } if (_key != null) { yield return(_key); } } }
// Token: 0x0600240C RID: 9228 RVA: 0x000AFC1A File Offset: 0x000ADE1A internal override IEnumerable <MarkupProperty> GetProperties(bool mapToConstructorArgs) { ValueSerializer serializerFor = ValueSerializer.GetSerializerFor(this.ObjectType, this.Context); if (serializerFor != null && serializerFor.CanConvertToString(this._instance, this.Context)) { yield return(new ElementStringValueProperty(this)); if (this._key != null) { yield return(this._key); } } else { Dictionary <string, string> constructorArguments = null; IEnumerator enumerator; if (mapToConstructorArgs && this._instance is MarkupExtension) { ParameterInfo[] parameters; ICollection collection; if (this.TryGetConstructorInfoArguments(this._instance, out parameters, out collection)) { int i = 0; foreach (object obj in collection) { if (constructorArguments == null) { constructorArguments = new Dictionary <string, string>(); } constructorArguments.Add(parameters[i].Name, parameters[i].Name); object value = obj; ParameterInfo[] array = parameters; int num = i; i = num + 1; yield return(new ElementConstructorArgument(value, array[num].ParameterType, this)); } enumerator = null; } parameters = null; } foreach (object obj2 in TypeDescriptor.GetProperties(this._instance)) { PropertyDescriptor propertyDescriptor = (PropertyDescriptor)obj2; DesignerSerializationVisibility serializationVisibility = propertyDescriptor.SerializationVisibility; if (serializationVisibility != DesignerSerializationVisibility.Hidden && (!propertyDescriptor.IsReadOnly || serializationVisibility == DesignerSerializationVisibility.Content) && ElementMarkupObject.ShouldSerialize(propertyDescriptor, this._instance, this._manager)) { if (serializationVisibility == DesignerSerializationVisibility.Content) { object value2 = propertyDescriptor.GetValue(this._instance); if (value2 == null) { continue; } ICollection collection2 = value2 as ICollection; if (collection2 != null && collection2.Count < 1) { continue; } IEnumerable enumerable = value2 as IEnumerable; if (enumerable != null && !enumerable.GetEnumerator().MoveNext()) { continue; } } if (constructorArguments != null) { ConstructorArgumentAttribute constructorArgumentAttribute = propertyDescriptor.Attributes[typeof(ConstructorArgumentAttribute)] as ConstructorArgumentAttribute; if (constructorArgumentAttribute != null && constructorArguments.ContainsKey(constructorArgumentAttribute.ArgumentName)) { continue; } } yield return(new ElementProperty(this, propertyDescriptor)); } } enumerator = null; IDictionary dictionary = this._instance as IDictionary; if (dictionary != null) { yield return(new ElementDictionaryItemsPseudoProperty(dictionary, typeof(IDictionary), this)); } else { IEnumerable enumerable2 = this._instance as IEnumerable; if (enumerable2 != null && enumerable2.GetEnumerator().MoveNext()) { yield return(new ElementItemsPseudoProperty(enumerable2, typeof(IEnumerable), this)); } } if (this._key != null) { yield return(this._key); } constructorArguments = null; } yield break; yield break; }