private void AddCustomAttributesToMethod(CodeMemberMethod dbMethod)
 {
     DataObjectMethodType update = DataObjectMethodType.Update;
     if (base.methodSource.EnableWebMethods)
     {
         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.MethodType != MethodTypeEnum.GenericUpdate)
     {
         if (base.activeCommand == base.methodSource.DeleteCommand)
         {
             update = DataObjectMethodType.Delete;
         }
         else if (base.activeCommand == base.methodSource.InsertCommand)
         {
             update = DataObjectMethodType.Insert;
         }
         else if (base.activeCommand == base.methodSource.UpdateCommand)
         {
             update = DataObjectMethodType.Update;
         }
         dbMethod.CustomAttributes.Add(new CodeAttributeDeclaration(CodeGenHelper.GlobalType(typeof(DataObjectMethodAttribute)), new CodeAttributeArgument[] { new CodeAttributeArgument(CodeGenHelper.Field(CodeGenHelper.GlobalTypeExpr(typeof(DataObjectMethodType)), update.ToString())), new CodeAttributeArgument(CodeGenHelper.Primitive(true)) }));
     }
 }
        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;
        }
Example #3
0
 //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,
     };
 }
Example #4
0
        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");
            }
        }
        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);

                }   

            }
        }
        protected override void OnFieldNameChanged(CodeTypeMemberExtension memberExtension, string oldName, string newName)
        {
            // Field can be either a body member or a message header.
            // First see if the field is a body member.
            CodeAttributeDeclaration bodyMember = memberExtension.FindAttribute("System.ServiceModel.MessageBodyMemberAttribute");
            // If this is a body member, modify the MessageBodyMemberAttribute to include the wire name.
            if (bodyMember != null)
            {                
                CodeAttributeDeclaration newBodyMember =
                new CodeAttributeDeclaration("System.ServiceModel.MessageBodyMemberAttribute",
                new CodeAttributeArgumentExtended("Name",
                new CodePrimitiveExpression(oldName), true));

                memberExtension.AddAttribute(newBodyMember);                
            }

            // Now check whether the field is a message header.
            CodeAttributeDeclaration header = memberExtension.FindAttribute("System.ServiceModel.MessageHeaderAttribute");
            if (header != null)
            {
                CodeAttributeDeclaration newHeader =
                new CodeAttributeDeclaration("System.ServiceModel.MessageHeaderAttribute",
                new CodeAttributeArgumentExtended("Name",
                new CodePrimitiveExpression(oldName), true));

                memberExtension.AddAttribute(newHeader);                
            }  
            
            // Make sure the field name change is reflected in the field name references.
            ConvertFieldReferencesInConstructors(memberExtension.Parent.Constructors, oldName, newName);
        }
    /*
     * 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);
            }
        }
    }
 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)) }));
     }
 }
Example #9
0
 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;
 }
		public static void AddAttribute(this CodeAttributeDeclarationCollection codeAttributeDeclarationCollection, CodeAttributeDeclaration codeAttributeDeclaration)
		{
			if (codeAttributeDeclaration != null)
			{
				codeAttributeDeclarationCollection.Add(codeAttributeDeclaration);
			}
		}
        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;
        }
        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 ();
            }
        }
 private void AddCustomAttributesToMethod(CodeMemberMethod dbMethod)
 {
     if (base.methodSource.EnableWebMethods)
     {
         CodeAttributeDeclaration declaration = new CodeAttributeDeclaration("System.Web.Services.WebMethod");
         declaration.Arguments.Add(new CodeAttributeArgument("Description", CodeGenHelper.Str(base.methodSource.WebMethodDescription)));
         dbMethod.CustomAttributes.Add(declaration);
     }
     DataObjectMethodType select = DataObjectMethodType.Select;
     if (base.methodSource.CommandOperation == CommandOperation.Update)
     {
         select = DataObjectMethodType.Update;
     }
     else if (base.methodSource.CommandOperation == CommandOperation.Delete)
     {
         select = DataObjectMethodType.Delete;
     }
     else if (base.methodSource.CommandOperation == CommandOperation.Insert)
     {
         select = DataObjectMethodType.Insert;
     }
     if (select != DataObjectMethodType.Select)
     {
         dbMethod.CustomAttributes.Add(new CodeAttributeDeclaration(CodeGenHelper.GlobalType(typeof(DataObjectMethodAttribute)), new CodeAttributeArgument[] { new CodeAttributeArgument(CodeGenHelper.Field(CodeGenHelper.GlobalTypeExpr(typeof(DataObjectMethodType)), select.ToString())), new CodeAttributeArgument(CodeGenHelper.Primitive(false)) }));
     }
 }
        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);

                    }
                }

            }
        }
 public void SetUp()
 {
     Generator = new StructureGenerator(Configuration);
     Configuration = new CodeGeneratorConfiguration().MediaTypes;
     attribute = new CodeAttributeDeclaration("MediaType");
     contentType = new MediaType();
 }
Example #16
0
        public override CodeAttributeDeclaration GetAttributeDeclaration()
        {
            CodeAttributeDeclaration attribute = new CodeAttributeDeclaration("ValidateEmail");

            base.AddAttributeArguments(attribute, ErrorMessagePlacement.UnOrdered);
            return attribute;
        }
        private CodeTypeDeclaration GetGeneratedClass(MultiDirectionTestClass testClass)
        {
            CodeTypeDeclaration result = new CodeTypeDeclaration(this.GetGeneratedClassName(testClass));
            result.Attributes = MemberAttributes.Public;
            result.BaseTypes.Add(testClass.ClassType);

            CodeAttributeDeclaration testClassAttribute = new CodeAttributeDeclaration(
                new CodeTypeReference(typeof(TestClassAttribute)));

            result.CustomAttributes.Add(testClassAttribute);

            // Add initialize and cleanup method
            result.Members.Add(this.GetInitCleanupMethod(typeof(ClassInitializeAttribute), testClass));
            result.Members.Add(this.GetInitCleanupMethod(typeof(ClassCleanupAttribute), testClass));

            // No need to generate TestInitialize and TestCleanup Method.
            // Generated class can inherit from base class.

            // Expand multiple direction test case
            foreach (MultiDirectionTestMethod testMethod in testClass.MultiDirectionMethods)
            {
                this.AddGeneratedMethod(result, testMethod);
            }

            return result;
        }
Example #18
0
 public static CodeAttributeDeclaration AddAttribute(CodeTypeMember tgtMethodCLR, string attr)
 {
     var declaration =
         new CodeAttributeDeclaration(new CodeTypeReference(attr, CodeTypeReferenceOptions.GlobalReference));
     tgtMethodCLR.CustomAttributes.Add(declaration);
     return declaration;
 }
 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);
 }
Example #20
0
        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;
        }
 internal CodeTypeDeclaration GenerateDataComponent(DesignTable designTable, bool isFunctionsComponent, bool generateHierarchicalUpdate)
 {
     CodeTypeDeclaration dataComponentClass = CodeGenHelper.Class(designTable.GeneratorDataComponentClassName, true, designTable.DataAccessorModifier);
     dataComponentClass.BaseTypes.Add(CodeGenHelper.GlobalType(designTable.BaseClass));
     dataComponentClass.CustomAttributes.Add(CodeGenHelper.AttributeDecl("System.ComponentModel.DesignerCategoryAttribute", CodeGenHelper.Str("code")));
     dataComponentClass.CustomAttributes.Add(CodeGenHelper.AttributeDecl("System.ComponentModel.ToolboxItem", CodeGenHelper.Primitive(true)));
     dataComponentClass.CustomAttributes.Add(CodeGenHelper.AttributeDecl("System.ComponentModel.DataObjectAttribute", CodeGenHelper.Primitive(true)));
     dataComponentClass.CustomAttributes.Add(CodeGenHelper.AttributeDecl("System.ComponentModel.DesignerAttribute", CodeGenHelper.Str(adapterDesigner + ", Microsoft.VSDesigner, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a")));
     dataComponentClass.CustomAttributes.Add(CodeGenHelper.AttributeDecl(typeof(HelpKeywordAttribute).FullName, CodeGenHelper.Str("vs.data.TableAdapter")));
     if (designTable.WebServiceAttribute)
     {
         CodeAttributeDeclaration declaration2 = new CodeAttributeDeclaration("System.Web.Services.WebService");
         declaration2.Arguments.Add(new CodeAttributeArgument("Namespace", CodeGenHelper.Str(designTable.WebServiceNamespace)));
         declaration2.Arguments.Add(new CodeAttributeArgument("Description", CodeGenHelper.Str(designTable.WebServiceDescription)));
         dataComponentClass.CustomAttributes.Add(declaration2);
     }
     dataComponentClass.Comments.Add(CodeGenHelper.Comment("Represents the connection and commands used to retrieve and save data.", true));
     new DataComponentMethodGenerator(this.dataSourceGenerator, designTable, generateHierarchicalUpdate).AddMethods(dataComponentClass, isFunctionsComponent);
     CodeGenerator.ValidateIdentifiers(dataComponentClass);
     QueryHandler handler = new QueryHandler(this.dataSourceGenerator, designTable);
     if (isFunctionsComponent)
     {
         handler.AddFunctionsToDataComponent(dataComponentClass, true);
         return dataComponentClass;
     }
     handler.AddQueriesToDataComponent(dataComponentClass);
     return dataComponentClass;
 }
 protected override void GenerateClassAttributes()
 {
     base.GenerateClassAttributes();
     if ((base._sourceDataClass != null) && (this.Parser.OutputCacheParameters != null))
     {
         OutputCacheParameters outputCacheParameters = this.Parser.OutputCacheParameters;
         if (outputCacheParameters.Duration > 0)
         {
             CodeAttributeDeclaration declaration = new CodeAttributeDeclaration("System.Web.UI.PartialCachingAttribute");
             CodeAttributeArgument argument = new CodeAttributeArgument(new CodePrimitiveExpression(outputCacheParameters.Duration));
             declaration.Arguments.Add(argument);
             argument = new CodeAttributeArgument(new CodePrimitiveExpression(outputCacheParameters.VaryByParam));
             declaration.Arguments.Add(argument);
             argument = new CodeAttributeArgument(new CodePrimitiveExpression(outputCacheParameters.VaryByControl));
             declaration.Arguments.Add(argument);
             argument = new CodeAttributeArgument(new CodePrimitiveExpression(outputCacheParameters.VaryByCustom));
             declaration.Arguments.Add(argument);
             argument = new CodeAttributeArgument(new CodePrimitiveExpression(outputCacheParameters.SqlDependency));
             declaration.Arguments.Add(argument);
             argument = new CodeAttributeArgument(new CodePrimitiveExpression(this.Parser.FSharedPartialCaching));
             declaration.Arguments.Add(argument);
             if (MultiTargetingUtil.IsTargetFramework40OrAbove)
             {
                 argument = new CodeAttributeArgument("ProviderName", new CodePrimitiveExpression(this.Parser.Provider));
                 declaration.Arguments.Add(argument);
             }
             base._sourceDataClass.CustomAttributes.Add(declaration);
         }
     }
 }
Example #23
0
        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;
        }
Example #24
0
        private static void FormatActions(AttributableCodeDomObject method, CodeAttributeDeclaration targetAttribute, string serviceNamespace, string serviceName)
        {
            serviceNamespace = serviceNamespace.TrimEnd('/');
            string operationName = method.ExtendedObject.Name;

            CodeAttributeArgument asyncPatternArgument = targetAttribute.FindArgument("AsyncPattern");
            if (asyncPatternArgument != null)
            {
                CodePrimitiveExpression value = asyncPatternArgument.Value as CodePrimitiveExpression;
                if (value != null && (bool)value.Value && operationName.StartsWith("Begin", StringComparison.OrdinalIgnoreCase))
                {
                    operationName = operationName.Substring(5);
                }
            }

            CodeAttributeArgument actionArgument = targetAttribute.FindArgument("Action");
            if (actionArgument != null)
            {
                string action = string.Format("{0}/{1}/{2}", serviceNamespace, serviceName, operationName);
                actionArgument.Value = new CodePrimitiveExpression(action);
            }

            CodeAttributeArgument replyArgument = targetAttribute.FindArgument("ReplyAction");
            if (replyArgument != null)
            {
                string action = string.Format("{0}/{1}/{2}Response", serviceNamespace, serviceName, operationName);
                replyArgument.Value = new CodePrimitiveExpression(action);
            }
        }
        internal CodeTypeMemberCollection GenerateParameterProperty(IParameter parameter,
            IMethod method,
            CodeTypeDeclaration resourceClass,
            IEnumerable<string> usedNames)
        {
            // Get the name and return type of this parameter.
            string name = parameter.Name;
            CodeTypeReference returnType = ResourceBaseGenerator.GetParameterTypeReference(
                resourceClass, parameter);

            // Generate the property and field.
            CodeTypeMemberCollection newMembers = DecoratorUtil.CreateAutoProperty(
                name, parameter.Description, returnType, usedNames, parameter.IsRequired);

            // Add the KeyAttribute to the property.
            foreach (CodeTypeMember member in newMembers)
            {
                CodeMemberProperty property = member as CodeMemberProperty;
                if (property == null)
                {
                    continue;
                }

                // Declare the RequestParameter attribute.
                CodeTypeReference attributeType = new CodeTypeReference(typeof(RequestParameterAttribute));
                CodeAttributeDeclaration attribute = new CodeAttributeDeclaration(attributeType);
                attribute.Arguments.Add(new CodeAttributeArgument(new CodePrimitiveExpression(parameter.Name)));
                property.CustomAttributes.Add(attribute);
            }

            return newMembers;
        }
 public void SetUp()
 {
     Configuration = CodeGeneratorConfiguration.Create().MediaTypes;
     attribute = new CodeAttributeDeclaration();
     Generator = new EntityDescriptionGenerator(Configuration);
     documentType = new DocumentType { Info = { Alias = "anEntity" } };
     EntityDescription = documentType.Info;
 }
		public void Constructor1_NullItem ()
		{
			CodeAttributeDeclaration[] declarations = new CodeAttributeDeclaration[] { 
				new CodeAttributeDeclaration (), null };

			CodeAttributeDeclarationCollection coll = new CodeAttributeDeclarationCollection (
				declarations);
		}
 public static CodeAttributeDeclaration Clone(this CodeAttributeDeclaration attribute)
 {
     if (attribute == null) return null;
     CodeAttributeDeclaration a = new CodeAttributeDeclaration(attribute.AttributeType.Clone());
     a.Arguments.AddRange(attribute.Arguments.Clone());
     a.Name = attribute.Name;
     return a;
 }
 /// <devdoc>
 /// <para>Copies the elements of an array to the end of the <see cref='System.CodeDom.CodeAttributeDeclarationCollection'/>.</para>
 /// </devdoc>
 public void AddRange(CodeAttributeDeclaration[] value) {
     if (value == null) {
         throw new ArgumentNullException("value");
     }
     for (int i = 0; ((i) < (value.Length)); i = ((i) + (1))) {
         this.Add(value[i]);
     }
 }
		public void Constructor1_Deny_Unrestricted ()
		{
			CodeAttributeDeclaration cad = new CodeAttributeDeclaration ("mono");
			Assert.AreEqual (0, cad.Arguments.Count, "Arguments");
			Assert.AreEqual ("mono", cad.Name, "Name");
			cad.Name = null;
			Assert.AreEqual ("System.Void", cad.AttributeType.BaseType, "AttributeType.BaseType");
		}
Example #31
0
        public System.CodeDom.CodeAttributeDeclaration ToCodeDom()
        {
            System.CodeDom.CodeAttributeDeclaration attr = new System.CodeDom.CodeAttributeDeclaration(
                this.Name
                );

            attr.Arguments.AddRange(this.Arguments.ToCodeDom());
            return(attr);
        }
 /// <include file='doc\CodeAttributeDeclarationCollection.uex' path='docs/doc[@for="CodeAttributeDeclarationCollection.Add"]/*' />
 /// <devdoc>
 ///    <para>Adds a <see cref='System.CodeDom.CodeAttributeDeclaration'/> with the specified value to the
 ///    <see cref='System.CodeDom.CodeAttributeDeclarationCollection'/> .</para>
 /// </devdoc>
 public int Add(CodeAttributeDeclaration value)
 {
     return(List.Add(value));
 }
 /// <include file='doc\CodeAttributeDeclarationCollection.uex' path='docs/doc[@for="CodeAttributeDeclarationCollection.IndexOf"]/*' />
 /// <devdoc>
 ///    <para>Returns the index of a <see cref='System.CodeDom.CodeAttributeDeclaration'/> in
 ///       the <see cref='System.CodeDom.CodeAttributeDeclarationCollection'/> .</para>
 /// </devdoc>
 public int IndexOf(CodeAttributeDeclaration value)
 {
     return(List.IndexOf(value));
 }
 /// <include file='doc\CodeAttributeDeclarationCollection.uex' path='docs/doc[@for="CodeAttributeDeclarationCollection.Contains"]/*' />
 /// <devdoc>
 /// <para>Gets a value indicating whether the
 ///    <see cref='System.CodeDom.CodeAttributeDeclarationCollection'/> contains the specified <see cref='System.CodeDom.CodeAttributeDeclaration'/>.</para>
 /// </devdoc>
 public bool Contains(CodeAttributeDeclaration value)
 {
     return(List.Contains(value));
 }
Example #35
0
 public void Insert(int index, CodeAttributeDeclaration value)
 {
 }
 public void Remove(CodeAttributeDeclaration value)
 {
     throw new NotImplementedException();
 }
Example #37
0
 public void Insert(int index, CodeAttributeDeclaration value) => List.Insert(index, value);
 public void Insert(int index, CodeAttributeDeclaration value)
 {
     throw new NotImplementedException();
 }
 public int IndexOf(CodeAttributeDeclaration value)
 {
     throw new NotImplementedException();
 }
 public bool Contains(CodeAttributeDeclaration value)
 {
     throw new NotImplementedException();
 }
Example #41
0
        public bool AddPropertyStruct(string name, Type type, System.CodeDom.CodeAttributeDeclaration cad, int len, string desc)
        {
            bool i = false;

            try
            {
                CodeMemberProperty cmp = new CodeMemberProperty();
                CodeMemberField    cmf = new CodeMemberField(typeof(byte[]), "ary_" + name);
                if (desc != null && desc.Trim() != "")
                {
                    cmf.Comments.Add(new CodeCommentStatement(desc));
                    cmp.Comments.Add(new CodeCommentStatement(desc));
                }
                cmf.CustomAttributes.Add(
                    new CodeAttributeDeclaration(new CodeTypeReference(typeof(MarshalAsAttribute))
                                                 , new CodeAttributeArgument(
                                                     new CodeFieldReferenceExpression(new CodeTypeReferenceExpression(typeof(UnmanagedType)),
                                                                                      UnmanagedType.ByValArray.ToString()))


                                                 , new CodeAttributeArgument("SizeConst", new CodePrimitiveExpression(len))));
                cmf.Attributes = (cmf.Attributes & ~MemberAttributes.AccessMask) | MemberAttributes.Public;
                ctst.Members.Add(cmf);

                cmp.Name = name;

                cmp.CustomAttributes.Add(cad);
                cmp.Type       = new CodeTypeReference(type);
                cmp.Attributes = (cmp.Attributes & ~MemberAttributes.AccessMask) | MemberAttributes.Public;

                CodeExpression csmt =
                    new CodeMethodInvokeExpression(
                        new CodeMethodReferenceExpression(
                            new CodeTypeReferenceExpression(typeof(Encoding))
                            , "Default.GetString")
                        , new CodeFieldReferenceExpression(new CodePropertyReferenceExpression(new CodeThisReferenceExpression(), cmf_var.Name), cmf.Name));

                if (type.Equals(typeof(byte[])))
                {
                    cmp.GetStatements.Add(new CodeMethodReturnStatement(new CodeFieldReferenceExpression(new CodePropertyReferenceExpression(new CodeThisReferenceExpression(), cmf_var.Name), cmf.Name)));
                }

                else if (type.Equals(typeof(string)))
                {
                    cmp.GetStatements.Add(new CodeMethodReturnStatement(csmt));
                }
                else
                {
                    cmp.GetStatements.Add(new CodeMethodReturnStatement(
                                              new CodeMethodInvokeExpression(new CodeMethodReferenceExpression(new CodeTypeReferenceExpression(type), "Parse"), csmt)));
                }

                if (type.Equals(typeof(byte[])))
                {
                    cmp.SetStatements.Add(
                        new CodeAssignStatement(
                            new CodeFieldReferenceExpression(
                                new CodePropertyReferenceExpression(
                                    new CodeThisReferenceExpression(), cmf_var.Name), cmf.Name)
                            , new CodePropertySetValueReferenceExpression()
                            ));
                }
                else
                {
                    cmp.SetStatements.Add(
                        new CodeConditionStatement(
                            new CodeMethodInvokeExpression(
                                new CodeTypeReferenceExpression(typeof(object)), "Equals",
                                new CodePropertySetValueReferenceExpression(),
                                new CodePrimitiveExpression(null))
                            , new CodeMethodReturnStatement()));
                    cmp.SetStatements.Add(
                        new CodeAssignStatement(
                            new CodeFieldReferenceExpression(
                                new CodePropertyReferenceExpression(
                                    new CodeThisReferenceExpression(), cmf_var.Name), cmf.Name),
                            new CodeMethodInvokeExpression(
                                new CodeMethodReferenceExpression(
                                    new CodePropertyReferenceExpression(
                                        new CodeTypeReferenceExpression(typeof(Encoding)), "Default")
                                    , "GetBytes"),
                                new CodeMethodInvokeExpression(new CodeMethodReferenceExpression(
                                                                   new CodeMethodInvokeExpression(new CodeMethodReferenceExpression(
                                                                                                      new CodePropertySetValueReferenceExpression()
                                                                                                      , "ToString")), "PadRight"), new CodePrimitiveExpression(len), new CodePrimitiveExpression(' '))

                                )));
                }

                ctd.Members.Add(cmp);
                i = true;
            }
            catch (Exception)
            {
                i = false;
            }
            return(i);
        }
Example #42
0
 public bool Contains(CodeAttributeDeclaration value) => List.Contains(value);
Example #43
0
 public int Add(CodeAttributeDeclaration value) => List.Add(value);
Example #44
0
 public void Remove(CodeAttributeDeclaration value)
 {
 }
Example #45
0
 public int IndexOf(CodeAttributeDeclaration value) => List.IndexOf(value);
Example #46
0
 public bool Contains(CodeAttributeDeclaration value)
 {
     return(default(bool));
 }
Example #47
0
 public void Remove(CodeAttributeDeclaration value) => List.Remove(value);
Example #48
0
 public int IndexOf(CodeAttributeDeclaration value)
 {
     return(default(int));
 }