本文整理汇总了C#中System.CodeDom.CodeAttributeDeclarationCollection.Add方法的典型用法代码示例。如果您正苦于以下问题:C# CodeAttributeDeclarationCollection.Add方法的具体用法?C# CodeAttributeDeclarationCollection.Add怎么用?C# CodeAttributeDeclarationCollection.Add使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.CodeDom.CodeAttributeDeclarationCollection
的用法示例。
在下文中一共展示了CodeAttributeDeclarationCollection.Add方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: SetDescription
private void SetDescription(CodeAttributeDeclarationCollection customAttributes, string description)
{
customAttributes.Add(
new CodeAttributeDeclaration(
new CodeTypeReference(DESCRIPTION_ATTR),
new CodeAttributeArgument(
new CodePrimitiveExpression(description))));
}
示例2: Clone
public static CodeAttributeDeclarationCollection Clone(this CodeAttributeDeclarationCollection collection)
{
if (collection == null) return null;
CodeAttributeDeclarationCollection c = new CodeAttributeDeclarationCollection();
foreach (CodeAttributeDeclaration attribute in collection)
c.Add(attribute.Clone());
return c;
}
示例3: SetProperty
private void SetProperty(CodeAttributeDeclarationCollection customAttributes, string name, string value)
{
customAttributes.Add(
new CodeAttributeDeclaration(
new CodeTypeReference(PROPERTY_ATTR),
new CodeAttributeArgument(
new CodePrimitiveExpression(name)),
new CodeAttributeArgument(
new CodePrimitiveExpression(value))));
}
示例4: SetCategories
private void SetCategories(CodeAttributeDeclarationCollection customAttributes, IEnumerable<string> categories)
{
foreach (var category in categories)
{
customAttributes.Add(
new CodeAttributeDeclaration(
new CodeTypeReference(CATEGORY_ATTR),
new CodeAttributeArgument(
new CodePrimitiveExpression(category))));
}
}
示例5: AddIncludeMetadata
internal static void AddIncludeMetadata(CodeAttributeDeclarationCollection metadata, StructMapping mapping, Type type)
{
if (!mapping.IsAnonymousType)
{
for (StructMapping mapping2 = mapping.DerivedMappings; mapping2 != null; mapping2 = mapping2.NextDerivedMapping)
{
CodeAttributeDeclaration declaration = new CodeAttributeDeclaration(type.FullName);
declaration.Arguments.Add(new CodeAttributeArgument(new CodeTypeOfExpression(mapping2.TypeDesc.FullName)));
metadata.Add(declaration);
AddIncludeMetadata(metadata, mapping2, type);
}
}
}
示例6: BuildParameterAttributes
private static CodeAttributeDeclarationCollection BuildParameterAttributes(ParameterInfo parameterInfo)
{
var collection = new CodeAttributeDeclarationCollection();
object defaultValue = parameterInfo.RawDefaultValue;
if (defaultValue != DBNull.Value)
{
var optionalAttribute = new CodeAttributeDeclaration(new CodeTypeReference(typeof(OptionalAttribute)));
var defaultParameterAttribute = new CodeAttributeDeclaration(new CodeTypeReference(typeof(DefaultParameterValueAttribute)), new CodeAttributeArgument(new CodePrimitiveExpression(defaultValue)));
collection.Add(optionalAttribute);
collection.Add(defaultParameterAttribute);
}
if (parameterInfo.GetCustomAttributes(typeof (ParamArrayAttribute), true).Any())
{
collection.Add(new CodeAttributeDeclaration(new CodeTypeReference(typeof (ParamArrayAttribute))));
}
return collection;
}
示例7: AddElementMetadata
private void AddElementMetadata(CodeAttributeDeclarationCollection metadata, string elementName, TypeDesc typeDesc, bool isNullable)
{
CodeAttributeDeclaration declaration = new CodeAttributeDeclaration(typeof(SoapElementAttribute).FullName);
if (elementName != null)
{
declaration.Arguments.Add(new CodeAttributeArgument(new CodePrimitiveExpression(elementName)));
}
if ((typeDesc != null) && typeDesc.IsAmbiguousDataType)
{
declaration.Arguments.Add(new CodeAttributeArgument("DataType", new CodePrimitiveExpression(typeDesc.DataType.Name)));
}
if (isNullable)
{
declaration.Arguments.Add(new CodeAttributeArgument("IsNullable", new CodePrimitiveExpression(true)));
}
metadata.Add(declaration);
}
示例8: CreateProperty
static CodeMemberProperty CreateProperty(PropertyNameType nameType, string constantsClassName, string defaultValuesClassName)
{
CodeMemberProperty publicProp = new CodeMemberProperty();
publicProp.Name = nameType.propertyName;
publicProp.Attributes = CodeDomHelperObjects.PublicFinal;
publicProp.HasGet = true;
publicProp.HasSet = true;
publicProp.Type = new CodeTypeReference(nameType.propertyType);
CodeAttributeDeclarationCollection attributes = new CodeAttributeDeclarationCollection();
CodeAttributeArgument arg1 = new CodeAttributeArgument(
new CodeFieldReferenceExpression(
new CodeTypeReferenceExpression(constantsClassName),
nameType.propertyName));
CodeAttributeArgument arg2 = new CodeAttributeArgument(
PropertyNameConstants.DefaultValueProperty,
new CodeFieldReferenceExpression(
new CodeTypeReferenceExpression(defaultValuesClassName),
Constants.DefaultPrefix + nameType.propertyName));
// Future TODO: Provide a library with attributes that custom channel writes
// can use to adorn their properties with default values and validators, we can
// then add it here.
attributes.Add(new CodeAttributeDeclaration(
new CodeTypeReference(TypeNameConstants.ConfigurationProperty),
arg1, arg2));
publicProp.CustomAttributes = new CodeAttributeDeclarationCollection(attributes);
string nameInConfig = constantsClassName + "." + nameType.propertyName;
CodeArrayIndexerExpression baseIndexedProperty
= new CodeArrayIndexerExpression(
CodeDomHelperObjects.BaseRef,
new CodeFieldReferenceExpression(
new CodeTypeReferenceExpression(constantsClassName),
nameType.propertyName));
publicProp.GetStatements.Add(new CodeMethodReturnStatement(
new CodeCastExpression(
nameType.propertyType,
baseIndexedProperty)));
publicProp.SetStatements.Add(new CodeAssignStatement(
baseIndexedProperty,
new CodePropertySetValueReferenceExpression()));
return publicProp;
}
示例9: AddDefaultValueAttribute
void AddDefaultValueAttribute(CodeMemberField field, CodeAttributeDeclarationCollection metadata, object defaultValue, TypeMapping mapping, CodeCommentStatementCollection comments, TypeDesc memberTypeDesc, Accessor accessor, CodeConstructor ctor) {
string attributeName = accessor.IsFixed ? "fixed" : "default";
if (!memberTypeDesc.HasDefaultSupport) {
if (comments != null && defaultValue is string) {
DropDefaultAttribute(accessor, comments, memberTypeDesc.FullName);
// do not generate intializers for the user prefered types if they do not have default capability
AddWarningComment(comments, Res.GetString(Res.XmlDropAttributeValue, attributeName, mapping.TypeName, defaultValue.ToString()));
}
return;
}
if (memberTypeDesc.IsArrayLike && accessor is ElementAccessor) {
if (comments != null && defaultValue is string) {
DropDefaultAttribute(accessor, comments, memberTypeDesc.FullName);
// do not generate intializers for array-like types
AddWarningComment(comments, Res.GetString(Res.XmlDropArrayAttributeValue, attributeName, defaultValue.ToString(), ((ElementAccessor)accessor).Name));
}
return;
}
if (mapping.TypeDesc.IsMappedType && field != null && defaultValue is string) {
SchemaImporterExtension extension = mapping.TypeDesc.ExtendedType.Extension;
CodeExpression init = extension.ImportDefaultValue((string)defaultValue, mapping.TypeDesc.FullName);
if (init != null) {
if (ctor != null) {
AddInitializationStatement(ctor, field, init);
}
else {
field.InitExpression = extension.ImportDefaultValue((string)defaultValue, mapping.TypeDesc.FullName);
}
}
if (comments != null) {
DropDefaultAttribute(accessor, comments, mapping.TypeDesc.FullName);
if (init == null) {
AddWarningComment(comments, Res.GetString(Res.XmlNotKnownDefaultValue, extension.GetType().FullName, attributeName, (string)defaultValue, mapping.TypeName, mapping.Namespace));
}
}
return;
}
object value = null;
if (defaultValue is string || defaultValue == null) {
value = ImportDefault(mapping, (string)defaultValue);
}
if (value == null) return;
if (!(mapping is PrimitiveMapping)) {
DropDefaultAttribute(accessor, comments, memberTypeDesc.FullName);
AddWarningComment(comments, Res.GetString(Res.XmlDropNonPrimitiveAttributeValue, attributeName, defaultValue.ToString()));
return;
}
PrimitiveMapping pm = (PrimitiveMapping)mapping;
if (comments != null && !pm.TypeDesc.HasDefaultSupport && pm.TypeDesc.IsMappedType) {
// do not generate intializers for the user prefered types if they do not have default capability
DropDefaultAttribute(accessor, comments, pm.TypeDesc.FullName);
return;
}
if (value == DBNull.Value) {
if (comments != null) {
AddWarningComment(comments, Res.GetString(Res.XmlDropAttributeValue, attributeName, pm.TypeName, defaultValue.ToString()));
}
return;
}
CodeAttributeArgument[] arguments = null;
CodeExpression initExpression = null;
if (pm.IsList) {
#if DEBUG
// use exception in the place of Debug.Assert to avoid throwing asserts from a server process such as aspnet_ewp.exe
if (value.GetType() != typeof(object[])) throw new InvalidOperationException(Res.GetString(Res.XmlInternalErrorDetails, "Default value for list should be object[], not " + value.GetType().Name));
#endif
object[] vals = (object[])value;
CodeExpression[] initializers = new CodeExpression[vals.Length];
for (int i = 0; i < vals.Length; i++) {
GetDefaultValueArguments(pm, vals[i], out initializers[i]);
}
initExpression = new CodeArrayCreateExpression(field.Type, initializers);
}
else {
arguments = GetDefaultValueArguments(pm, value, out initExpression);
}
if (field != null) {
if (ctor != null) {
AddInitializationStatement(ctor, field, initExpression);
}
else {
field.InitExpression = initExpression;
}
}
if (arguments != null && pm.TypeDesc.HasDefaultSupport && accessor.IsOptional && !accessor.IsFixed) {
// Add [DefaultValueAttribute]
CodeAttributeDeclaration attribute = new CodeAttributeDeclaration(typeof(DefaultValueAttribute).FullName, arguments);
metadata.Add(attribute);
}
else if (comments != null) {
DropDefaultAttribute(accessor, comments, memberTypeDesc.FullName);
}
}
示例10: PopulateCustomAttributes
private static void PopulateCustomAttributes(ICustomAttributeProvider type,
CodeAttributeDeclarationCollection attributes, Func<CodeTypeReference, CodeTypeReference> codeTypeModifier)
{
foreach (var customAttribute in type.CustomAttributes.Where(ShouldIncludeAttribute).OrderBy(a => a.AttributeType.FullName).ThenBy(a => ConvertAttrbuteToCode(codeTypeModifier, a)))
{
var attribute = GenerateCodeAttributeDeclaration(codeTypeModifier, customAttribute);
attributes.Add(attribute);
}
}
示例11: AddAttribute
static void AddAttribute (CodeAttributeDeclarationCollection atts, CodeTypeReference type, string val)
{
atts.Add (new CodeAttributeDeclaration (type, new CodeAttributeArgument (new CodePrimitiveExpression (val))));
}
示例12: ExportAnyAttribute
void ExportAnyAttribute(CodeAttributeDeclarationCollection metadata) {
metadata.Add(new CodeAttributeDeclaration(typeof(XmlAnyAttributeAttribute).FullName));
}
示例13: ExportAnyElement
void ExportAnyElement(CodeAttributeDeclarationCollection metadata, string name, string ns, int sequenceId) {
CodeAttributeDeclaration attribute = new CodeAttributeDeclaration(typeof(XmlAnyElementAttribute).FullName);
if (name != null && name.Length > 0) {
attribute.Arguments.Add(new CodeAttributeArgument("Name", new CodePrimitiveExpression(name)));
}
if (ns != null && ns.Length > 0) {
attribute.Arguments.Add(new CodeAttributeArgument("Namespace", new CodePrimitiveExpression(ns)));
}
if (sequenceId >= 0) {
attribute.Arguments.Add(new CodeAttributeArgument("Order", new CodePrimitiveExpression(sequenceId)));
}
metadata.Add(attribute);
}
示例14: ExportMetadata
void ExportMetadata(CodeAttributeDeclarationCollection metadata, Type attributeType, string name, string ns, TypeDesc typeDesc, TypeDesc dataTypeDesc, object isNullable, XmlSchemaForm form, int nestingLevel, int sequenceId) {
CodeAttributeDeclaration attribute = new CodeAttributeDeclaration(attributeType.FullName);
if (name != null) {
attribute.Arguments.Add(new CodeAttributeArgument(new CodePrimitiveExpression(name)));
}
if (typeDesc != null) {
if (isNullable != null && (bool)isNullable && typeDesc.IsValueType && !typeDesc.IsMappedType && CodeProvider.Supports(GeneratorSupport.GenericTypeReference)) {
attribute.Arguments.Add(new CodeAttributeArgument(new CodeTypeOfExpression("System.Nullable`1[" + typeDesc.FullName + "]")));
isNullable = null;
}
else {
attribute.Arguments.Add(new CodeAttributeArgument(new CodeTypeOfExpression(typeDesc.FullName)));
}
}
if (form != XmlSchemaForm.None) {
attribute.Arguments.Add(new CodeAttributeArgument("Form", new CodeFieldReferenceExpression(new CodeTypeReferenceExpression(typeof(XmlSchemaForm).FullName), Enum.Format(typeof(XmlSchemaForm), form, "G"))));
if (form == XmlSchemaForm.Unqualified && ns != null && ns.Length == 0) {
ns = null;
}
}
if (ns != null ) {
attribute.Arguments.Add(new CodeAttributeArgument("Namespace", new CodePrimitiveExpression(ns)));
}
if (dataTypeDesc != null && dataTypeDesc.IsAmbiguousDataType && !dataTypeDesc.IsMappedType) {
attribute.Arguments.Add(new CodeAttributeArgument("DataType", new CodePrimitiveExpression(dataTypeDesc.DataType.Name)));
}
if (isNullable != null) {
attribute.Arguments.Add(new CodeAttributeArgument("IsNullable", new CodePrimitiveExpression((bool)isNullable)));
}
if (nestingLevel > 0) {
attribute.Arguments.Add(new CodeAttributeArgument("NestingLevel", new CodePrimitiveExpression(nestingLevel)));
}
if (sequenceId >= 0) {
attribute.Arguments.Add(new CodeAttributeArgument("Order", new CodePrimitiveExpression(sequenceId)));
}
if (attribute.Arguments.Count == 0 && attributeType == typeof(XmlElementAttribute)) return;
metadata.Add(attribute);
}
示例15: AddCustomAttribute
void AddCustomAttribute(CodeAttributeDeclarationCollection metadata, Type type, CodeAttributeArgument[] arguments) {
CodeAttributeDeclaration attribute = new CodeAttributeDeclaration(type.FullName, arguments);
metadata.Add(attribute);
}