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);
        }
        /// <summary>
        /// Generates the notification methods on the class.
        /// </summary>
        protected virtual void GenerateNotificationMethods()
        {
            this.Write("partial void OnCreated();\r\n");


            foreach (PropertyDescriptor pd in this.NotificationMethodList)
            {
                Type   propType         = CodeGenUtilities.TranslateType(pd.PropertyType);
                string propertyTypeName = CodeGenUtilities.GetTypeName(propType);

                this.Write("partial void On");

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

                this.Write("Changing(");

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

                this.Write(" value);\r\npartial void On");

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

                this.Write("Changed();\r\n");
            }
        }
Exemplo n.º 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)));
            }
        }
Exemplo n.º 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);

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

                this.Write(" ");

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


                if (i + 1 < paramInfos.Length)
                {
                    this.Write(", ");
                }
            }
        }
Exemplo n.º 5
0
        /// <summary>
        /// Generates the properties on the WebContext class.
        /// </summary>
        protected virtual void GenerateProperties()
        {
            this.Write("public new static WebContext Current\r\n{\r\n\tget\r\n\t{\r\n\t\treturn ((WebContext)(OpenRia" +
                       "Services.DomainServices.Client.ApplicationServices.WebContextBase.Current));\r\n\t}" +
                       "\r\n}\r\n");



            DomainServiceDescription defaultAuthDescription = this.GetDefaultAuthDescription();

            if (defaultAuthDescription != null)
            {
                Type genericType = null;
                typeof(IAuthentication <>).DefinitionIsAssignableFrom(defaultAuthDescription.DomainServiceType, out genericType);
                if ((genericType != null) && (genericType.GetGenericArguments().Count() == 1))
                {
                    string typeName = CodeGenUtilities.GetTypeName(genericType.GetGenericArguments()[0]);

                    this.Write("public new ");

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

                    this.Write(" User\r\n{\r\n\tget { return (");

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

                    this.Write(")base.User; }\r\n}\r\n");
                }
            }
        }
Exemplo n.º 6
0
        private void GenerateEnumMembers(Type enumType)
        {
            Type underlyingType = enumType.GetEnumUnderlyingType();

            string[] memberNames   = Enum.GetNames(enumType);
            Type     enumValueType = Enum.GetUnderlyingType(enumType);

            for (int i = 0; i < memberNames.Length; ++i)
            {
                string    memberName = memberNames[i];
                FieldInfo fieldInfo  = enumType.GetField(memberName);

                this.GenerateEnumMemberAttributes(fieldInfo);

                if (fieldInfo != null)
                {
                    object memberValue = fieldInfo.GetRawConstantValue();

                    object[] minMaxValues = null;
                    CodeGenUtilities.IntegralMinMaxValues.TryGetValue(underlyingType, out minMaxValues);

                    if (minMaxValues != null && !memberValue.Equals(minMaxValues[2]) && memberValue.Equals(minMaxValues[0]))
                    {
                        this.Write(this.ToStringHelper.ToStringWithCulture(memberName));

                        this.Write(" = ");

                        this.Write(this.ToStringHelper.ToStringWithCulture(CodeGenUtilities.GetTypeName(underlyingType)));

                        this.Write(".MinValue ");
                    }
                    else if (minMaxValues != null && memberValue.Equals(minMaxValues[1]))
                    {
                        this.Write(this.ToStringHelper.ToStringWithCulture(memberName));

                        this.Write(" = ");

                        this.Write(this.ToStringHelper.ToStringWithCulture(CodeGenUtilities.GetTypeName(underlyingType)));

                        this.Write(".MaxValue ");
                    }
                    else
                    {
                        this.Write(this.ToStringHelper.ToStringWithCulture(memberName));

                        this.Write(" = ");

                        this.Write(this.ToStringHelper.ToStringWithCulture(memberValue.ToString()));
                    }

                    if (i + 1 < memberNames.Length)
                    {
                        this.Write(",\r\n");
                    }
                }
            }
        }
Exemplo n.º 7
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"
                }
            }
        }
Exemplo n.º 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 GenerateBackingPrivateField(PropertyDescriptor propertyDescriptor)
        {
            Type   propertyType     = CodeGenUtilities.TranslateType(propertyDescriptor.PropertyType);
            string propertyTypeName = CodeGenUtilities.GetTypeName(propertyType);
            string fieldName        = CodeGenUtilities.MakeCompliantFieldName(propertyDescriptor.Name);

            this.Write("private ");

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

            this.Write(" ");

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

            this.Write(";\r\n");
        }
