本文整理汇总了C#中System.CodeDom.CodeAttributeDeclaration类的典型用法代码示例。如果您正苦于以下问题:C# CodeAttributeDeclaration类的具体用法?C# CodeAttributeDeclaration怎么用?C# CodeAttributeDeclaration使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
CodeAttributeDeclaration类属于System.CodeDom命名空间,在下文中一共展示了CodeAttributeDeclaration类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetOneToOneAttributeForTarget
public CodeAttributeDeclaration GetOneToOneAttributeForTarget()
{
CodeAttributeDeclaration attribute = null;
if (!this.Lazy)
{
attribute = new CodeAttributeDeclaration("OneToOne");
if (TargetAccess != PropertyAccess.Property)
attribute.Arguments.Add(AttributeHelper.GetNamedEnumAttributeArgument("Access", "PropertyAccess", TargetAccess));
if (TargetConstrained)
attribute.Arguments.Add(AttributeHelper.GetNamedAttributeArgument("Constrained", TargetConstrained));
}
else
attribute = new CodeAttributeDeclaration("BelongsTo");
if (TargetCascade != CascadeEnum.None)
attribute.Arguments.Add(AttributeHelper.GetNamedEnumAttributeArgument("Cascade", "CascadeEnum", TargetCascade));
if (!string.IsNullOrEmpty(TargetCustomAccess))
attribute.Arguments.Add(AttributeHelper.GetNamedAttributeArgument("CustomAccess", TargetCustomAccess));
if (TargetOuterJoin != OuterJoinEnum.Auto)
attribute.Arguments.Add(AttributeHelper.GetNamedEnumAttributeArgument("OuterJoin", "OuterJoinEnum", TargetOuterJoin));
return attribute;
}
示例2: Execute
public override void Execute(CodeNamespace codeNamespace)
{
// foreach datatype in the codeNamespace
foreach (CodeTypeDeclaration type in codeNamespace.Types)
{
if (type.IsEnum) continue;
foreach (CodeTypeMember member in type.Members)
{
CodeMemberField codeField = member as CodeMemberField;
if (codeField == null)
continue;
// check if the Field is XmlElement
//"[System.ComponentModel.TypeConverter(typeof(ByteTypeConverter))]";
if (codeField.Type.BaseType == typeof(XmlElement).ToString())
{
// add the custom type editor attribute
CodeAttributeDeclaration attr = new CodeAttributeDeclaration("System.NonSerialized");
codeField.CustomAttributes.Add(attr);
}
}
}
}
示例3: AddAttributeDeclaration
private void AddAttributeDeclaration(CodeTypeDeclaration typeDecl, string clrTypeName, string jsonName)
{
if (this.serializationModel == SerializationModel.DataContractJsonSerializer)
{
CodeAttributeDeclaration attr = new CodeAttributeDeclaration(
new CodeTypeReference(typeof(DataContractAttribute)));
if (clrTypeName != jsonName)
{
attr.Arguments.Add(new CodeAttributeArgument("Name", new CodePrimitiveExpression(jsonName)));
}
typeDecl.CustomAttributes.Add(attr);
}
else if (this.serializationModel == SerializationModel.JsonNet)
{
typeDecl.CustomAttributes.Add(
new CodeAttributeDeclaration(
new CodeTypeReference(typeof(JsonObjectAttribute)),
new CodeAttributeArgument(
"MemberSerialization",
new CodeFieldReferenceExpression(
new CodeTypeReferenceExpression(typeof(MemberSerialization)),
"OptIn"))));
}
else
{
throw new ArgumentException("Invalid serialization model");
}
}
示例4: SetUp
public void SetUp()
{
Generator = new StructureGenerator(Configuration);
Configuration = new CodeGeneratorConfiguration().MediaTypes;
attribute = new CodeAttributeDeclaration("MediaType");
contentType = new MediaType();
}
示例5: BuildPoc
public CodeTypeDeclaration BuildPoc(TableViewBase rootModel)
{
CodeTypeDeclaration ctd = new CodeTypeDeclaration();
ConstructorGraph ctorGraph = new ConstructorGraph();
ctd.Name = rootModel.Name;
ctd.TypeAttributes = System.Reflection.TypeAttributes.Public;
ctd.Attributes = MemberAttributes.Public;
ctd.IsPartial = true;
CodeAttributeDeclaration cad_DataContract = new CodeAttributeDeclaration(" System.Runtime.Serialization.DataContractAttribute");
ctd.CustomAttributes.Add(cad_DataContract);
// Members
foreach (Column c in rootModel.Columns)
{
MemberGraph mGraph = new MemberGraph(c);
CodeMemberField c_field = mGraph.GetField();
CodeMemberProperty c_prop = mGraph.GetProperty();
CodeAttributeDeclaration cad_DataMember = new CodeAttributeDeclaration("System.Runtime.Serialization.DataMemberAttribute");
c_prop.CustomAttributes.Add(cad_DataMember);
ctd.Members.Add(c_field);
ctd.Members.Add(c_prop);
}
foreach (CodeConstructor cc in ctorGraph.GraphConstructors(rootModel))
{
ctd.Members.Add(cc);
}
return ctd;
}
示例6: Clone
//CodeAttributeDeclarationCollection
//public static CodeAttributeDeclarationCollection Clone(CodeAttributeDeclarationCollection attributeCol) {
// foreach(CodeAttributeDeclaration attr in attributeCol) {
// }
// //CodeDirectiveCollection clone = new CodeDirectiveCollection(directivecol);
// //return clone;
//}
public static CodeAttributeDeclaration Clone(CodeAttributeDeclaration attributeDecl)
{
return new CodeAttributeDeclaration(((CodeTypeReferenceEx)attributeDecl.AttributeType).Clone() as CodeTypeReferenceEx)
{
Name = attributeDecl.Name,
};
}
示例7: AddCustomAttributesToMethod
private void AddCustomAttributesToMethod(CodeMemberMethod dbMethod)
{
bool primitive = false;
DataObjectMethodType fill = DataObjectMethodType.Fill;
if (base.methodSource.EnableWebMethods && base.getMethod)
{
CodeAttributeDeclaration declaration = new CodeAttributeDeclaration("System.Web.Services.WebMethod");
declaration.Arguments.Add(new CodeAttributeArgument("Description", CodeGenHelper.Str(base.methodSource.WebMethodDescription)));
dbMethod.CustomAttributes.Add(declaration);
}
if (!base.GeneratePagingMethod && (base.getMethod || (base.ContainerParameterType == typeof(DataTable))))
{
if (base.MethodSource == base.DesignTable.MainSource)
{
primitive = true;
}
if (base.getMethod)
{
fill = DataObjectMethodType.Select;
}
else
{
fill = DataObjectMethodType.Fill;
}
dbMethod.CustomAttributes.Add(new CodeAttributeDeclaration(CodeGenHelper.GlobalType(typeof(DataObjectMethodAttribute)), new CodeAttributeArgument[] { new CodeAttributeArgument(CodeGenHelper.Field(CodeGenHelper.GlobalTypeExpr(typeof(DataObjectMethodType)), fill.ToString())), new CodeAttributeArgument(CodeGenHelper.Primitive(primitive)) }));
}
}
示例8: GetOneToOneAttributeForTarget
public CodeAttributeDeclaration GetOneToOneAttributeForTarget()
{
CodeAttributeDeclaration attribute;
if (!Lazy)
{
attribute = new CodeAttributeDeclaration("OneToOne");
if (TargetConstrained)
attribute.Arguments.Add(AttributeHelper.GetNamedAttributeArgument("Constrained", TargetConstrained));
}
else
attribute = new CodeAttributeDeclaration("BelongsTo");
if (TargetCascade != CascadeEnum.None)
attribute.Arguments.Add(AttributeHelper.GetNamedEnumAttributeArgument("Cascade", "CascadeEnum", TargetCascade));
if (!string.IsNullOrEmpty(TargetCustomAccess))
attribute.Arguments.Add(AttributeHelper.GetNamedAttributeArgument("CustomAccess", TargetCustomAccess));
// This was moved out of the above if(Lazy) block. The properties themselves can be virtual and we can fill in the fields when the NHibernate object is loaded.
else if (EffectiveTargetAccess != PropertyAccess.Property)
attribute.Arguments.Add(AttributeHelper.GetNamedEnumAttributeArgument("Access", "PropertyAccess", EffectiveTargetAccess));
if (TargetOuterJoin != OuterJoinEnum.Auto)
attribute.Arguments.Add(AttributeHelper.GetNamedEnumAttributeArgument("OuterJoin", "OuterJoinEnum", TargetOuterJoin));
return attribute;
}
示例9: AddAttribute
public static void AddAttribute(this CodeAttributeDeclarationCollection codeAttributeDeclarationCollection, CodeAttributeDeclaration codeAttributeDeclaration)
{
if (codeAttributeDeclaration != null)
{
codeAttributeDeclarationCollection.Add(codeAttributeDeclaration);
}
}
示例10: GenerateClassAttributes
/*
* Add metadata attributes to the class
*/
protected override void GenerateClassAttributes() {
base.GenerateClassAttributes();
// If the user control has an OutputCache directive, generate
// an attribute with the information about it.
if (_sourceDataClass != null && Parser.OutputCacheParameters != null) {
OutputCacheParameters cacheSettings = Parser.OutputCacheParameters;
if (cacheSettings.Duration > 0) {
CodeAttributeDeclaration attribDecl = new CodeAttributeDeclaration(
"System.Web.UI.PartialCachingAttribute");
CodeAttributeArgument attribArg = new CodeAttributeArgument(
new CodePrimitiveExpression(cacheSettings.Duration));
attribDecl.Arguments.Add(attribArg);
attribArg = new CodeAttributeArgument(new CodePrimitiveExpression(cacheSettings.VaryByParam));
attribDecl.Arguments.Add(attribArg);
attribArg = new CodeAttributeArgument(new CodePrimitiveExpression(cacheSettings.VaryByControl));
attribDecl.Arguments.Add(attribArg);
attribArg = new CodeAttributeArgument(new CodePrimitiveExpression(cacheSettings.VaryByCustom));
attribDecl.Arguments.Add(attribArg);
attribArg = new CodeAttributeArgument(new CodePrimitiveExpression(cacheSettings.SqlDependency));
attribDecl.Arguments.Add(attribArg);
attribArg = new CodeAttributeArgument(new CodePrimitiveExpression(Parser.FSharedPartialCaching));
attribDecl.Arguments.Add(attribArg);
// Use the providerName argument only when targeting 4.0 and above.
if (MultiTargetingUtil.IsTargetFramework40OrAbove) {
attribArg = new CodeAttributeArgument("ProviderName", new CodePrimitiveExpression(Parser.Provider));
attribDecl.Arguments.Add(attribArg);
}
_sourceDataClass.CustomAttributes.Add(attribDecl);
}
}
}
示例11: GetKeyPropertyAttribute
public CodeAttributeDeclaration GetKeyPropertyAttribute()
{
// Why KeyPropertyAttribute doesn't have the same constructor signature as it's base class PropertyAttribute?
CodeAttributeDeclaration attribute = new CodeAttributeDeclaration("KeyProperty");
PopulateKeyPropertyAttribute(attribute);
return attribute;
}
示例12: GetBelongsToAttribute
public CodeAttributeDeclaration GetBelongsToAttribute()
{
CodeAttributeDeclaration attribute = new CodeAttributeDeclaration("BelongsTo");
if (!string.IsNullOrEmpty(SourceColumn))
attribute.Arguments.Add(AttributeHelper.GetPrimitiveAttributeArgument(SourceColumn));
if (SourceCascade != CascadeEnum.None)
attribute.Arguments.Add(AttributeHelper.GetNamedEnumAttributeArgument("Cascade", "CascadeEnum", SourceCascade));
if (!string.IsNullOrEmpty(SourceCustomAccess))
attribute.Arguments.Add(AttributeHelper.GetNamedAttributeArgument("CustomAccess", SourceCustomAccess));
if (!SourceInsert)
attribute.Arguments.Add(AttributeHelper.GetNamedAttributeArgument("Insert", SourceInsert));
if (SourceNotNull)
attribute.Arguments.Add(AttributeHelper.GetNamedAttributeArgument("NotNull", SourceNotNull));
if (SourceOuterJoin != OuterJoinEnum.Auto)
attribute.Arguments.Add(
AttributeHelper.GetNamedEnumAttributeArgument("OuterJoin", "OuterJoinEnum", SourceOuterJoin));
if (!string.IsNullOrEmpty(SourceType))
attribute.Arguments.Add(AttributeHelper.GetNamedTypeAttributeArgument("Type", SourceType));
if (SourceUnique)
attribute.Arguments.Add(AttributeHelper.GetNamedAttributeArgument("Unique", SourceUnique));
if (!SourceUpdate)
attribute.Arguments.Add(AttributeHelper.GetNamedAttributeArgument("Update", SourceUpdate));
if (SourceNotFoundBehaviour != NotFoundBehaviour.Default)
attribute.Arguments.Add(AttributeHelper.GetNamedEnumAttributeArgument("NotFoundBehaviour", "NotFoundBehaviour", SourceNotFoundBehaviour));
return attribute;
}
示例13: AddAttribute
public static void AddAttribute(ITypeDefinition cls, string name, params object[] parameters)
{
bool isOpen;
string fileName = cls.Region.FileName;
var buffer = TextFileProvider.Instance.GetTextEditorData (fileName, out isOpen);
var attr = new CodeAttributeDeclaration (name);
foreach (var parameter in parameters) {
attr.Arguments.Add (new CodeAttributeArgument (new CodePrimitiveExpression (parameter)));
}
var type = new CodeTypeDeclaration ("temp");
type.CustomAttributes.Add (attr);
Project project;
if (!cls.TryGetSourceProject (out project)) {
LoggingService.LogError ("Error can't get source project for:" + cls.FullName);
}
var provider = ((DotNetProject)project).LanguageBinding.GetCodeDomProvider ();
var sw = new StringWriter ();
provider.GenerateCodeFromType (type, sw, new CodeGeneratorOptions ());
string code = sw.ToString ();
int start = code.IndexOf ('[');
int end = code.LastIndexOf (']');
code = code.Substring (start, end - start + 1) + Environment.NewLine;
int pos = buffer.LocationToOffset (cls.Region.BeginLine, cls.Region.BeginColumn);
code = buffer.GetLineIndent (cls.Region.BeginLine) + code;
buffer.Insert (pos, code);
if (!isOpen) {
File.WriteAllText (fileName, buffer.Text);
buffer.Dispose ();
}
}
示例14: DynaAttributeDeclaration
public DynaAttributeDeclaration(string AttributeName, object[] AttributeArguements)
{
CodeAttributeArgument[] caa = new CodeAttributeArgument[AttributeArguements.Length];
for (int i = 0; i < caa.Length; i++)
caa[i] = new CodeAttributeArgument(new CodePrimitiveExpression(AttributeArguements[i]));
cad = new CodeAttributeDeclaration(AttributeName, caa);
}
示例15: Execute
public override void Execute(CodeNamespace codeNamespace)
{
if (Options == null || Options.Property == null || Options.Property.Count == 0)
return;
// foreach datatype in the codeNamespace
foreach (CodeTypeDeclaration type in codeNamespace.Types)
{
// get a list of the propertytypes that start with the class name
List<PropertyType> propertyTypes = Options.Property.FindAll(x => x.QualifiedName.StartsWith(type.Name));
if (propertyTypes == null || propertyTypes.Count == 0)
continue;
foreach (PropertyType propertyType in propertyTypes)
{
CodeMemberProperty member = type
.Members
.OfType<CodeMemberProperty>()
.FirstOrDefault(x => propertyType.QualifiedName.EndsWith(x.Name) || propertyType.QualifiedName.EndsWith("*"));
if (member == null)
continue;
// add the custom type editor attribute
CodeAttributeDeclaration attr = new CodeAttributeDeclaration("System.ComponentModel.Browsable");
attr.Arguments.Add(new CodeAttributeArgument(new CodePrimitiveExpression(false)));
member.CustomAttributes.Add(attr);
}
}
}