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
- ToolStripComboBox.cs
- CheckBoxRenderer.cs
- RtfToXamlReader.cs
- FrameworkReadOnlyPropertyMetadata.cs
- SqlXmlStorage.cs
- TransactionOptions.cs
- StartUpEventArgs.cs
- ThicknessAnimationUsingKeyFrames.cs
- ContentPosition.cs
- HMACSHA256.cs
- ObjectDataSourceChooseMethodsPanel.cs
- OdbcHandle.cs
- Label.cs
- OracleRowUpdatedEventArgs.cs
- UserNameSecurityToken.cs
- EditingCoordinator.cs
- ImageDrawing.cs
- Math.cs
- FormatStringEditor.cs
- OracleParameterCollection.cs
- RepeatButton.cs
- DataGridViewCellParsingEventArgs.cs
- OdbcException.cs
- ProjectionCamera.cs
- GridViewRowPresenter.cs
- MimeBasePart.cs
- SmtpTransport.cs
- DefaultShape.cs
- Stylus.cs
- WorkflowDefinitionDispenser.cs
- SystemIPv6InterfaceProperties.cs
- PageMediaSize.cs
- UpdatableGenericsFeature.cs
- PrintingPermissionAttribute.cs
- EmptyControlCollection.cs
- StaticTextPointer.cs
- QueryResponse.cs
- BamlRecordHelper.cs
- PageThemeParser.cs
- HtmlImage.cs
- RemoteWebConfigurationHostServer.cs
- BaseContextMenu.cs
- DataControlPagerLinkButton.cs
- TreeWalkHelper.cs
- VideoDrawing.cs
- UIElement3DAutomationPeer.cs
- RecognizedWordUnit.cs
- XamlTemplateSerializer.cs
- WsatStrings.cs
- ZipIOExtraFieldElement.cs
- SiteMapNodeItemEventArgs.cs
- DataBinding.cs
- wmiprovider.cs
- ClickablePoint.cs
- InvokeProviderWrapper.cs
- OutArgument.cs
- AnimatedTypeHelpers.cs
- PointValueSerializer.cs
- ClrPerspective.cs
- CheckBoxDesigner.cs
- WebContext.cs
- ConnectionStringEditor.cs
- ExecutionContext.cs
- ServiceNameElementCollection.cs
- SqlProviderManifest.cs
- Page.cs
- ActivityDesignerLayoutSerializers.cs
- DataSourceDescriptorCollection.cs
- DataFormats.cs
- SoapFormatExtensions.cs
- SmiEventSink_DeferedProcessing.cs
- DataGridViewSelectedCellsAccessibleObject.cs
- OleAutBinder.cs
- DataGridViewSortCompareEventArgs.cs
- AppLevelCompilationSectionCache.cs
- SoapEnumAttribute.cs
- TreeNode.cs
- util.cs
- InvalidPrinterException.cs
- CustomExpressionEventArgs.cs
- OrthographicCamera.cs
- DataGridTextBox.cs
- StateRuntime.cs
- SafeArchiveContext.cs
- FileSystemEnumerable.cs
- HostingPreferredMapPath.cs
- NetStream.cs
- Animatable.cs
- RijndaelManagedTransform.cs
- BoundsDrawingContextWalker.cs
- ReadOnlyAttribute.cs
- DataServiceExpressionVisitor.cs
- Crc32.cs
- ToolboxItemAttribute.cs
- RichTextBox.cs
- Frame.cs
- FileInfo.cs
- EngineSite.cs
- CodeTypeConstructor.cs
- HttpCacheParams.cs