示例#1
0
        private void GenerateParameterDeclaration(IEnumerable <DomainOperationParameter> parameters, bool generateAttributes)
        {
            DomainOperationParameter[] paramInfos = parameters.ToArray();
            for (int i = 0; i < paramInfos.Length; i++)
            {
                DomainOperationParameter paramInfo = paramInfos[i];
                if (generateAttributes)
                {
                    IEnumerable <Attribute> paramAttributes = paramInfo.Attributes.Cast <Attribute>();
                    this.GenerateAttributes(paramAttributes);
                }
                string paramTypeName = CodeGenUtilities.GetTypeName(CodeGenUtilities.TranslateType(paramInfo.ParameterType));
                string paramName     = CodeGenUtilities.GetSafeName(paramInfo.Name);

                this.Write(this.ToStringHelper.ToStringWithCulture(paramTypeName));

                this.Write(" ");

                this.Write(this.ToStringHelper.ToStringWithCulture(paramName));


                if (i + 1 < paramInfos.Length)
                {
                    this.Write(", ");
                }
            }
        }
        public AssociationMetadata(PropertyDescriptor pd)
        {
            this.PropertyDescriptor = pd;
            AttributeCollection propertyAttributes = pd.ExplicitAttributes();

            this.AssociationAttribute = (AssociationAttribute)propertyAttributes[typeof(AssociationAttribute)];
            this.IsExternal           = propertyAttributes[typeof(ExternalReferenceAttribute)] != null;
            this.IsCollection         = EntityGenerator.IsCollectionType(pd.PropertyType);

            if (!this.IsCollection)
            {
                this.PropTypeName        = CodeGenUtilities.GetTypeName(pd.PropertyType);
                this.AssociationTypeName = @"OpenRiaServices.DomainServices.Client.EntityRef<" + this.PropTypeName + ">";
                this.Attributes          = propertyAttributes.Cast <Attribute>().Where(a => a.GetType() != typeof(DataMemberAttribute));
            }
            else
            {
                this.PropTypeName        = CodeGenUtilities.GetTypeName(TypeUtility.GetElementType(pd.PropertyType));
                this.AssociationTypeName = "OpenRiaServices.DomainServices.Client.EntityCollection<" + this.PropTypeName + ">";

                List <Attribute>  attributeList = propertyAttributes.Cast <Attribute>().ToList();
                ReadOnlyAttribute readOnlyAttr  = propertyAttributes.OfType <ReadOnlyAttribute>().SingleOrDefault();
                if (readOnlyAttr != null && !propertyAttributes.OfType <EditableAttribute>().Any())
                {
                    attributeList.Add(new EditableAttribute(!readOnlyAttr.IsReadOnly));
                }
                this.Attributes = attributeList.Where(a => a.GetType() != typeof(DataMemberAttribute));
            }

            this.PropertyName = CodeGenUtilities.GetSafeName(pd.Name);
            this.FieldName    = CodeGenUtilities.MakeCompliantFieldName(this.PropertyName);
        }
示例#3
0
        private void GenerateEnumTypeDeclaration(Type enumType)
        {
            DataContractAttribute dataContractAttr = (DataContractAttribute)Attribute.GetCustomAttribute(enumType, typeof(DataContractAttribute));

            if (dataContractAttr != null)
            {
                this.GenerateDataContractAttribute(enumType);
            }

            if (enumType.GetCustomAttributes(typeof(FlagsAttribute), false).Length > 0)
            {
                this.Write("[System.Flags]\r\n");
            }


            this.Write("public enum ");

            this.Write(this.ToStringHelper.ToStringWithCulture(CodeGenUtilities.GetSafeName(enumType.Name)));



            Type underlyingType = enumType.GetEnumUnderlyingType();

            if (underlyingType != typeof(int))
            {
                this.Write(" : ");

                this.Write(this.ToStringHelper.ToStringWithCulture(CodeGenUtilities.GetTypeName(underlyingType)));
            }
        }
