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
- Configuration.cs
- AutomationElement.cs
- EntitySqlQueryState.cs
- DecoderNLS.cs
- RecipientServiceModelSecurityTokenRequirement.cs
- PrintPreviewDialog.cs
- ConfigurationException.cs
- QilFactory.cs
- CodeGenerator.cs
- ValueCollectionParameterReader.cs
- Win32Exception.cs
- ToolStripItem.cs
- SpotLight.cs
- DataGridViewRowEventArgs.cs
- COM2PictureConverter.cs
- DataException.cs
- RegexTypeEditor.cs
- ConditionalAttribute.cs
- DataList.cs
- _KerberosClient.cs
- EndpointAddressMessageFilter.cs
- WindowsTokenRoleProvider.cs
- RowUpdatingEventArgs.cs
- XmlQueryOutput.cs
- XamlClipboardData.cs
- Quaternion.cs
- OleDbParameter.cs
- AxisAngleRotation3D.cs
- SqlRowUpdatingEvent.cs
- MemberMaps.cs
- counter.cs
- DiscreteKeyFrames.cs
- XmlResolver.cs
- WebBrowserUriTypeConverter.cs
- OperationSelectorBehavior.cs
- ValidatorCompatibilityHelper.cs
- PrintPreviewDialog.cs
- InstanceNotReadyException.cs
- ItemsPanelTemplate.cs
- AccessDataSource.cs
- ObjectManager.cs
- PenCursorManager.cs
- Margins.cs
- SafeProcessHandle.cs
- MdiWindowListItemConverter.cs
- ConstraintEnumerator.cs
- FormViewUpdatedEventArgs.cs
- ContourSegment.cs
- DeferredReference.cs
- DataGridViewElement.cs
- InstanceHandleConflictException.cs
- DesignTimeValidationFeature.cs
- XmlSchemaImport.cs
- PropertyDescriptor.cs
- CodeDefaultValueExpression.cs
- JsonDeserializer.cs
- TraceContextRecord.cs
- AtlasWeb.Designer.cs
- RecommendedAsConfigurableAttribute.cs
- SerializationEventsCache.cs
- PrimarySelectionAdorner.cs
- DateTimeFormatInfo.cs
- MatrixStack.cs
- AppSettings.cs
- AttachedPropertyBrowsableForChildrenAttribute.cs
- DataTableMapping.cs
- StrokeDescriptor.cs
- sqlmetadatafactory.cs
- ProjectionPathSegment.cs
- ToolStripDropDownItem.cs
- XPathPatternBuilder.cs
- DetailsViewPagerRow.cs
- querybuilder.cs
- ItemCheckEvent.cs
- HostingEnvironmentException.cs
- QuaternionAnimation.cs
- XsdDataContractExporter.cs
- DataGridViewColumnHeaderCell.cs
- TypeDescriptor.cs
- DataRowComparer.cs
- KnownBoxes.cs
- SortKey.cs
- ScriptingProfileServiceSection.cs
- CommandBindingCollection.cs
- DivideByZeroException.cs
- SocketException.cs
- Evidence.cs
- DataIdProcessor.cs
- ComEventsInfo.cs
- entityreference_tresulttype.cs
- NamedObjectList.cs
- SiteMapProvider.cs
- InheritanceContextChangedEventManager.cs
- CodeMemberEvent.cs
- ToolStripRenderer.cs
- _AutoWebProxyScriptEngine.cs
- ComboBoxItem.cs
- Point4D.cs
- EntityParameter.cs
- MouseBinding.cs