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
- DelimitedListTraceListener.cs
- DataSourceCache.cs
- CompositeActivityValidator.cs
- SqlStatistics.cs
- TemplatingOptionsDialog.cs
- DataErrorValidationRule.cs
- XmlSiteMapProvider.cs
- CaseStatementSlot.cs
- OverflowException.cs
- AppSettingsExpressionBuilder.cs
- CachedBitmap.cs
- TablePattern.cs
- BookmarkInfo.cs
- MailAddress.cs
- RtfControlWordInfo.cs
- WindowShowOrOpenTracker.cs
- ColorAnimationBase.cs
- HtmlLink.cs
- ComponentEditorPage.cs
- BypassElement.cs
- DesignTimeVisibleAttribute.cs
- BinaryMethodMessage.cs
- ResolveCriteria.cs
- AngleUtil.cs
- ErrorFormatter.cs
- PagedDataSource.cs
- XmlSchemaExternal.cs
- DefaultObjectSerializer.cs
- QueryPageSettingsEventArgs.cs
- HttpProcessUtility.cs
- ObjectStateManager.cs
- Quaternion.cs
- IfAction.cs
- glyphs.cs
- BmpBitmapEncoder.cs
- XmlDeclaration.cs
- ReverseComparer.cs
- FormViewInsertedEventArgs.cs
- UdpTransportBindingElement.cs
- DataSourceUtil.cs
- UnsafeNativeMethodsTablet.cs
- ListDataHelper.cs
- TemplateColumn.cs
- MouseEventArgs.cs
- GenerateScriptTypeAttribute.cs
- ConfigXmlCDataSection.cs
- ClientScriptItem.cs
- DiagnosticTrace.cs
- WebPartDisplayModeCancelEventArgs.cs
- XmlFormatWriterGenerator.cs
- FrameSecurityDescriptor.cs
- ParseNumbers.cs
- ValidationEventArgs.cs
- RequestQueryProcessor.cs
- TraceContextRecord.cs
- Atom10FormatterFactory.cs
- CheckBox.cs
- RSAOAEPKeyExchangeDeformatter.cs
- InvariantComparer.cs
- MemberAccessException.cs
- RepeatBehavior.cs
- MultiPageTextView.cs
- cookiecollection.cs
- ComponentSerializationService.cs
- ApplicationFileParser.cs
- DrawingContextDrawingContextWalker.cs
- MetaModel.cs
- StringAnimationUsingKeyFrames.cs
- AspNetCacheProfileAttribute.cs
- Serializer.cs
- LostFocusEventManager.cs
- PersistenceProviderBehavior.cs
- SmiRecordBuffer.cs
- AutomationPatternInfo.cs
- Menu.cs
- SocketException.cs
- FormViewInsertedEventArgs.cs
- HtmlHead.cs
- ScopedMessagePartSpecification.cs
- PersianCalendar.cs
- SQLInt32.cs
- SQLSingle.cs
- TdsParserHelperClasses.cs
- NotSupportedException.cs
- CompleteWizardStep.cs
- RightsManagementEncryptedStream.cs
- StateFinalizationActivity.cs
- XmlDocumentType.cs
- EventListenerClientSide.cs
- PerformanceCounterTraceRecord.cs
- ImageDrawing.cs
- TransactedBatchingElement.cs
- EventLogger.cs
- TextBoxBase.cs
- AlphabeticalEnumConverter.cs
- DoubleLinkListEnumerator.cs
- Point3DCollection.cs
- SqlTriggerContext.cs
- ActionFrame.cs
- GZipStream.cs