示例#4
0
        private void GenerateParameterDeclaration(IEnumerable <DomainOperationParameter> parameters, bool generateAttributes)
        {
            DomainOperationParameter[] paramInfos = parameters.ToArray();
            for (int i = 0; i < paramInfos.Length; i++)
            {
                DomainOperationParameter paramInfo = paramInfos[i];
                if (generateAttributes)
                {
                    IEnumerable <Attribute> paramAttributes = paramInfo.Attributes.Cast <Attribute>();
                    this.GenerateAttributes(paramAttributes);
                }
                string paramTypeName = CodeGenUtilities.GetTypeName(CodeGenUtilities.TranslateType(paramInfo.ParameterType));
                string paramName     = CodeGenUtilities.GetSafeName(paramInfo.Name);


        #line default
        #line hidden

        #line 79 "C:\Code\Repos\openriaservices\OpenRiaServices.DomainServices.Tools.TextTemplate\Framework\CSharpGenerators\Templates\Utility.ttinclude"
                this.Write(this.ToStringHelper.ToStringWithCulture(paramTypeName));


        #line default
        #line hidden

        #line 79 "C:\Code\Repos\openriaservices\OpenRiaServices.DomainServices.Tools.TextTemplate\Framework\CSharpGenerators\Templates\Utility.ttinclude"
                this.Write(" ");


        #line default
        #line hidden

        #line 79 "C:\Code\Repos\openriaservices\OpenRiaServices.DomainServices.Tools.TextTemplate\Framework\CSharpGenerators\Templates\Utility.ttinclude"
                this.Write(this.ToStringHelper.ToStringWithCulture(paramName));


        #line default
        #line hidden

        #line 79 "C:\Code\Repos\openriaservices\OpenRiaServices.DomainServices.Tools.TextTemplate\Framework\CSharpGenerators\Templates\Utility.ttinclude"

                if (i + 1 < paramInfos.Length)
                {
        #line default
        #line hidden

        #line 82 "C:\Code\Repos\openriaservices\OpenRiaServices.DomainServices.Tools.TextTemplate\Framework\CSharpGenerators\Templates\Utility.ttinclude"
                    this.Write(", ");


        #line default
        #line hidden

        #line 82 "C:\Code\Repos\openriaservices\OpenRiaServices.DomainServices.Tools.TextTemplate\Framework\CSharpGenerators\Templates\Utility.ttinclude"
                }
            }
        }
示例#5
0
        /// <summary>
        /// Generates the type declaration.
        /// </summary>
        protected virtual void GenerateClassDeclaration()
        {
            this.GenerateTypeAttributes();

            string baseType   = this.GetBaseTypeName();
            string visibility = this.GetClassVisibility();


        #line default
        #line hidden

        #line 20 "C:\Code\Repos\openriaservices\OpenRiaServices.DomainServices.Tools.TextTemplate\Framework\CSharpGenerators\Templates\DataContractGeneratorTemplate.ttinclude"
            this.Write(this.ToStringHelper.ToStringWithCulture(visibility));


        #line default
        #line hidden

        #line 20 "C:\Code\Repos\openriaservices\OpenRiaServices.DomainServices.Tools.TextTemplate\Framework\CSharpGenerators\Templates\DataContractGeneratorTemplate.ttinclude"
            this.Write(" partial class ");


        #line default
        #line hidden

        #line 20 "C:\Code\Repos\openriaservices\OpenRiaServices.DomainServices.Tools.TextTemplate\Framework\CSharpGenerators\Templates\DataContractGeneratorTemplate.ttinclude"
            this.Write(this.ToStringHelper.ToStringWithCulture(CodeGenUtilities.GetSafeName(this.Type.Name)));


        #line default
        #line hidden

        #line 20 "C:\Code\Repos\openriaservices\OpenRiaServices.DomainServices.Tools.TextTemplate\Framework\CSharpGenerators\Templates\DataContractGeneratorTemplate.ttinclude"
            this.Write(" : ");


        #line default
        #line hidden

        #line 20 "C:\Code\Repos\openriaservices\OpenRiaServices.DomainServices.Tools.TextTemplate\Framework\CSharpGenerators\Templates\DataContractGeneratorTemplate.ttinclude"
            this.Write(this.ToStringHelper.ToStringWithCulture(baseType));


        #line default
        #line hidden

        #line 20 "C:\Code\Repos\openriaservices\OpenRiaServices.DomainServices.Tools.TextTemplate\Framework\CSharpGenerators\Templates\DataContractGeneratorTemplate.ttinclude"
            this.Write("\r\n");


        #line default
        #line hidden

        #line 21 "C:\Code\Repos\openriaservices\OpenRiaServices.DomainServices.Tools.TextTemplate\Framework\CSharpGenerators\Templates\DataContractGeneratorTemplate.ttinclude"
        }
        /// <summary>
        /// Generates the data contract type constructor.
        /// </summary>
        protected virtual void GenerateConstructor()
        {
            string ctorVisibility = this.IsAbstract ? "protected" : "public";

            this.Write(this.ToStringHelper.ToStringWithCulture(ctorVisibility));

            this.Write(" ");

            this.Write(this.ToStringHelper.ToStringWithCulture(CodeGenUtilities.GetSafeName(this.Type.Name)));

            this.Write("()\r\n{\r\n\tthis.OnCreated();\r\n}\r\n");
        }
