protected override void CacheMetadata(CodeActivityMetadata metadata) { MethodInfo oldGetMethod = this.getMethod; MethodInfo oldSetMethod = this.setMethod; if (!typeof(TOperand).IsValueType) { metadata.AddValidationError(SR.TypeMustbeValueType(typeof(TOperand).Name)); } if (typeof(TOperand).IsEnum) { metadata.AddValidationError(SR.TargetTypeCannotBeEnum(this.GetType().Name, this.DisplayName)); } else if (String.IsNullOrEmpty(this.PropertyName)) { metadata.AddValidationError(SR.ActivityPropertyMustBeSet("PropertyName", this.DisplayName)); } else { this.propertyInfo = typeof(TOperand).GetProperty(this.PropertyName); if (this.propertyInfo == null) { metadata.AddValidationError(SR.MemberNotFound(PropertyName, typeof(TOperand).Name)); } } bool isRequired = false; if (this.propertyInfo != null) { this.setMethod = this.propertyInfo.GetSetMethod(); this.getMethod = this.propertyInfo.GetGetMethod(); if (setMethod == null) { metadata.AddValidationError(SR.MemberIsReadOnly(propertyInfo.Name, typeof(TOperand))); } if (setMethod != null && !setMethod.IsStatic) { isRequired = true; } } MemberExpressionHelper.AddOperandLocationArgument <TOperand>(metadata, this.OperandLocation, isRequired); if (this.propertyInfo != null) { if (MethodCallExpressionHelper.NeedRetrieve(this.getMethod, oldGetMethod, this.getFunc)) { this.getFunc = MethodCallExpressionHelper.GetFunc(metadata, this.getMethod, funcCache, locker); } if (MethodCallExpressionHelper.NeedRetrieve(this.setMethod, oldSetMethod, this.setFunc)) { this.setFunc = MethodCallExpressionHelper.GetFunc(metadata, this.setMethod, funcCache, locker, true); } } }
/// <summary> /// Caches the metadata. /// </summary> /// <param name="metadata">The metadata.</param> protected override void CacheMetadata(CodeActivityMetadata metadata) { var oldGetMethod = this.getMethod; var oldSetMethod = this.setMethod; if (typeof(TOperand).IsValueType) { metadata.AddValidationError(SR.TargetTypeIsValueType(this.GetType().Name, this.DisplayName)); } if (this.Indices.Count == 0) { metadata.AddValidationError(SR.IndicesAreNeeded(this.GetType().Name, this.DisplayName)); } else { IndexerHelper.CacheMethod <TOperand, TItem>(this.Indices, ref this.getMethod, ref this.setMethod); if (this.setMethod == null) { metadata.AddValidationError(SR.SpecialMethodNotFound("set_Item", typeof(TOperand).Name)); } } var operandArgument = new RuntimeArgument("Operand", typeof(TOperand), ArgumentDirection.In, true); metadata.Bind(this.Operand, operandArgument); metadata.AddArgument(operandArgument); IndexerHelper.OnGetArguments(this.Indices, this.Result, metadata); if (MethodCallExpressionHelper.NeedRetrieve(this.getMethod, oldGetMethod, this.getFunc)) { this.getFunc = MethodCallExpressionHelper.GetFunc(metadata, this.getMethod, funcCache, locker); } if (MethodCallExpressionHelper.NeedRetrieve(this.setMethod, oldSetMethod, this.setFunc)) { this.setFunc = MethodCallExpressionHelper.GetFunc(metadata, this.setMethod, funcCache, locker); } }
protected override void CacheMetadata(CodeActivityMetadata metadata) { MethodInfo oldGetMethod = this.getMethod; MethodInfo oldSetMethod = this.setMethod; bool isRequired = false; if (typeof(TOperand).IsEnum) { metadata.AddValidationError(SR.TargetTypeCannotBeEnum(this.GetType().Name, this.DisplayName)); } else if (typeof(TOperand).IsValueType) { metadata.AddValidationError(SR.TargetTypeIsValueType(this.GetType().Name, this.DisplayName)); } if (string.IsNullOrEmpty(this.PropertyName)) { metadata.AddValidationError(SR.ActivityPropertyMustBeSet("PropertyName", this.DisplayName)); } else { Type operandType = typeof(TOperand); this.propertyInfo = operandType.GetProperty(this.PropertyName); if (this.propertyInfo == null) { metadata.AddValidationError(SR.MemberNotFound(PropertyName, typeof(TOperand).Name)); } else { getMethod = this.propertyInfo.GetGetMethod(); setMethod = this.propertyInfo.GetSetMethod(); // Only allow access to public properties, EXCEPT that Locations are top-level variables // from the other's perspective, not internal properties, so they're okay as a special case. // E.g. "[N]" from the user's perspective is not accessing a nonpublic property, even though // at an implementation level it is. if (setMethod == null && TypeHelper.AreTypesCompatible(this.propertyInfo.DeclaringType, typeof(Location)) == false) { metadata.AddValidationError(SR.ReadonlyPropertyCannotBeSet(this.propertyInfo.DeclaringType, this.propertyInfo.Name)); } if ((getMethod != null && !getMethod.IsStatic) || (setMethod != null && !setMethod.IsStatic)) { isRequired = true; } } } MemberExpressionHelper.AddOperandArgument(metadata, this.Operand, isRequired); if (propertyInfo != null) { if (MethodCallExpressionHelper.NeedRetrieve(this.getMethod, oldGetMethod, this.getFunc)) { this.getFunc = MethodCallExpressionHelper.GetFunc(metadata, this.getMethod, funcCache, locker); } if (MethodCallExpressionHelper.NeedRetrieve(this.setMethod, oldSetMethod, this.setFunc)) { this.setFunc = MethodCallExpressionHelper.GetFunc(metadata, this.setMethod, funcCache, locker); } } }