Code:
/ WCF / WCF / 3.5.30729.1 / untmp / Orcas / SP / ndp / cdf / src / WCF / ServiceModel / System / ServiceModel / Channels / SecurityAttributeGenerationHelper.cs / 1 / SecurityAttributeGenerationHelper.cs
//------------------------------------------------------------------------------ // Copyright (c) Microsoft Corporation. All rights reserved. //----------------------------------------------------------------------------- namespace System.ServiceModel.Channels { using System.CodeDom; using System.Xml; static class SecurityAttributeGenerationHelper { public static CodeAttributeDeclaration FindOrCreateAttributeDeclaration(CodeAttributeDeclarationCollection attributes) where T : Attribute { if (attributes == null) throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("attributes"); CodeTypeReference refT = new CodeTypeReference(typeof(T)); foreach (CodeAttributeDeclaration attribute in attributes) if (attribute.AttributeType.BaseType == refT.BaseType) return attribute; CodeAttributeDeclaration result = new CodeAttributeDeclaration(refT); attributes.Add(result); return result; } public static void CreateOrOverridePropertyDeclaration (CodeAttributeDeclaration attribute, string propertyName, V value) { if (attribute == null) throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("attribute"); if (propertyName == null) throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("propertyName"); CodeExpression newValue; if (value is TimeSpan) newValue = new CodeObjectCreateExpression( typeof(TimeSpan), new CodePrimitiveExpression(((TimeSpan)(object)value).Ticks)); else if (value is Enum) newValue = new CodeFieldReferenceExpression( new CodeTypeReferenceExpression(typeof(V)), ((object)value).ToString()); else newValue = new CodePrimitiveExpression((object)value); CodeAttributeArgument attributeProperty = TryGetAttributeProperty(attribute, propertyName); if (attributeProperty == null) { attributeProperty = new CodeAttributeArgument(propertyName, newValue); attribute.Arguments.Add(attributeProperty); } else attributeProperty.Value = newValue; } public static CodeAttributeArgument TryGetAttributeProperty(CodeAttributeDeclaration attribute, string propertyName) { if (attribute == null) throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("attribute"); if (propertyName == null) throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("propertyName"); foreach (CodeAttributeArgument argument in attribute.Arguments) if (argument.Name == propertyName) return argument; return null; } } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007. // Copyright (c) Microsoft Corporation. All rights reserved.
Link Menu
This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- GuidConverter.cs
- OleDbInfoMessageEvent.cs
- QueryCacheKey.cs
- SystemWebCachingSectionGroup.cs
- HttpModuleActionCollection.cs
- ExceptionDetail.cs
- ObjectDataSourceDisposingEventArgs.cs
- GridToolTip.cs
- GroupAggregateExpr.cs
- Debugger.cs
- ImageList.cs
- XmlUtilWriter.cs
- ProviderBase.cs
- XmlSerializerSection.cs
- PreloadHost.cs
- AccessDataSourceView.cs
- NetNamedPipeBinding.cs
- SizeIndependentAnimationStorage.cs
- OleDbFactory.cs
- DispatcherExceptionEventArgs.cs
- GridViewSortEventArgs.cs
- PersonalizationStateInfoCollection.cs
- LayoutManager.cs
- CompositeDispatchFormatter.cs
- CaseExpr.cs
- documentsequencetextcontainer.cs
- WsatExtendedInformation.cs
- SubpageParagraph.cs
- ItemsChangedEventArgs.cs
- WmpBitmapEncoder.cs
- TreeViewCancelEvent.cs
- DbReferenceCollection.cs
- RoleGroupCollection.cs
- CodeBlockBuilder.cs
- TimeSpanOrInfiniteConverter.cs
- LongValidator.cs
- WSHttpBinding.cs
- XmlSchemaAttributeGroup.cs
- SignedXml.cs
- ClientRuntimeConfig.cs
- RawAppCommandInputReport.cs
- wgx_exports.cs
- Content.cs
- SettingsBindableAttribute.cs
- __ConsoleStream.cs
- CustomValidator.cs
- WindowInteractionStateTracker.cs
- DiscoveryProxy.cs
- TrackingMemoryStreamFactory.cs
- SHA256.cs
- CopyNodeSetAction.cs
- cookiecontainer.cs
- LinqDataSourceInsertEventArgs.cs
- Compiler.cs
- LiteralTextParser.cs
- ListBoxChrome.cs
- Invariant.cs
- AliasedExpr.cs
- PreloadedPackages.cs
- FontDialog.cs
- EmptyStringExpandableObjectConverter.cs
- StringUtil.cs
- DelegateSerializationHolder.cs
- IgnoreSectionHandler.cs
- NavigationProperty.cs
- FontFamily.cs
- IndexerHelper.cs
- OleDbInfoMessageEvent.cs
- Vars.cs
- ProxyWebPart.cs
- DataGridCell.cs
- VirtualizedContainerService.cs
- FilterableAttribute.cs
- SerializationSectionGroup.cs
- RepeatInfo.cs
- WebRequestModuleElement.cs
- SoapTransportImporter.cs
- HandlerBase.cs
- TPLETWProvider.cs
- StoreItemCollection.cs
- ContentElement.cs
- ControlBuilderAttribute.cs
- AttributeUsageAttribute.cs
- TextTreeTextElementNode.cs
- OlePropertyStructs.cs
- ExpressionBindingCollection.cs
- FunctionParameter.cs
- PtsHelper.cs
- CodeObject.cs
- X509InitiatorCertificateClientElement.cs
- XPathMessageFilter.cs
- AssemblySettingAttributes.cs
- PathSegment.cs
- SystemInformation.cs
- HtmlControl.cs
- CodeGeneratorOptions.cs
- XsltSettings.cs
- QueryRelOp.cs
- RemotingServices.cs
- ManipulationDeltaEventArgs.cs