示例#7
0
        private string GenerateServiceOpMethodBody(DomainOperationEntry domainOperationEntry, string methodName)
        {
            string parameterDictionaryName = "null";

            DomainOperationParameter[] domainOperationEntryParameters = domainOperationEntry.Parameters.ToArray();
            if (domainOperationEntryParameters.Length > 0)
            {
                parameterDictionaryName = "parameters";

                this.Write("Dictionary<string, object> ");

                this.Write(this.ToStringHelper.ToStringWithCulture(parameterDictionaryName));

                this.Write(" = new Dictionary<string, object>();\t\t\t\r\n");


                foreach (DomainOperationParameter paramInfo in domainOperationEntryParameters)
                {
                    if (!this.RegisterEnumTypeIfNecessary(paramInfo.ParameterType, domainOperationEntry))
                    {
                        return(String.Empty);
                    }
                    string paramName = CodeGenUtilities.GetSafeName(paramInfo.Name);

                    this.Write(this.ToStringHelper.ToStringWithCulture(parameterDictionaryName));

                    this.Write(".Add(\"");

                    this.Write(this.ToStringHelper.ToStringWithCulture(paramName));

                    this.Write("\", ");

                    this.Write(this.ToStringHelper.ToStringWithCulture(paramName));

                    this.Write(");\r\n");
                }
            }


            this.Write("this.ValidateMethod(\"");

            this.Write(this.ToStringHelper.ToStringWithCulture(methodName));

            this.Write("\", ");

            this.Write(this.ToStringHelper.ToStringWithCulture(parameterDictionaryName));

            this.Write(");\r\n");


            return(parameterDictionaryName);
        }
示例#8
0
        private void GeneratePropertyDeclaration(PropertyDescriptor propertyDescriptor)
        {
            Type   propertyType     = CodeGenUtilities.TranslateType(propertyDescriptor.PropertyType);
            string propertyTypeName = CodeGenUtilities.GetTypeName(propertyType);
            IEnumerable <Attribute> propAttributes = this.GetPropertyAttributes(propertyDescriptor, propertyType);
            string propertyName = CodeGenUtilities.GetSafeName(propertyDescriptor.Name);

            this.GenerateAttributes(propAttributes);


        #line default
        #line hidden

        #line 161 "C:\Code\Repos\openriaservices\OpenRiaServices.DomainServices.Tools.TextTemplate\Framework\CSharpGenerators\Templates\DataContractGeneratorTemplate.ttinclude"
            this.Write("public ");


        #line default
        #line hidden

        #line 162 "C:\Code\Repos\openriaservices\OpenRiaServices.DomainServices.Tools.TextTemplate\Framework\CSharpGenerators\Templates\DataContractGeneratorTemplate.ttinclude"
            this.Write(this.ToStringHelper.ToStringWithCulture(propertyTypeName));


        #line default
        #line hidden

        #line 162 "C:\Code\Repos\openriaservices\OpenRiaServices.DomainServices.Tools.TextTemplate\Framework\CSharpGenerators\Templates\DataContractGeneratorTemplate.ttinclude"
            this.Write(" ");


        #line default
        #line hidden

        #line 162 "C:\Code\Repos\openriaservices\OpenRiaServices.DomainServices.Tools.TextTemplate\Framework\CSharpGenerators\Templates\DataContractGeneratorTemplate.ttinclude"
            this.Write(this.ToStringHelper.ToStringWithCulture(propertyName));


        #line default
        #line hidden

        #line 162 "C:\Code\Repos\openriaservices\OpenRiaServices.DomainServices.Tools.TextTemplate\Framework\CSharpGenerators\Templates\DataContractGeneratorTemplate.ttinclude"
            this.Write("\r\n");


        #line default
        #line hidden

        #line 163 "C:\Code\Repos\openriaservices\OpenRiaServices.DomainServices.Tools.TextTemplate\Framework\CSharpGenerators\Templates\DataContractGeneratorTemplate.ttinclude"
        }
        private void GeneratePropertyDeclaration(PropertyDescriptor propertyDescriptor)
        {
            Type   propertyType     = CodeGenUtilities.TranslateType(propertyDescriptor.PropertyType);
            string propertyTypeName = CodeGenUtilities.GetTypeName(propertyType);
            IEnumerable <Attribute> propAttributes = this.GetPropertyAttributes(propertyDescriptor, propertyType);
            string propertyName = CodeGenUtilities.GetSafeName(propertyDescriptor.Name);

            this.GenerateAttributes(propAttributes);

            this.Write("public ");

            this.Write(this.ToStringHelper.ToStringWithCulture(propertyTypeName));

            this.Write(" ");

            this.Write(this.ToStringHelper.ToStringWithCulture(propertyName));

            this.Write("\r\n");
        }
        /// <summary>
        /// Generates the type declaration.
        /// </summary>
        protected virtual void GenerateClassDeclaration()
        {
            this.GenerateTypeAttributes();

            string baseType   = this.GetBaseTypeName();
            string visibility = this.GetClassVisibility();

            this.Write(this.ToStringHelper.ToStringWithCulture(visibility));

            this.Write(" partial class ");

            this.Write(this.ToStringHelper.ToStringWithCulture(CodeGenUtilities.GetSafeName(this.Type.Name)));

            this.Write(" : ");

            this.Write(this.ToStringHelper.ToStringWithCulture(baseType));

            this.Write("\r\n");
        }
