Code:
/ Dotnetfx_Win7_3.5.1 / Dotnetfx_Win7_3.5.1 / 3.5.1 / DEVDIV / depot / DevDiv / releases / Orcas / NetFXw7 / ndp / fx / src / DataWeb / Design / system / Data / EntityModel / Emitters / AttributeEmitter.cs / 1 / AttributeEmitter.cs
//----------------------------------------------------------------------
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
//
// @owner [....]
// @backupOwner [....]
//---------------------------------------------------------------------
using System.CodeDom;
using System.Collections.Generic;
using System.Data.Services.Design;
using System.Data.Metadata.Edm;
using System.Diagnostics;
using System.Linq;
namespace System.Data.EntityModel.Emitters
{
///
/// Summary description for AttributeEmitter.
///
internal sealed class AttributeEmitter
{
TypeReference _typeReference;
internal TypeReference TypeReference
{
get { return _typeReference; }
}
internal AttributeEmitter(TypeReference typeReference)
{
_typeReference = typeReference;
}
///
/// The method to be called to create the type level attributes for the ItemTypeEmitter
///
/// The strongly typed emitter
/// The type declaration to add the attribues to.
public void EmitTypeAttributes(EntityTypeEmitter emitter, CodeTypeDeclaration typeDecl)
{
Debug.Assert(emitter != null, "emitter should not be null");
Debug.Assert(typeDecl != null, "typeDecl should not be null");
object[] keys = emitter.Item.KeyMembers.Select(km => (object) km.Name).ToArray();
typeDecl.CustomAttributes.Add(EmitSimpleAttribute(Utils.WebFrameworkCommonNamespace + "." + "DataServiceKeyAttribute", keys));
}
///
/// The method to be called to create the type level attributes for the StructuredTypeEmitter
///
/// The strongly typed emitter
/// The type declaration to add the attribues to.
public void EmitTypeAttributes(StructuredTypeEmitter emitter, CodeTypeDeclaration typeDecl)
{
Debug.Assert(emitter != null, "emitter should not be null");
Debug.Assert(typeDecl != null, "typeDecl should not be null");
// nothing to do here yet
}
///
/// The method to be called to create the type level attributes for the SchemaTypeEmitter
///
/// The strongly typed emitter
/// The type declaration to add the attribues to.
public void EmitTypeAttributes(SchemaTypeEmitter emitter, CodeTypeDeclaration typeDecl)
{
Debug.Assert(emitter != null, "emitter should not be null");
Debug.Assert(typeDecl != null, "typeDecl should not be null");
}
///
/// The method to be called to create the property level attributes for the PropertyEmitter
///
/// The strongly typed emitter
/// The type declaration to add the attribues to.
/// Additional attributes to emit
public void EmitPropertyAttributes(PropertyEmitter emitter,
CodeMemberProperty propertyDecl,
List additionalAttributes)
{
if (additionalAttributes != null && additionalAttributes.Count > 0)
{
try
{
propertyDecl.CustomAttributes.AddRange(additionalAttributes.ToArray());
}
catch (ArgumentNullException e)
{
emitter.Generator.AddError(Strings.InvalidAttributeSuppliedForProperty(emitter.Item.Name),
ModelBuilderErrorCode.InvalidAttributeSuppliedForProperty,
EdmSchemaErrorSeverity.Error,
e);
}
}
}
///
/// The method to be called to create the type level attributes for the NestedTypeEmitter
///
/// The strongly typed emitter
/// The type declaration to add the attribues to.
public void EmitTypeAttributes(ComplexTypeEmitter emitter, CodeTypeDeclaration typeDecl)
{
Debug.Assert(emitter != null, "emitter should not be null");
Debug.Assert(typeDecl != null, "typeDecl should not be null");
// not emitting System.Runtime.Serializaton.DataContractAttribute
// not emitting System.Serializable
}
#region Static Methods
///
///
///
///
///
///
public CodeAttributeDeclaration EmitSimpleAttribute(string attributeType, params object[] arguments)
{
CodeAttributeDeclaration attribute = new CodeAttributeDeclaration(TypeReference.FromString(attributeType, true));
AddAttributeArguments(attribute, arguments);
return attribute;
}
///
///
///
///
///
public static void AddAttributeArguments(CodeAttributeDeclaration attribute, object[] arguments)
{
foreach (object argument in arguments)
{
CodeExpression expression = argument as CodeExpression;
if (expression == null)
expression = new CodePrimitiveExpression(argument);
attribute.Arguments.Add(new CodeAttributeArgument(expression));
}
}
///
/// Adds an XmlIgnore attribute to the given property declaration. This is
/// used to explicitly skip certain properties during XML serialization.
///
/// the property to mark with XmlIgnore
public void AddIgnoreAttributes(CodeMemberProperty propertyDecl)
{
// not emitting System.Xml.Serialization.XmlIgnoreAttribute
// not emitting System.Xml.Serialization.SoapIgnoreAttribute
}
///
/// Adds an Browsable(false) attribute to the given property declaration.
/// This is used to explicitly avoid display property in the PropertyGrid.
///
/// the property to mark with XmlIgnore
public void AddBrowsableAttribute(CodeMemberProperty propertyDecl)
{
// not emitting System.ComponentModel.BrowsableAttribute
}
#endregion
}
}
// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
//----------------------------------------------------------------------
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
//
// @owner [....]
// @backupOwner [....]
//---------------------------------------------------------------------
using System.CodeDom;
using System.Collections.Generic;
using System.Data.Services.Design;
using System.Data.Metadata.Edm;
using System.Diagnostics;
using System.Linq;
namespace System.Data.EntityModel.Emitters
{
///
/// Summary description for AttributeEmitter.
///
internal sealed class AttributeEmitter
{
TypeReference _typeReference;
internal TypeReference TypeReference
{
get { return _typeReference; }
}
internal AttributeEmitter(TypeReference typeReference)
{
_typeReference = typeReference;
}
///
/// The method to be called to create the type level attributes for the ItemTypeEmitter
///
/// The strongly typed emitter
/// The type declaration to add the attribues to.
public void EmitTypeAttributes(EntityTypeEmitter emitter, CodeTypeDeclaration typeDecl)
{
Debug.Assert(emitter != null, "emitter should not be null");
Debug.Assert(typeDecl != null, "typeDecl should not be null");
object[] keys = emitter.Item.KeyMembers.Select(km => (object) km.Name).ToArray();
typeDecl.CustomAttributes.Add(EmitSimpleAttribute(Utils.WebFrameworkCommonNamespace + "." + "DataServiceKeyAttribute", keys));
}
///
/// The method to be called to create the type level attributes for the StructuredTypeEmitter
///
/// The strongly typed emitter
/// The type declaration to add the attribues to.
public void EmitTypeAttributes(StructuredTypeEmitter emitter, CodeTypeDeclaration typeDecl)
{
Debug.Assert(emitter != null, "emitter should not be null");
Debug.Assert(typeDecl != null, "typeDecl should not be null");
// nothing to do here yet
}
///
/// The method to be called to create the type level attributes for the SchemaTypeEmitter
///
/// The strongly typed emitter
/// The type declaration to add the attribues to.
public void EmitTypeAttributes(SchemaTypeEmitter emitter, CodeTypeDeclaration typeDecl)
{
Debug.Assert(emitter != null, "emitter should not be null");
Debug.Assert(typeDecl != null, "typeDecl should not be null");
}
///
/// The method to be called to create the property level attributes for the PropertyEmitter
///
/// The strongly typed emitter
/// The type declaration to add the attribues to.
/// Additional attributes to emit
public void EmitPropertyAttributes(PropertyEmitter emitter,
CodeMemberProperty propertyDecl,
List additionalAttributes)
{
if (additionalAttributes != null && additionalAttributes.Count > 0)
{
try
{
propertyDecl.CustomAttributes.AddRange(additionalAttributes.ToArray());
}
catch (ArgumentNullException e)
{
emitter.Generator.AddError(Strings.InvalidAttributeSuppliedForProperty(emitter.Item.Name),
ModelBuilderErrorCode.InvalidAttributeSuppliedForProperty,
EdmSchemaErrorSeverity.Error,
e);
}
}
}
///
/// The method to be called to create the type level attributes for the NestedTypeEmitter
///
/// The strongly typed emitter
/// The type declaration to add the attribues to.
public void EmitTypeAttributes(ComplexTypeEmitter emitter, CodeTypeDeclaration typeDecl)
{
Debug.Assert(emitter != null, "emitter should not be null");
Debug.Assert(typeDecl != null, "typeDecl should not be null");
// not emitting System.Runtime.Serializaton.DataContractAttribute
// not emitting System.Serializable
}
#region Static Methods
///
///
///
///
///
///
public CodeAttributeDeclaration EmitSimpleAttribute(string attributeType, params object[] arguments)
{
CodeAttributeDeclaration attribute = new CodeAttributeDeclaration(TypeReference.FromString(attributeType, true));
AddAttributeArguments(attribute, arguments);
return attribute;
}
///
///
///
///
///
public static void AddAttributeArguments(CodeAttributeDeclaration attribute, object[] arguments)
{
foreach (object argument in arguments)
{
CodeExpression expression = argument as CodeExpression;
if (expression == null)
expression = new CodePrimitiveExpression(argument);
attribute.Arguments.Add(new CodeAttributeArgument(expression));
}
}
///
/// Adds an XmlIgnore attribute to the given property declaration. This is
/// used to explicitly skip certain properties during XML serialization.
///
/// the property to mark with XmlIgnore
public void AddIgnoreAttributes(CodeMemberProperty propertyDecl)
{
// not emitting System.Xml.Serialization.XmlIgnoreAttribute
// not emitting System.Xml.Serialization.SoapIgnoreAttribute
}
///
/// Adds an Browsable(false) attribute to the given property declaration.
/// This is used to explicitly avoid display property in the PropertyGrid.
///
/// the property to mark with XmlIgnore
public void AddBrowsableAttribute(CodeMemberProperty propertyDecl)
{
// not emitting System.ComponentModel.BrowsableAttribute
}
#endregion
}
}
// 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
- DerivedKeyCachingSecurityTokenSerializer.cs
- NativeWrapper.cs
- DefaultObjectMappingItemCollection.cs
- Rect3DValueSerializer.cs
- ContentType.cs
- TreeViewAutomationPeer.cs
- AutomationPropertyInfo.cs
- ScalarConstant.cs
- UseLicense.cs
- WindowAutomationPeer.cs
- StrokeNodeData.cs
- CodeBinaryOperatorExpression.cs
- QueryTask.cs
- ServicePoint.cs
- TreeNodeBindingCollection.cs
- NotificationContext.cs
- CollectionContainer.cs
- MethodCallExpression.cs
- WebServiceTypeData.cs
- MdiWindowListItemConverter.cs
- MissingMemberException.cs
- MappingException.cs
- StrokeNodeOperations2.cs
- TransformerInfoCollection.cs
- RemotingSurrogateSelector.cs
- SamlSecurityTokenAuthenticator.cs
- AutomationPeer.cs
- CacheAxisQuery.cs
- XmlBufferReader.cs
- LogReservationCollection.cs
- VerificationException.cs
- CommunicationObject.cs
- ContentDisposition.cs
- ImageMapEventArgs.cs
- SelectionPatternIdentifiers.cs
- MarginCollapsingState.cs
- RubberbandSelector.cs
- DataGridViewTopLeftHeaderCell.cs
- TableStyle.cs
- FieldToken.cs
- SafeCoTaskMem.cs
- Attribute.cs
- BindingMemberInfo.cs
- loginstatus.cs
- SqlRowUpdatingEvent.cs
- FaultReason.cs
- GeneralTransform3DTo2DTo3D.cs
- TextServicesPropertyRanges.cs
- UnsafeNativeMethods.cs
- InteropBitmapSource.cs
- PreviewPageInfo.cs
- Int32RectConverter.cs
- Object.cs
- MenuItem.cs
- ToolStripContentPanel.cs
- TargetControlTypeAttribute.cs
- MimeObjectFactory.cs
- SmiContextFactory.cs
- ColumnMapTranslator.cs
- Transaction.cs
- MtomMessageEncodingElement.cs
- DataTableClearEvent.cs
- XomlCompilerHelpers.cs
- XmlTypeMapping.cs
- XmlReader.cs
- SiteMapNodeItem.cs
- DesignTimeResourceProviderFactoryAttribute.cs
- CommandCollectionEditor.cs
- CheckableControlBaseAdapter.cs
- Point3D.cs
- ForeignKeyConstraint.cs
- ConfigDefinitionUpdates.cs
- XhtmlConformanceSection.cs
- DbParameterCollection.cs
- ContextItemManager.cs
- SamlSecurityTokenAuthenticator.cs
- ComponentTray.cs
- Debugger.cs
- KeyNotFoundException.cs
- BindingValueChangedEventArgs.cs
- PropertyItemInternal.cs
- RSAOAEPKeyExchangeDeformatter.cs
- SurrogateEncoder.cs
- CommonXSendMessage.cs
- MemberMaps.cs
- Binding.cs
- DataObjectAttribute.cs
- BindingContext.cs
- D3DImage.cs
- SelectionItemProviderWrapper.cs
- XamlGridLengthSerializer.cs
- HttpListenerElement.cs
- SizeLimitedCache.cs
- HttpRequest.cs
- TimeoutHelper.cs
- XmlILOptimizerVisitor.cs
- PositiveTimeSpanValidatorAttribute.cs
- ExtendedProtectionPolicyElement.cs
- DirectionalLight.cs
- HttpException.cs