Code:
/ 4.0 / 4.0 / untmp / DEVDIV_TFS / Dev10 / Releases / RTMRel / ndp / cdf / src / NetFx40 / System.Activities / System / Activities / Expressions / NewArray.cs / 1305376 / NewArray.cs
//---------------------------------------------------------------- // Copyright (c) Microsoft Corporation. All rights reserved. //--------------------------------------------------------------- namespace System.Activities.Expressions { using System.Activities; using System.Collections.ObjectModel; using System.Reflection; using System.Runtime.Collections; using System.Windows.Markup; [ContentProperty("Bounds")] public sealed class NewArray: CodeActivity { Collection bounds; ConstructorInfo constructorInfo; public Collection Bounds { get { if (this.bounds == null) { this.bounds = new ValidatingCollection { // disallow null values OnAddValidationCallback = item => { if (item == null) { throw FxTrace.Exception.ArgumentNull("item"); } } }; } return this.bounds; } } protected override void CacheMetadata(CodeActivityMetadata metadata) { if (!typeof(TResult).IsArray) { metadata.AddValidationError(SR.NewArrayRequiresArrayTypeAsResultType); // We shortcut any further processing in this case. return; } bool foundError = false; // Loop through each argument, validate it, and if validation // passed expose it to the metadata Type[] types = new Type[this.Bounds.Count]; for (int i = 0; i < this.Bounds.Count; i++) { Argument argument = this.Bounds[i]; if (argument == null || argument.IsEmpty) { metadata.AddValidationError(SR.ArgumentRequired("Bounds", typeof(NewArray ))); foundError = true; } else { if (!isIntegralType(argument.ArgumentType)) { metadata.AddValidationError(SR.NewArrayBoundsRequiresIntegralArguments); foundError = true; } else { RuntimeArgument runtimeArgument = new RuntimeArgument("Argument" + i, this.Bounds[i].ArgumentType, this.bounds[i].Direction, true); metadata.Bind(this.Bounds[i], runtimeArgument); metadata.AddArgument(runtimeArgument); types[i] = argument.ArgumentType; } } } // If we didn't find any errors in the arguments then // we can look for an appropriate constructor. if (!foundError) { this.constructorInfo = typeof(TResult).GetConstructor(types); if (this.constructorInfo == null) { metadata.AddValidationError(SR.ConstructorInfoNotFound(typeof(TResult).Name)); } } } protected override TResult Execute(CodeActivityContext context) { object[] objects = new object[this.Bounds.Count]; int i = 0; foreach (Argument argument in this.Bounds) { objects[i] = argument.Get(context); i++; } TResult result = (TResult)this.constructorInfo.Invoke(objects); return result; } bool isIntegralType(Type type) { if (type == typeof(sbyte) || type == typeof(byte) || type == typeof(char) || type == typeof(short) || type == typeof(ushort) || type == typeof(int) || type == typeof(uint) || type == typeof(long) || type == typeof(ulong)) { return true; } else { return false; } } } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007.
Link Menu

This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- TaskFormBase.cs
- DbConnectionPoolGroup.cs
- InvalidComObjectException.cs
- Executor.cs
- FontWeight.cs
- FixedPage.cs
- CodeLabeledStatement.cs
- GridViewCancelEditEventArgs.cs
- CodeRegionDirective.cs
- OptimalBreakSession.cs
- ClientFormsAuthenticationCredentials.cs
- ThemeableAttribute.cs
- Random.cs
- Compiler.cs
- ExpressionBuilder.cs
- TextDecorationCollectionConverter.cs
- DrawingDrawingContext.cs
- MissingSatelliteAssemblyException.cs
- AppDomainProtocolHandler.cs
- GridViewCommandEventArgs.cs
- Environment.cs
- ScriptHandlerFactory.cs
- SqlDataSourceFilteringEventArgs.cs
- AttributeAction.cs
- PeerSecurityManager.cs
- KeyProperty.cs
- BindingContext.cs
- SqlConnectionManager.cs
- HttpWrapper.cs
- NotifyParentPropertyAttribute.cs
- MouseDevice.cs
- RegionData.cs
- SwitchElementsCollection.cs
- FilterElement.cs
- GreenMethods.cs
- ApplicationSecurityManager.cs
- ComponentResourceKeyConverter.cs
- Typography.cs
- querybuilder.cs
- Expr.cs
- ImageUrlEditor.cs
- InheritedPropertyChangedEventArgs.cs
- NodeLabelEditEvent.cs
- BuiltInPermissionSets.cs
- TouchDevice.cs
- HttpModuleCollection.cs
- ApplicationActivator.cs
- MachineKeyConverter.cs
- MetafileHeaderEmf.cs
- LogPolicy.cs
- ObjectParameter.cs
- SchemaSetCompiler.cs
- Positioning.cs
- SessionStateItemCollection.cs
- XmlUtf8RawTextWriter.cs
- ResolveDuplexAsyncResult.cs
- PersonalizationAdministration.cs
- RawContentTypeMapper.cs
- Byte.cs
- DispatchOperationRuntime.cs
- HelpProvider.cs
- CheckBoxPopupAdapter.cs
- SweepDirectionValidation.cs
- TitleStyle.cs
- ReplyAdapterChannelListener.cs
- RecipientInfo.cs
- MemberInitExpression.cs
- Vector3DAnimationUsingKeyFrames.cs
- ToolStripPanelRow.cs
- SuppressIldasmAttribute.cs
- AxisAngleRotation3D.cs
- SqlUserDefinedTypeAttribute.cs
- HwndKeyboardInputProvider.cs
- CodeNamespace.cs
- WebWorkflowRole.cs
- AdCreatedEventArgs.cs
- ConstraintConverter.cs
- DataGridViewAccessibleObject.cs
- ExtensionFile.cs
- CssStyleCollection.cs
- MaskedTextBoxTextEditorDropDown.cs
- ClockController.cs
- Region.cs
- SamlAuthenticationStatement.cs
- ValueConversionAttribute.cs
- ListenerConfig.cs
- FormClosedEvent.cs
- ActivityXamlServices.cs
- Speller.cs
- FixedTextPointer.cs
- LinqToSqlWrapper.cs
- EntityDataSourceSelectedEventArgs.cs
- XmlSchemaElement.cs
- UnsafeNetInfoNativeMethods.cs
- coordinatorfactory.cs
- CapabilitiesAssignment.cs
- TriggerActionCollection.cs
- ToolStripGrip.cs
- StateDesigner.TransitionInfo.cs
- OdbcPermission.cs