示例#11
0
        /// <summary>
        /// Generates the data contract type constructor.
        /// </summary>
        protected virtual void GenerateConstructor()
        {
            string ctorVisibility = this.IsAbstract ? "protected" : "public";


        #line default
        #line hidden

        #line 62 "C:\Code\Repos\openriaservices\OpenRiaServices.DomainServices.Tools.TextTemplate\Framework\CSharpGenerators\Templates\DataContractGeneratorTemplate.ttinclude"
            this.Write(this.ToStringHelper.ToStringWithCulture(ctorVisibility));


        #line default
        #line hidden

        #line 62 "C:\Code\Repos\openriaservices\OpenRiaServices.DomainServices.Tools.TextTemplate\Framework\CSharpGenerators\Templates\DataContractGeneratorTemplate.ttinclude"
            this.Write(" ");


        #line default
        #line hidden

        #line 62 "C:\Code\Repos\openriaservices\OpenRiaServices.DomainServices.Tools.TextTemplate\Framework\CSharpGenerators\Templates\DataContractGeneratorTemplate.ttinclude"
            this.Write(this.ToStringHelper.ToStringWithCulture(CodeGenUtilities.GetSafeName(this.Type.Name)));


        #line default
        #line hidden

        #line 62 "C:\Code\Repos\openriaservices\OpenRiaServices.DomainServices.Tools.TextTemplate\Framework\CSharpGenerators\Templates\DataContractGeneratorTemplate.ttinclude"
            this.Write("()\r\n{\r\n\tthis.OnCreated();\r\n}\r\n");


        #line default
        #line hidden

        #line 66 "C:\Code\Repos\openriaservices\OpenRiaServices.DomainServices.Tools.TextTemplate\Framework\CSharpGenerators\Templates\DataContractGeneratorTemplate.ttinclude"
        }
示例#12
0
 internal override void Initialize()
 {
     base.Initialize();
     this.DomainContextTypeName = CodeGenUtilities.GetSafeName(DomainContextGenerator.GetDomainContextTypeName(this.DomainServiceDescription));
 }
