Code:
/ 4.0 / 4.0 / untmp / DEVDIV_TFS / Dev10 / Releases / RTMRel / ndp / cdf / src / NetFx40 / System.Activities / System / Activities / Expressions / New.cs / 1305376 / New.cs
//---------------------------------------------------------------- // Copyright (c) Microsoft Corporation. All rights reserved. //--------------------------------------------------------------- namespace System.Activities.Expressions { using System.Activities; using System.Collections.ObjectModel; using System.Diagnostics.CodeAnalysis; using System.Reflection; using System.Runtime; using System.Runtime.Collections; using System.Windows.Markup; [SuppressMessage(FxCop.Category.Naming, FxCop.Rule.IdentifiersShouldNotMatchKeywords, Justification = "Optimizing for XAML naming. VB imperative users will [] qualify (e.g. New [New])")] [SuppressMessage(FxCop.Category.Naming, FxCop.Rule.IdentifiersShouldNotHaveIncorrectSuffix, Justification = "Optimizing for XAML naming.")] [ContentProperty("Arguments")] public sealed class New: CodeActivity { Collection arguments; ConstructorInfo constructorInfo; public New() : base() { } [SuppressMessage(FxCop.Category.Naming, FxCop.Rule.PropertyNamesShouldNotMatchGetMethods, Justification = "Optimizing for XAML naming.")] public Collection Arguments { get { if (this.arguments == null) { this.arguments = new ValidatingCollection { // disallow null values OnAddValidationCallback = item => { if (item == null) { throw FxTrace.Exception.ArgumentNull("item"); } } }; } return this.arguments; } } protected override void CacheMetadata(CodeActivityMetadata metadata) { bool foundError = false; // Loop through each argument, validate it, and if validation // passed expose it to the metadata Type[] types = new Type[this.Arguments.Count]; for (int i = 0; i < this.Arguments.Count; i++) { Argument argument = this.Arguments[i]; if (argument == null || argument.Expression == null) { metadata.AddValidationError(SR.ArgumentRequired("Arguments", typeof(New ))); foundError = true; } else { RuntimeArgument runtimeArgument = new RuntimeArgument("Argument" + i, this.arguments[i].ArgumentType, this.arguments[i].Direction, true); metadata.Bind(this.arguments[i], runtimeArgument); metadata.AddArgument(runtimeArgument); types[i] = this.Arguments[i].Direction == ArgumentDirection.In ? this.Arguments[i].ArgumentType : this.Arguments[i].ArgumentType.MakeByRefType(); } } // 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 && (!typeof(TResult).IsValueType || types.Length > 0)) { metadata.AddValidationError(SR.ConstructorInfoNotFound(typeof(TResult).Name)); } } } protected override TResult Execute(CodeActivityContext context) { object[] objects = new object[this.Arguments.Count]; for (int i = 0; i < this.Arguments.Count; i++) { objects[i] = this.Arguments[i].Get(context); } TResult result; if (this.constructorInfo != null) { result = (TResult)this.constructorInfo.Invoke(objects); } else { Fx.Assert(typeof(TResult).IsValueType, "The type of '" + typeof(TResult).Name + "' must be a value type."); Fx.Assert(this.Arguments.Count == 0, "The number of argument must be zero."); result = (TResult)Activator.CreateInstance(typeof(TResult)); } for (int i = 0; i < this.Arguments.Count; i++) { Argument argument = this.Arguments[i]; if (argument.Direction == ArgumentDirection.InOut || argument.Direction == ArgumentDirection.Out) { argument.Set(context, objects[i]); } } return result; } } } // 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
- IgnoreDeviceFilterElement.cs
- CustomPopupPlacement.cs
- FrameworkReadOnlyPropertyMetadata.cs
- OletxTransactionManager.cs
- BitmapEffectInputConnector.cs
- WizardSideBarListControlItemEventArgs.cs
- ConstraintStruct.cs
- IndexedSelectQueryOperator.cs
- TTSVoice.cs
- WSSecurityJan2004.cs
- ToolStripArrowRenderEventArgs.cs
- RsaSecurityTokenAuthenticator.cs
- StackSpiller.Generated.cs
- EntityDesignerUtils.cs
- HijriCalendar.cs
- TextBoxBaseDesigner.cs
- ContentElement.cs
- SmiMetaDataProperty.cs
- Page.cs
- FormViewDeleteEventArgs.cs
- XsdDuration.cs
- CLSCompliantAttribute.cs
- RegionIterator.cs
- XmlSchemaSubstitutionGroup.cs
- DescendantBaseQuery.cs
- XmlSchemaSimpleTypeUnion.cs
- QuotedPairReader.cs
- HashUtility.cs
- HttpModulesSection.cs
- HttpListenerRequest.cs
- SiteMapDataSource.cs
- ReadingWritingEntityEventArgs.cs
- ReadOnlyNameValueCollection.cs
- FormViewModeEventArgs.cs
- ISessionStateStore.cs
- ViewCellSlot.cs
- RecordConverter.cs
- Pair.cs
- ResourceReferenceExpressionConverter.cs
- TreeView.cs
- PolicyException.cs
- TextViewBase.cs
- AttachedPropertyBrowsableAttribute.cs
- OleDbStruct.cs
- EventHandlersStore.cs
- TextServicesPropertyRanges.cs
- SelectionProviderWrapper.cs
- LicenseProviderAttribute.cs
- EventHandlerList.cs
- ProxyAttribute.cs
- URLAttribute.cs
- PermissionToken.cs
- SecurityKeyUsage.cs
- CapiHashAlgorithm.cs
- DecoderFallback.cs
- PrintEvent.cs
- SiteOfOriginPart.cs
- MailAddressCollection.cs
- HttpHandlerActionCollection.cs
- Screen.cs
- MsmqIntegrationProcessProtocolHandler.cs
- ListViewItemSelectionChangedEvent.cs
- MemberCollection.cs
- DesignerWebPartChrome.cs
- DataTable.cs
- RegistryDataKey.cs
- CodeSubDirectory.cs
- CompModSwitches.cs
- EdmToObjectNamespaceMap.cs
- NumberFormatInfo.cs
- EmbeddedObject.cs
- webproxy.cs
- MessageSecurityProtocol.cs
- OracleParameterCollection.cs
- SmiRecordBuffer.cs
- SignatureToken.cs
- ObjectCacheSettings.cs
- ProtocolsSection.cs
- Model3DGroup.cs
- SiteMembershipCondition.cs
- CodeActivityContext.cs
- XmlSignatureManifest.cs
- SafeFileMappingHandle.cs
- InputBuffer.cs
- SvcMapFileLoader.cs
- GuidConverter.cs
- ObjectSet.cs
- DispatcherOperation.cs
- CheckBoxBaseAdapter.cs
- ReferencedAssemblyResolver.cs
- Rule.cs
- OleDbCommandBuilder.cs
- WebPartDisplayModeCancelEventArgs.cs
- DataGridViewSortCompareEventArgs.cs
- MailAddressParser.cs
- ParameterModifier.cs
- Rectangle.cs
- RecordBuilder.cs
- SyndicationElementExtension.cs
- COM2IDispatchConverter.cs