Exemplo n.º 10
0
        private void GenerateBackingPrivateField(PropertyDescriptor propertyDescriptor)
        {
            Type   propertyType     = CodeGenUtilities.TranslateType(propertyDescriptor.PropertyType);
            string propertyTypeName = CodeGenUtilities.GetTypeName(propertyType);
            string fieldName        = CodeGenUtilities.MakeCompliantFieldName(propertyDescriptor.Name);


        #line default
        #line hidden

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


        #line default
        #line hidden

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


        #line default
        #line hidden

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


        #line default
        #line hidden

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


        #line default
        #line hidden

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


        #line default
        #line hidden

        #line 151 "C:\Code\Repos\openriaservices\OpenRiaServices.DomainServices.Tools.TextTemplate\Framework\CSharpGenerators\Templates\DataContractGeneratorTemplate.ttinclude"
        }
Exemplo n.º 11
0
        private void GenerateEntityContainerClass(string entityContainerClassName)
        {
            this.Write("internal sealed class ");

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

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

            this.GenerateOpeningBrace();
            this.Write("public ");

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

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

            this.GenerateOpeningBrace();

            HashSet <Type> entityTypesToUse = new HashSet <Type>();

            foreach (Type entityType in this.DomainServiceDescription.EntityTypes)
            {
                entityTypesToUse.Add(entityType);
            }

            foreach (Type entityType in this.DomainServiceDescription.EntityTypes.OrderBy(t => t.FullName))
            {
                if (entityTypesToUse.Any(t => t != entityType && t.IsAssignableFrom(entityType)))
                {
                    continue;
                }
                string entitySetOperationsEnumValue = this.GetEntitySetOperationsEnumValue(entityType);
                string entityTypeName = CodeGenUtilities.GetTypeName(entityType);

                this.Write("this.CreateEntitySet<");

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

                this.Write(">(");

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

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

            this.GenerateClosingBrace();
            this.GenerateClosingBrace();
        }
Exemplo n.º 12
0
        private void GenerateContractMethod(DomainOperationEntry operation)
        {
            this.Write("[OpenRiaServices.DomainServices.Client.HasSideEffects(");

            this.Write(this.ToStringHelper.ToStringWithCulture(DomainContextGenerator.OperationHasSideEffects(operation).ToString().ToLower()));

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


            this.GenerateContractMethodAttributes(operation.Name);

            this.Write("System.IAsyncResult Begin");

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

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


            foreach (DomainOperationParameter parameter in operation.Parameters)
            {
                Type parameterType = CodeGenUtilities.TranslateType(parameter.ParameterType);

                this.Write(this.ToStringHelper.ToStringWithCulture(CodeGenUtilities.GetTypeName(parameterType)));

                this.Write(" ");

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

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

            this.Write("System.AsyncCallback callback, object asyncState);\r\n");


            string returnTypeName = CSharpDomainContextGenerator.GetEndOperationReturnType(operation);

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

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

            this.Write(" End");

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

            this.Write("(System.IAsyncResult result);\r\n");
        }
Exemplo n.º 13
0
        /// <summary>
        /// Generates the EntitySet property.
        /// </summary>
        /// <param name="entityType">The type of the EntitySet to be generated.</param>
        protected virtual void GenerateEntitySet(Type entityType)
        {
            string propertyName   = Naming.MakePluralName(entityType.Name);
            string entityTypeName = CodeGenUtilities.GetTypeName(entityType);

            this.Write("public EntitySet<");

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

            this.Write("> ");

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

            this.Write("\r\n{\r\n    get\r\n    {\r\n        return base.EntityContainer.GetEntitySet<");

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

            this.Write(">();\r\n    }\r\n}\r\n");
        }
        private void GenerateTypeAttributes()
        {
            IEnumerable <Attribute> typeAttributes = this.GetTypeAttributes();

            this.GenerateAttributes(typeAttributes);
            this.GenerateDataContractAttribute(this.Type);

            if (!this.IsDerivedType)
            {
                foreach (Type derivedType in this.GetDerivedTypes().OrderBy(t => t.FullName))
                {
                    this.Write("[System.Runtime.Serialization.KnownType(typeof(");

                    this.Write(this.ToStringHelper.ToStringWithCulture(CodeGenUtilities.GetTypeName(derivedType)));

                    this.Write("))]\r\n");
                }
            }
        }
        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");
        }
Exemplo n.º 16
0
        internal string GetInvokeMethodReturnTypeName(DomainOperationEntry domainOperationEntry, InvokeKind invokeKind)
        {
            Type   returnType       = CodeGenUtilities.TranslateType(domainOperationEntry.ReturnType);
            string returnTypeString = (invokeKind == InvokeKind.Async) ? "InvokeResult" :  "InvokeOperation";

            if (returnType != typeof(void))
            {
                if (!this.RegisterEnumTypeIfNecessary(returnType, domainOperationEntry))
                {
                    return(String.Empty);
                }
                returnTypeString = returnTypeString + "<" + CodeGenUtilities.GetTypeName(returnType) + ">";
            }

            if (invokeKind == InvokeKind.Async)
            {
                returnTypeString = string.Format("System.Threading.Tasks.Task<{0}>", returnTypeString);
            }
            return(returnTypeString);
        }
Exemplo n.º 17
0
        internal static string GetEndOperationReturnType(DomainOperationEntry operation)
        {
            string returnTypeName = null;

            if (operation.Operation == DomainOperation.Query)
            {
                if (operation.ReturnType == typeof(void))
                {
                    returnTypeName = "OpenRiaServices.DomainServices.Client.QueryResult";
                }
                else
                {
                    returnTypeName = "OpenRiaServices.DomainServices.Client.QueryResult<" + CodeGenUtilities.GetTypeName(CodeGenUtilities.TranslateType(operation.AssociatedType)) + ">";
                }
            }
            else
            {
                returnTypeName = CodeGenUtilities.GetTypeName(CodeGenUtilities.TranslateType(operation.ReturnType));
            }
            return(returnTypeName);
        }
Exemplo n.º 18
0
        private void GenerateTypeAttributes()
        {
            IEnumerable <Attribute> typeAttributes = this.GetTypeAttributes();

            this.GenerateAttributes(typeAttributes);
            this.GenerateDataContractAttribute(this.Type);

            if (!this.IsDerivedType)
            {
                foreach (Type derivedType in this.GetDerivedTypes().OrderBy(t => t.FullName))
                {
        #line default
        #line hidden

        #line 48 "C:\Code\Repos\openriaservices\OpenRiaServices.DomainServices.Tools.TextTemplate\Framework\CSharpGenerators\Templates\DataContractGeneratorTemplate.ttinclude"
                    this.Write("[System.Runtime.Serialization.KnownType(typeof(");


        #line default
        #line hidden

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


        #line default
        #line hidden

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


        #line default
        #line hidden

        #line 50 "C:\Code\Repos\openriaservices\OpenRiaServices.DomainServices.Tools.TextTemplate\Framework\CSharpGenerators\Templates\DataContractGeneratorTemplate.ttinclude"
                }
            }
        }
        /// <summary>
        /// Generates the properties on the WebContext class.
        /// </summary>
        protected virtual void GenerateProperties()
        {
        #line default
        #line hidden

        #line 1 "C:\Code\Repos\openriaservices\OpenRiaServices.DomainServices.Tools.TextTemplate\Framework\CSharpGenerators\CSharpWebContextGenerator.tt"
            this.Write("\npublic new static WebContext Current\n{\n    get\n    {\n        return ((WebContext" +
                       ")(OpenRiaServices.DomainServices.Client.ApplicationServices.WebContextBase.Curre" +
                       "nt));\n    }\n}\n");


        #line default
        #line hidden

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


            DomainServiceDescription defaultAuthDescription = this.GetDefaultAuthDescription();
            if (defaultAuthDescription != null)
            {
                Type genericType = null;
                typeof(IAuthentication <>).DefinitionIsAssignableFrom(defaultAuthDescription.DomainServiceType, out genericType);
                if ((genericType != null) && (genericType.GetGenericArguments().Count() == 1))
                {
                    string typeName = CodeGenUtilities.GetTypeName(genericType.GetGenericArguments()[0]);


        #line default
        #line hidden

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


        #line default
        #line hidden

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


        #line default
        #line hidden

        #line 1 "C:\Code\Repos\openriaservices\OpenRiaServices.DomainServices.Tools.TextTemplate\Framework\CSharpGenerators\CSharpWebContextGenerator.tt"
                    this.Write(" User\n{\n\tget { return (");


        #line default
        #line hidden

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


        #line default
        #line hidden

        #line 1 "C:\Code\Repos\openriaservices\OpenRiaServices.DomainServices.Tools.TextTemplate\Framework\CSharpGenerators\CSharpWebContextGenerator.tt"
                    this.Write(")base.User; }\n}\n");


        #line default
        #line hidden

        #line 1 "C:\Code\Repos\openriaservices\OpenRiaServices.DomainServices.Tools.TextTemplate\Framework\CSharpGenerators\CSharpWebContextGenerator.tt"
                }
            }
        }
Exemplo n.º 20
0
        /// <summary>
        /// Generates attribute declarations in C#.
        /// </summary>
        /// <param name="attributes">The attributes to be generated.</param>
        /// <param name="forcePropagation">Causes the attributes to be generated even if the attribute verification fails.</param>
        protected virtual void GenerateAttributes(IEnumerable <Attribute> attributes, bool forcePropagation)
        {
            foreach (Attribute attribute in attributes.OrderBy(a => a.GetType().Name))
            {
                AttributeDeclaration attributeDeclaration = AttributeGeneratorHelper.GetAttributeDeclaration(attribute, this.ClientCodeGenerator, forcePropagation);
                if (attributeDeclaration == null || attributeDeclaration.HasErrors)
                {
                    continue;
                }

                string attributeTypeName = CodeGenUtilities.GetTypeName(attributeDeclaration.AttributeType);

                this.Write("[");

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

                this.Write("(");


                if (attributeDeclaration.ConstructorArguments.Count > 0)
                {
                    for (int i = 0; i < attributeDeclaration.ConstructorArguments.Count; i++)
                    {
                        object value       = attributeDeclaration.ConstructorArguments[i];
                        string stringValue = AttributeGeneratorHelper.ConvertValueToCode(value, true);

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


                        if (i + 1 < attributeDeclaration.ConstructorArguments.Count)
                        {
                            this.Write(", ");
                        }
                    }
                }
                if (attributeDeclaration.NamedParameters.Count > 0)
                {
                    if (attributeDeclaration.ConstructorArguments.Count > 0)
                    {
                        this.Write(", ");
                    }

                    for (int i = 0; i < attributeDeclaration.NamedParameters.Count; i++)
                    {
                        KeyValuePair <string, object> pair = attributeDeclaration.NamedParameters.ElementAt(i);
                        string stringValue = AttributeGeneratorHelper.ConvertValueToCode(pair.Value, true);

                        this.Write(this.ToStringHelper.ToStringWithCulture(pair.Key));

                        this.Write("=");

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


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

                this.Write(")]\r\n");
            }
        }
Exemplo n.º 21
0
        private void GenerateEnumMembers(Type enumType)
        {
            Type underlyingType = enumType.GetEnumUnderlyingType();

            string[] memberNames   = Enum.GetNames(enumType);
            Type     enumValueType = Enum.GetUnderlyingType(enumType);

            for (int i = 0; i < memberNames.Length; ++i)
            {
                string    memberName = memberNames[i];
                FieldInfo fieldInfo  = enumType.GetField(memberName);

                this.GenerateEnumMemberAttributes(fieldInfo);

                if (fieldInfo != null)
                {
                    object memberValue = fieldInfo.GetRawConstantValue();

                    object[] minMaxValues = null;
                    CodeGenUtilities.IntegralMinMaxValues.TryGetValue(underlyingType, out minMaxValues);

                    if (minMaxValues != null && !memberValue.Equals(minMaxValues[2]) && memberValue.Equals(minMaxValues[0]))
                    {
        #line default
        #line hidden

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


        #line default
        #line hidden

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


        #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"
                        this.Write(".MinValue ");


        #line default
        #line hidden

        #line 1 "C:\Code\Repos\openriaservices\OpenRiaServices.DomainServices.Tools.TextTemplate\Framework\CSharpGenerators\CSharpEnumGenerator.tt"
                    }
                    else if (minMaxValues != null && memberValue.Equals(minMaxValues[1]))
                    {
        #line default
        #line hidden

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


        #line default
        #line hidden

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


        #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"
                        this.Write(".MaxValue ");


        #line default
        #line hidden

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

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


        #line default
        #line hidden

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


        #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(memberValue.ToString()));


        #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"
                    }

                    if (i + 1 < memberNames.Length)
                    {
        #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"
                    }
                }
            }
        }
Exemplo n.º 22
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"
            }
        }
Exemplo n.º 23
0
        /// <summary>
        /// Generates the notification methods on the class.
        /// </summary>
        protected virtual void GenerateNotificationMethods()
        {
        #line default
        #line hidden

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


        #line default
        #line hidden

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

            foreach (PropertyDescriptor pd in this.NotificationMethodList)
            {
                Type   propType         = CodeGenUtilities.TranslateType(pd.PropertyType);
                string propertyTypeName = CodeGenUtilities.GetTypeName(propType);


        #line default
        #line hidden

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


        #line default
        #line hidden

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


        #line default
        #line hidden

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


        #line default
        #line hidden

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


        #line default
        #line hidden

        #line 179 "C:\Code\Repos\openriaservices\OpenRiaServices.DomainServices.Tools.TextTemplate\Framework\CSharpGenerators\Templates\DataContractGeneratorTemplate.ttinclude"
                this.Write(" value);\r\npartial void On");


        #line default
        #line hidden

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


        #line default
        #line hidden

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


        #line default
        #line hidden

        #line 181 "C:\Code\Repos\openriaservices\OpenRiaServices.DomainServices.Tools.TextTemplate\Framework\CSharpGenerators\Templates\DataContractGeneratorTemplate.ttinclude"
            }
        }
Exemplo n.º 24
0
        /// <summary>
        /// Generates attribute declarations in C#.
        /// </summary>
        /// <param name="attributes">The attributes to be generated.</param>
        /// <param name="forcePropagation">Causes the attributes to be generated even if the attribute verification fails.</param>
        protected virtual void GenerateAttributes(IEnumerable <Attribute> attributes, bool forcePropagation)
        {
            foreach (Attribute attribute in attributes.OrderBy(a => a.GetType().Name))
            {
                AttributeDeclaration attributeDeclaration = AttributeGeneratorHelper.GetAttributeDeclaration(attribute, this.ClientCodeGenerator, forcePropagation);
                if (attributeDeclaration == null || attributeDeclaration.HasErrors)
                {
                    continue;
                }

                string attributeTypeName = CodeGenUtilities.GetTypeName(attributeDeclaration.AttributeType);


        #line default
        #line hidden

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


        #line default
        #line hidden

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


        #line default
        #line hidden

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


        #line default
        #line hidden

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

                if (attributeDeclaration.ConstructorArguments.Count > 0)
                {
                    for (int i = 0; i < attributeDeclaration.ConstructorArguments.Count; i++)
                    {
                        object value       = attributeDeclaration.ConstructorArguments[i];
                        string stringValue = AttributeGeneratorHelper.ConvertValueToCode(value, true);


        #line default
        #line hidden

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


        #line default
        #line hidden

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

                        if (i + 1 < attributeDeclaration.ConstructorArguments.Count)
                        {
        #line default
        #line hidden

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


        #line default
        #line hidden

        #line 38 "C:\Code\Repos\openriaservices\OpenRiaServices.DomainServices.Tools.TextTemplate\Framework\CSharpGenerators\Templates\AttributeGeneratorTemplate.ttinclude"
                        }
                    }
                }
                if (attributeDeclaration.NamedParameters.Count > 0)
                {
                    if (attributeDeclaration.ConstructorArguments.Count > 0)
                    {
        #line default
        #line hidden

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


        #line default
        #line hidden

        #line 46 "C:\Code\Repos\openriaservices\OpenRiaServices.DomainServices.Tools.TextTemplate\Framework\CSharpGenerators\Templates\AttributeGeneratorTemplate.ttinclude"
                    }

                    for (int i = 0; i < attributeDeclaration.NamedParameters.Count; i++)
                    {
                        KeyValuePair <string, object> pair = attributeDeclaration.NamedParameters.ElementAt(i);
                        string stringValue = AttributeGeneratorHelper.ConvertValueToCode(pair.Value, true);


        #line default
        #line hidden

        #line 53 "C:\Code\Repos\openriaservices\OpenRiaServices.DomainServices.Tools.TextTemplate\Framework\CSharpGenerators\Templates\AttributeGeneratorTemplate.ttinclude"
                        this.Write(this.ToStringHelper.ToStringWithCulture(pair.Key));


        #line default
        #line hidden

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


        #line default
        #line hidden

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


        #line default
        #line hidden

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

                        if (i + 1 < attributeDeclaration.NamedParameters.Count)
                        {
        #line default
        #line hidden

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


        #line default
        #line hidden

        #line 56 "C:\Code\Repos\openriaservices\OpenRiaServices.DomainServices.Tools.TextTemplate\Framework\CSharpGenerators\Templates\AttributeGeneratorTemplate.ttinclude"
                        }
                    }
                }


        #line default
        #line hidden

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


        #line default
        #line hidden

        #line 61 "C:\Code\Repos\openriaservices\OpenRiaServices.DomainServices.Tools.TextTemplate\Framework\CSharpGenerators\Templates\AttributeGeneratorTemplate.ttinclude"
            }
        }
Exemplo n.º 25
0
        private void GenerateCustomMethod(DomainOperationEntry customMethod)
        {
            string methodInvokingName = "On" + customMethod.Name + "Invoking";
            string methodInvokedName  = "On" + customMethod.Name + "Invoked";
            List <KeyValuePair <string, string> > customMethodParameters       = new List <KeyValuePair <string, string> >();
            List <DomainOperationParameter>       domainOperationparameterList = new List <DomainOperationParameter>();

            for (int i = 1; i < customMethod.Parameters.Count(); i++)
            {
                DomainOperationParameter paramInfo = customMethod.Parameters[i];
                customMethodParameters.Add(new KeyValuePair <string, string>(CodeGenUtilities.GetTypeName(CodeGenUtilities.TranslateType(paramInfo.ParameterType)), paramInfo.Name));
                domainOperationparameterList.Add(paramInfo);
            }

            var  customMethodAttribute    = customMethod.OperationAttribute as EntityActionAttribute;
            bool allowMultipleInvocations = customMethodAttribute != null && customMethodAttribute.AllowMultipleInvocations;

            this.Write("[OpenRiaServices.DomainServices.Client.EntityAction(\"");

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

            this.Write("\", AllowMultipleInvocations = ");

            this.Write(this.ToStringHelper.ToStringWithCulture(allowMultipleInvocations.ToString().ToLower()));

            this.Write(")]\r\npublic void ");

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

            this.Write("(");


            this.GenerateParameterDeclaration(domainOperationparameterList, true);

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


            this.GenerateOpeningBrace();

            this.Write("this.");

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

            this.Write("(");

            this.GenerateParametersForMethodCall(domainOperationparameterList);
            this.Write(");\r\nbase.InvokeAction(\"");

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

            this.Write("\"");

            if (domainOperationparameterList.Count > 0)
            {
                this.Write(", ");

                this.GenerateParametersForMethodCall(domainOperationparameterList);
            }
            this.Write(");\r\nthis.");

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

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


            this.GenerateClosingBrace();

            this.Write("partial void ");

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

            this.Write("(");

            this.GenerateParameterDeclaration(domainOperationparameterList, false);
            this.Write(");\r\npartial void ");

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

            this.Write("();\r\n");
        }
Exemplo n.º 26
0
        private void GenerateInvokeMethodReturn(DomainOperationEntry domainOperationEntry, string parameterDictionaryString, InvokeKind invokeKind)
        {
            InvokeAttribute invokeAttribute      = (InvokeAttribute)domainOperationEntry.OperationAttribute;
            string          returnTypeNameString = CodeGenUtilities.GetTypeName(CodeGenUtilities.TranslateType(domainOperationEntry.ReturnType));

            if (invokeKind == InvokeKind.Async)
            {
                returnTypeNameString = (domainOperationEntry.ReturnType == typeof(void)) ? string.Empty : string.Format("<{0}>", returnTypeNameString);

                this.Write("return this.InvokeOperationAsync");

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

                this.Write("(\"");

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

                this.Write("\", ");

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

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

                this.Write(this.ToStringHelper.ToStringWithCulture(CodeGenUtilities.GetBooleanString(invokeAttribute.HasSideEffects, true)));

                this.Write(", cancellationToken);\r\n");
            }
            else
            {
                this.Write("return this.");

                this.Write(this.ToStringHelper.ToStringWithCulture(this.GetInvokeMethodReturnTypeName(domainOperationEntry, invokeKind)));

                this.Write("(\"");

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

                this.Write("\", typeof(");

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

                this.Write("), ");

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

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

                this.Write(this.ToStringHelper.ToStringWithCulture(CodeGenUtilities.GetBooleanString(invokeAttribute.HasSideEffects, true)));

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


                if (invokeKind == InvokeKind.WithCallback)
                {
                    this.Write("callback, userState);\r\n");
                }
                else
                {
                    this.Write("null, null);\r\n");
                }
            }
        }
Exemplo n.º 27
0
        private string GetEntityQueryMethodElementReturnTypeName(DomainOperationEntry domainOperationEntry)
        {
            Type entityType = TypeUtility.GetElementType(domainOperationEntry.ReturnType);

            return(CodeGenUtilities.GetTypeName(entityType));
        }
Exemplo n.º 28
0
        private void GenerateSingletonAssociationPropertySetter(AssociationMetadata metadata)
        {
            if (metadata.IsExternal && !metadata.AssociationAttribute.IsForeignKey)
            {
                return;
            }


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

            this.GenerateOpeningBrace();

            this.Write(this.ToStringHelper.ToStringWithCulture(metadata.PropTypeName));

            this.Write(" previous = this.");

            this.Write(this.ToStringHelper.ToStringWithCulture(metadata.PropertyDescriptor.Name));

            this.Write(";\r\nif (previous != value)\r\n");

            this.GenerateOpeningBrace();

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

            this.Write(this.ToStringHelper.ToStringWithCulture(metadata.PropertyDescriptor.Name));

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


            PropertyDescriptor reverseAssociationMember = GetReverseAssociation(metadata.PropertyDescriptor, metadata.AssociationAttribute);

            bool   reverseIsSingleton         = false;
            bool   isBiDirectionalAssociation = (reverseAssociationMember != null) && this.CanGenerateProperty(reverseAssociationMember);
            string revName = isBiDirectionalAssociation ? reverseAssociationMember.Name : string.Empty;

            if (isBiDirectionalAssociation && !metadata.IsExternal)
            {
                this.Write("if(previous != null)\r\n");


                this.GenerateOpeningBrace();

                this.Write("this.");

                this.Write(this.ToStringHelper.ToStringWithCulture(metadata.FieldName));

                this.Write(".Entity = null;\r\n");


                reverseIsSingleton = !EntityGenerator.IsCollectionType(reverseAssociationMember.PropertyType);
                if (!reverseIsSingleton)
                {
                    this.Write("previous.");

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

                    this.Write(".Remove(this);\r\n");
                }
                else
                {
                    this.Write("previous.");

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

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

                this.GenerateClosingBrace();
            }

            if (metadata.AssociationAttribute.IsForeignKey)
            {
                string[] thisKeyProps  = metadata.AssociationAttribute.ThisKeyMembers.ToArray();
                string[] otherKeyProps = metadata.AssociationAttribute.OtherKeyMembers.ToArray();

                this.Write("if(value != null)\r\n");


                this.GenerateOpeningBrace();
                for (int i = 0; i < thisKeyProps.Length; i++)
                {
                    this.Write("this.");

                    this.Write(this.ToStringHelper.ToStringWithCulture(thisKeyProps[i]));

                    this.Write(" = value.");

                    this.Write(this.ToStringHelper.ToStringWithCulture(otherKeyProps[i]));

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

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


                this.GenerateOpeningBrace();
                for (int i = 0; i < thisKeyProps.Length; i++)
                {
                    Type   foreignKeyType     = TypeDescriptor.GetProperties(this.Type).Find(thisKeyProps[i], false).PropertyType;
                    string foreignKeyTypeName = CodeGenUtilities.GetTypeName(foreignKeyType);

                    this.Write("this.");

                    this.Write(this.ToStringHelper.ToStringWithCulture(thisKeyProps[i]));

                    this.Write(" = default(");

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

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

                if (!metadata.IsExternal)
                {
                    this.GenerateSingletonAssociationPropertySetterEntitySetStatement(metadata, isBiDirectionalAssociation, reverseIsSingleton, revName);
                }
            }
            else
            {
                this.GenerateSingletonAssociationPropertySetterEntitySetStatement(metadata, isBiDirectionalAssociation, reverseIsSingleton, revName);
            }

            if (!metadata.IsExternal)
            {
                this.Write("this.RaisePropertyChanged(\"");

                this.Write(this.ToStringHelper.ToStringWithCulture(metadata.PropertyDescriptor.Name));

                this.Write("\");\r\n");
            }
            this.GenerateClosingBrace();
            this.GenerateClosingBrace();
        }
Exemplo n.º 29
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();
        }