示例#13
0
        /// <summary>
        /// Generates a custom method.
        /// </summary>
        /// <param name="domainMethod">The custom method to be generated.</param>
        protected virtual void GenerateCustomMethod(DomainOperationEntry domainMethod)
        {
            this.Write("public void ");

            this.Write(this.ToStringHelper.ToStringWithCulture(domainMethod.Name));

            this.Write("(");


            List <string> invokeParams = new List <string>();

            DomainOperationParameter[] paramInfos = domainMethod.Parameters.ToArray();
            for (int i = 0; i < paramInfos.Length; i++)
            {
                DomainOperationParameter paramInfo = paramInfos[i];
                string paramTypeName = CodeGenUtilities.GetTypeName(CodeGenUtilities.TranslateType(paramInfo.ParameterType));

                this.Write(this.ToStringHelper.ToStringWithCulture(paramTypeName));

                this.Write(" ");

                this.Write(this.ToStringHelper.ToStringWithCulture(CodeGenUtilities.GetSafeName(paramInfo.Name)));


                if (i + 1 < paramInfos.Length)
                {
                    this.Write(", ");
                }
                if (i > 0)
                {
                    invokeParams.Add(paramInfo.Name);
                }
            }

            this.Write(")\r\n");


            this.GenerateOpeningBrace();

            this.Write(this.ToStringHelper.ToStringWithCulture(paramInfos[0].Name));

            this.Write(".");

            this.Write(this.ToStringHelper.ToStringWithCulture(domainMethod.Name));

            this.Write("(");


            for (int i = 0; i < invokeParams.Count; i++)
            {
                this.Write(this.ToStringHelper.ToStringWithCulture(invokeParams[i]));


                if (i + 1 < invokeParams.Count)
                {
                    this.Write(", ");
                }
            }

            this.Write(");\r\n");


            this.GenerateClosingBrace();
        }
示例#14
0
        private void GenerateEnumTypeDeclaration(Type enumType)
        {
            DataContractAttribute dataContractAttr = (DataContractAttribute)Attribute.GetCustomAttribute(enumType, typeof(DataContractAttribute));

            if (dataContractAttr != null)
            {
                this.GenerateDataContractAttribute(enumType);
            }

            if (enumType.GetCustomAttributes(typeof(FlagsAttribute), false).Length > 0)
            {
        #line default
        #line hidden

        #line 1 "C:\Code\Repos\openriaservices\OpenRiaServices.DomainServices.Tools.TextTemplate\Framework\CSharpGenerators\CSharpEnumGenerator.tt"
                this.Write("\n[System.Flags]\n");


        #line default
        #line hidden

        #line 1 "C:\Code\Repos\openriaservices\OpenRiaServices.DomainServices.Tools.TextTemplate\Framework\CSharpGenerators\CSharpEnumGenerator.tt"
            }



        #line default
        #line hidden

        #line 1 "C:\Code\Repos\openriaservices\OpenRiaServices.DomainServices.Tools.TextTemplate\Framework\CSharpGenerators\CSharpEnumGenerator.tt"
            this.Write("public enum ");


        #line default
        #line hidden

        #line 1 "C:\Code\Repos\openriaservices\OpenRiaServices.DomainServices.Tools.TextTemplate\Framework\CSharpGenerators\CSharpEnumGenerator.tt"
            this.Write(this.ToStringHelper.ToStringWithCulture(CodeGenUtilities.GetSafeName(enumType.Name)));


        #line default
        #line hidden

        #line 1 "C:\Code\Repos\openriaservices\OpenRiaServices.DomainServices.Tools.TextTemplate\Framework\CSharpGenerators\CSharpEnumGenerator.tt"


            Type underlyingType = enumType.GetEnumUnderlyingType();
            if (underlyingType != typeof(int))
            {
        #line default
        #line hidden

        #line 1 "C:\Code\Repos\openriaservices\OpenRiaServices.DomainServices.Tools.TextTemplate\Framework\CSharpGenerators\CSharpEnumGenerator.tt"
                this.Write(" : ");


        #line default
        #line hidden

        #line 1 "C:\Code\Repos\openriaservices\OpenRiaServices.DomainServices.Tools.TextTemplate\Framework\CSharpGenerators\CSharpEnumGenerator.tt"
                this.Write(this.ToStringHelper.ToStringWithCulture(CodeGenUtilities.GetTypeName(underlyingType)));


        #line default
        #line hidden

        #line 1 "C:\Code\Repos\openriaservices\OpenRiaServices.DomainServices.Tools.TextTemplate\Framework\CSharpGenerators\CSharpEnumGenerator.tt"
            }
        }