Esempio n. 1
0
 /// <include file='doc\SoapCodeExporter.uex' path='docs/doc[@for="SoapCodeExporter.AddMappingMetadata"]/*' />
 /// <devdoc>
 ///    <para>[To be supplied.]</para>
 /// </devdoc>
 internal void AddMappingMetadata(CodeAttributeDeclarationCollection metadata, XmlMemberMapping member, bool forceUseMemberName)
 {
     AddMemberMetadata(metadata, member.Mapping, forceUseMemberName);
 }
        /// <summary>
        ///     Method called by the tool importing the wsdl whenever a operation/web method is found in the wsdl file.
        /// </summary>
        /// <remarks>
        ///     <para>
        ///         This is called once per binding in the wsdl. Each binding is associated with a different
        ///         web method. ImportMethod add attributes to each web method and the web service class
        ///         to add client (proxy) validation capabilities.
        ///     </para>
        ///     <para>
        ///         This class depends on the wsdl file containing the definition of
        ///         just a single service. At present the wsdl files generated by
        ///         the WebService class create wsdl files that meet this restriction.
        ///     </para>
        /// </remarks>
        /// <param name="metadata">Code DOM being created by tool</param>
        public override void ImportMethod(CodeAttributeDeclarationCollection metadata)
        {
            Argument.Assert.IsNotNull(metadata, "metadata");

            // get the ImportContext, it provides access
            // to Wsdl File
            SoapProtocolImporter importer = ImportContext;

            // if there are no validation attributes in any bindings then no
            // DevInterop.Web.Service attributes should be added to
            // generated code. This prevents unneeded attributes from
            // being added to code that does not make use of them
            if (false == CheckedForValidation)
            {
                // this is what does the checking for validation
                CheckedForValidation = true;
                // check every binding in wsdl file for this service
                foreach (Binding binding in importer.Service.ServiceDescription.Bindings)
                {
                    // check every operation in the binding
                    foreach (OperationBinding operationBinding in binding.Operations)
                    {
                        // check to see if the binding has a validation extensibility element
                        HasValidation = null != operationBinding.Input.Extensions.Find("validation", ValidationNamespaces.DevInterop);
                        if (HasValidation)
                        {
                            break;
                        }
                    }
                    if (HasValidation)
                    {
                        break;
                    }
                }
            }
            if (false == HasValidation)
            {
                return;
            }
            // do web service (rather than web method) specific code
            // generation when first method is processed
            if (MethodPos == 0)
            {
                // add a comment to the class to indicate the source of the extension creating the code
                importer.CodeTypeDeclaration.Comments.Add(new CodeCommentStatement("Proxy validation code generated by http://www.DevInterop.net"));
                // Add an attribute to the web service for each schema
                // found in the wsdl file. This will be used for client side validation
                // of messages
                foreach (XmlSchema s in importer.ConcreteSchemas)
                {
                    // string builder is needed to hold serialzation fo schems
                    StringBuilder sb = new StringBuilder();
                    // text writer wraped around string builder captures schema
                    XmlTextWriter xwr = new XmlTextWriter(new StringWriter(sb));
                    // write schema to string builder
                    s.Write(xwr);
                    // convert string builder rto string
                    string schema = sb.ToString();
                    // strip off xml declaration, it is not needed
                    // and its encoding may cause problems
                    schema = schema.Substring(schema.IndexOf("?>") + 2);
                    // build an attribute (a ValdiationSchemaValueAttribute) to be
                    // inserted into the code dom
                    CodeAttributeDeclaration attr =
                        new CodeAttributeDeclaration(typeof(ValidationSchemaValueAttribute).FullName);
                    // build an unnamed attribute argument.
                    CodeAttributeArgument arg =
                        new CodeAttributeArgument(string.Empty,
                                                  // the value of this argument is the string which represents the schema
                                                  new CodePrimitiveExpression(schema));
                    // add this argument to the attribute
                    attr.Arguments.Add(arg);
                    // add this attribute to the code dom. This will add it
                    // to the web service class being processed
                    importer.CodeTypeDeclaration.CustomAttributes.Add(attr);
                }
                // The first binding is being looked at to find the namespace
                // declaration extensibility elements in the binding that contains it.
                // In the current implementation only the binding for the
                // first operation found is checked.
                // This would have to be enhanced
                // to support multiple services defined in a single wsdl file
                Binding    firstBinding = importer.Binding;
                XmlElement ov           = firstBinding.Extensions.Find("validationNS", ValidationNamespaces.DevInterop);
                // no need to process if no validation extensibiltity element exists
                if (null != ov)
                {
                    // make an XPathDocument out of the XmlElement that was found.
                    XPathDocument xpdoc = new XPathDocument(new XmlNodeReader(ov));
                    // now make a navigator to use to find things
                    XPathNavigator xpnav = xpdoc.CreateNavigator();
                    // A namespace manager will be required to use XPathExpressions
                    XmlNamespaceManager namespaceManager = new XmlNamespaceManager(xpnav.NameTable);
                    // add the DevInterop.Web.Services to the collection of namespaces
                    namespaceManager.AddNamespace("dm", ValidationNamespaces.DevInterop);
                    // compile an XPath expression that will find all of the
                    // namespace bindings in the extensibility element
                    XPathExpression exp = xpnav.Compile("/dm:validationNS/dm:namespaces/dm:namespace");
                    // add the namespace to the expression
                    exp.SetContext(namespaceManager);
                    // find all of the namespace bindings
                    XPathNodeIterator itr = xpnav.Select(exp);
                    // iterate through all of the namespace bindings
                    // that were found
                    while (itr.MoveNext())
                    {
                        // clone the iterator so it is not moved while you look
                        // for parts of the namespace binding
                        XPathNodeIterator assert = itr.Clone();
                        // first child of the binding is the prefix
                        assert.Current.MoveToFirstChild();
                        // create an AssertNamspaceBindingAttribute to be inserted into the code dom
                        CodeAttributeDeclaration attr = new CodeAttributeDeclaration(typeof(AssertNamespaceBindingAttribute).FullName);
                        // make the argurments for the AssertNamespaceBindingAttribute
                        CodeAttributeArgument arg =
                            new CodeAttributeArgument(string.Empty,
                                                      new CodePrimitiveExpression(assert.Current.Value));
                        // add the first argument, that is the prefix

                        attr.Arguments.Add(arg);
                        // move to the next sibling of the prefix, that is the namespace uri itself
                        assert.Current.MoveToNext();
                        // build an argument out of the namespace uri
                        arg =
                            new CodeAttributeArgument(string.Empty,
                                                      new CodePrimitiveExpression(assert.Current.Value));
                        // add the namespace uri as the second argument of the constructor
                        attr.Arguments.Add(arg);
                        // add this AssertNamespaceBindingAttribute to the class
                        importer.CodeTypeDeclaration.CustomAttributes.Add(attr);
                    }
                }
                // keep method count up to date
                MethodPos++;
            }
            // get binding for method being processed
            OperationBinding methodBinding = importer.OperationBinding;
            // now see if it has a validation extensibility element from the DevInterop.Web.Services namespace
            XmlElement validationExtensibity =
                methodBinding.Input.Extensions.Find("validation", ValidationNamespaces.DevInterop);

            if (null != validationExtensibity)
            {
                // if there was an extensibilty element, process it
                // turn extensibility element into XPathDocument so
                // you can use XPath to find the parts of it you want.
                XPathDocument xpdoc = new XPathDocument(new XmlNodeReader(validationExtensibity));
                // make a navigator to look things up
                XPathNavigator xpnav = xpdoc.CreateNavigator();
                // make a namespace manager for the XPath expressions
                XmlNamespaceManager namespaceManager = new XmlNamespaceManager(xpnav.NameTable);
                // add the DevInterop.Web.Services namespac to it
                namespaceManager.AddNamespace("dm", ValidationNamespaces.DevInterop);
                // make an XPath expression that can be used to look for
                // asserts in the extensibilty element
                XPathExpression expression = xpnav.Compile("/dm:validation/dm:assertions/dm:assert");
                // add namespace to XPath expression
                expression.SetContext(namespaceManager);
                // make an XPath expression that can be evaluated to see
                // if schema validation is enabled
                XPathExpression validate = xpnav.Compile("/dm:validation/@SchemaValidation='true'");
                // add the namepaces to the validate XPath expression
                validate.SetContext(namespaceManager);
                // build a attribute that can be used to add a Validation attribute
                CodeAttributeDeclaration validateAttr = new CodeAttributeDeclaration(typeof(ValidationAttribute).FullName);
                // build argument for the validation attribute
                CodeAttributeArgument schemaArg =
                    new CodeAttributeArgument("SchemaValidation",
                                              // evaluate the validation
                                              new CodePrimitiveExpression((bool)xpnav.Evaluate(validate)));
                // added the arguement to the validation attribute, this
                // determines whether or not shchema validation is done
                validateAttr.Arguments.Add(schemaArg);
                // add the attribute to the method
                metadata.Add(validateAttr);
                // now find all of the asserts in the extensibilty element
                XPathNodeIterator pathNodeIterator = xpnav.Select(expression);
                // iterate through all of them
                while (pathNodeIterator.MoveNext())
                {
                    // clone the iterator so it is not changed while looking for its parts
                    XPathNodeIterator assert = pathNodeIterator.Clone();
                    // move to the first child, this is the XPath expression itself
                    assert.Current.MoveToFirstChild();
                    // create an AssertAttribute
                    CodeAttributeDeclaration attr = new CodeAttributeDeclaration(typeof(AssertAttribute).FullName);
                    // create an argument for the AssertAttribute constructor
                    CodeAttributeArgument arg =
                        new CodeAttributeArgument(string.Empty,
                                                  // use the XPath expression string as the first argument
                                                  new CodePrimitiveExpression(assert.Current.Value));
                    // add the first argument to the constructor
                    attr.Arguments.Add(arg);
                    // move to the next sibling of the xpath expression,
                    // that is the message to be passed back if the
                    // assert is not true
                    assert.Current.MoveToNext();
                    // now create an argument for the second parameter of
                    // the AssertAttribute constructor
                    arg =
                        new CodeAttributeArgument(string.Empty,
                                                  // use the error message itself as the second argument value
                                                  new CodePrimitiveExpression(assert.Current.Value));
                    // add the second argument to the constructor
                    attr.Arguments.Add(arg);
                    // add the AssertAttribute to the method
                    metadata.Add(attr);
                }
            }
        }
Esempio n. 3
0
 protected abstract void GenerateAttributeDeclarationsEnd(CodeAttributeDeclarationCollection attributes);
Esempio n. 4
0
 //[EnumMember(Value = "flash")]
 private static void AddEnumMemberAttribute(CodeAttributeDeclarationCollection attributes, string name)
 {
     attributes.Add(new CodeAttributeDeclaration("EnumMember", new CodeAttributeArgument("Value", new CodePrimitiveExpression(name))));
 }
	public void AddRange(CodeAttributeDeclarationCollection value) {}
Esempio n. 6
0
 private void GenerateAttributeDeclarationsEnd(CodeAttributeDeclarationCollection attributes)
 {
     Output.Write("]");
 }
Esempio n. 7
0
        public void AddElementMemberAttributes(XmlTypeMapMemberElement member, string defaultNamespace, CodeAttributeDeclarationCollection attributes, bool forceUseMemberName)
        {
            TypeData defaultType   = member.TypeData;
            bool     addAlwaysAttr = false;

            if (member is XmlTypeMapMemberFlatList)
            {
                defaultType   = defaultType.ListItemTypeData;
                addAlwaysAttr = true;
            }

            foreach (XmlTypeMapElementInfo einfo in member.ElementInfo)
            {
                if (ExportExtraElementAttributes(attributes, einfo, defaultNamespace, defaultType))
                {
                    continue;
                }

                GenerateElementInfoMember(attributes, member, einfo, defaultType, defaultNamespace, addAlwaysAttr, forceUseMemberName);
                if (einfo.MappedType != null)
                {
                    ExportMapCode(einfo.MappedType);
                    RemoveInclude(einfo.MappedType);
                }
            }

            GenerateElementMember(attributes, member);
        }
Esempio n. 8
0
 public static void AddExcludeFromCodeCoverage(this CodeAttributeDeclarationCollection attributes)
 {
     attributes.Add(new CodeAttributeDeclaration("System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage"));
 }
Esempio n. 9
0
        private void GenerateAttributes(CodeAttributeDeclarationCollection attributes, string prefix, bool inLine)
        {
            if (attributes.Count == 0) return;
            IEnumerator en = attributes.GetEnumerator();
            bool paramArray = false;

            while (en.MoveNext())
            {
                // we need to convert paramArrayAttribute to params keyword to
                // make csharp compiler happy. In addition, params keyword needs to be after
                // other attributes.

                CodeAttributeDeclaration current = (CodeAttributeDeclaration)en.Current;

                if (current.Name.Equals("system.paramarrayattribute", StringComparison.OrdinalIgnoreCase))
                {
                    paramArray = true;
                    continue;
                }

                GenerateAttributeDeclarationsStart(attributes);
                if (prefix != null)
                {
                    Output.Write(prefix);
                }

                if (current.AttributeType != null)
                {
                    Output.Write(GetTypeOutput(current.AttributeType));
                }
                Output.Write("(");

                bool firstArg = true;
                foreach (CodeAttributeArgument arg in current.Arguments)
                {
                    if (firstArg)
                    {
                        firstArg = false;
                    }
                    else
                    {
                        Output.Write(", ");
                    }

                    OutputAttributeArgument(arg);
                }

                Output.Write(")");
                GenerateAttributeDeclarationsEnd(attributes);
                if (inLine)
                {
                    Output.Write(" ");
                }
                else
                {
                    Output.WriteLine();
                }
            }

            if (paramArray)
            {
                if (prefix != null)
                {
                    Output.Write(prefix);
                }
                Output.Write("params");

                if (inLine)
                {
                    Output.Write(" ");
                }
                else
                {
                    Output.WriteLine();
                }
            }
        }
Esempio n. 10
0
 public void AddAttributeMemberAttributes(XmlTypeMapMemberAttribute attinfo, string defaultNamespace, CodeAttributeDeclarationCollection attributes, bool forceUseMemberName)
 {
     GenerateAttributeMember(attributes, attinfo, defaultNamespace, forceUseMemberName);
 }
Esempio n. 11
0
 private void GenerateAttributes(CodeAttributeDeclarationCollection attributes, string prefix)
 {
     GenerateAttributes(attributes, prefix, false);
 }
Esempio n. 12
0
 private void GenerateAttributes(CodeAttributeDeclarationCollection attributes)
 {
     GenerateAttributes(attributes, null, false);
 }
Esempio n. 13
0
 private void GenerateAttributeDeclarationsStart(CodeAttributeDeclarationCollection attributes)
 {
     Output.Write("[");
 }
	internal void OutputAttributeDeclarations
				(String prefix, CodeAttributeDeclarationCollection attributes)
			{
				if(attributes.Count == 0)
				{
					return;
				}
				bool first = true;
				bool first2;
				CodeAttributeArgumentCollection args;
				GenerateAttributeDeclarationsStart(attributes);
				foreach(CodeAttributeDeclaration attr in attributes)
				{
					if(!first)
					{
						ContinueOnNewLine(", ");
					}
					else
					{
						first = false;
					}
					if(prefix != null)
					{
						Output.Write(prefix);
					}
					Output.Write(attr.Name);
					args = attr.Arguments;
					if(args.Count != 0)
					{
						Output.Write("(");
						first2 = true;
						foreach(CodeAttributeArgument arg in args)
						{
							if(!first2)
							{
								Output.Write(", ");
							}
							else
							{
								first2 = false;
							}
							OutputAttributeArgument(arg);
						}
						Output.Write(")");
					}
				}
				GenerateAttributeDeclarationsEnd(attributes);
			}
Esempio n. 15
0
 public void AddArrayAttributes(CodeAttributeDeclarationCollection attributes, XmlTypeMapMemberElement member, string defaultNamespace, bool forceUseMemberName)
 {
     GenerateArrayElement(attributes, member, defaultNamespace, forceUseMemberName);
 }
Esempio n. 16
0
        // CodeAttributeDeclarationCollection
        public void CodeAttributeDeclarationCollectionExample()
        {
            //<Snippet1>
            //<Snippet2>
            // Creates an empty CodeAttributeDeclarationCollection.
            CodeAttributeDeclarationCollection collection = new CodeAttributeDeclarationCollection();

            //</Snippet2>

            //<Snippet3>
            // Adds a CodeAttributeDeclaration to the collection.
            collection.Add(new CodeAttributeDeclaration("DescriptionAttribute", new CodeAttributeArgument(new CodePrimitiveExpression("Test Description"))));
            //</Snippet3>

            //<Snippet4>
            // Adds an array of CodeAttributeDeclaration objects
            // to the collection.
            CodeAttributeDeclaration[] declarations = { new CodeAttributeDeclaration(), new CodeAttributeDeclaration() };
            collection.AddRange(declarations);

            // Adds a collection of CodeAttributeDeclaration objects
            // to the collection.
            CodeAttributeDeclarationCollection declarationsCollection = new CodeAttributeDeclarationCollection();

            declarationsCollection.Add(new CodeAttributeDeclaration("DescriptionAttribute", new CodeAttributeArgument(new CodePrimitiveExpression("Test Description"))));
            declarationsCollection.Add(new CodeAttributeDeclaration("BrowsableAttribute", new CodeAttributeArgument(new CodePrimitiveExpression(true))));
            collection.AddRange(declarationsCollection);
            //</Snippet4>

            //<Snippet5>
            // Tests for the presence of a CodeAttributeDeclaration in
            // the collection, and retrieves its index if it is found.
            CodeAttributeDeclaration testdeclaration = new CodeAttributeDeclaration("DescriptionAttribute", new CodeAttributeArgument(new CodePrimitiveExpression("Test Description")));
            int itemIndex = -1;

            if (collection.Contains(testdeclaration))
            {
                itemIndex = collection.IndexOf(testdeclaration);
            }
            //</Snippet5>

            //<Snippet6>
            // Copies the contents of the collection, beginning at index 0,
            // to the specified CodeAttributeDeclaration array.
            // 'declarations' is a CodeAttributeDeclaration array.
            collection.CopyTo(declarations, 0);
            //</Snippet6>

            //<Snippet7>
            // Retrieves the count of the items in the collection.
            int collectionCount = collection.Count;

            //</Snippet7>

            //<Snippet8>
            // Inserts a CodeAttributeDeclaration at index 0 of the collection.
            collection.Insert(0, new CodeAttributeDeclaration("DescriptionAttribute", new CodeAttributeArgument(new CodePrimitiveExpression("Test Description"))));
            //</Snippet8>

            //<Snippet9>
            // Removes the specified CodeAttributeDeclaration from
            // the collection.
            CodeAttributeDeclaration declaration = new CodeAttributeDeclaration("DescriptionAttribute", new CodeAttributeArgument(new CodePrimitiveExpression("Test Description")));

            collection.Remove(declaration);
            //</Snippet9>

            //<Snippet10>
            // Removes the CodeAttributeDeclaration at index 0.
            collection.RemoveAt(0);
            //</Snippet10>
            //</Snippet1>
        }
Esempio n. 17
0
 protected virtual void GenerateClassInclude(CodeAttributeDeclarationCollection attributes, XmlTypeMapping map)
 {
 }
 protected override void GenerateAttributeDeclarationsStart(CodeAttributeDeclarationCollection attributes)
 {
     Output.WriteLine("[CodeAttributeDeclarationCollection: {0}]", attributes.ToString());
 }
Esempio n. 19
0
 protected virtual void GenerateAttributeMember(CodeAttributeDeclarationCollection attributes, XmlTypeMapMemberAttribute attinfo, string defaultNamespace, bool forceUseMemberName)
 {
 }
Esempio n. 20
0
 protected abstract void GenerateAttributeDeclarationsEnd(CodeAttributeDeclarationCollection attributes);
Esempio n. 21
0
 protected virtual void GenerateElementInfoMember(CodeAttributeDeclarationCollection attributes, XmlTypeMapMemberElement member, XmlTypeMapElementInfo einfo, TypeData defaultType, string defaultNamespace, bool addAlwaysAttr, bool forceUseMemberName)
 {
 }
Esempio n. 22
0
 protected override void GenerateAttributeDeclarationsEnd(CodeAttributeDeclarationCollection attributes)
 {
 }
Esempio n. 23
0
 protected virtual void GenerateElementMember(CodeAttributeDeclarationCollection attributes, XmlTypeMapMemberElement member)
 {
 }
Esempio n. 24
0
 //[JsonProperty("extension")]
 private static void AddJsonPropertyAttritbute(CodeAttributeDeclarationCollection attributes, string name)
 {
     attributes.Add(new CodeAttributeDeclaration("JsonProperty", new CodeAttributeArgument(new CodePrimitiveExpression(name))));
 }
Esempio n. 25
0
 protected virtual void GenerateArrayElement(CodeAttributeDeclarationCollection attributes, XmlTypeMapMemberElement member, string defaultNamespace, bool forceUseMemberName)
 {
 }
Esempio n. 26
0
 static void PopulateCustomAttributes(ICustomAttributeProvider type,
                                      CodeAttributeDeclarationCollection attributes,
                                      HashSet <string> excludeAttributes)
 {
     PopulateCustomAttributes(type, attributes, ctr => ctr, excludeAttributes);
 }
Esempio n. 27
0
 protected virtual void GenerateArrayItemAttributes(CodeAttributeDeclarationCollection attributes, ListMap listMap, TypeData type, XmlTypeMapElementInfo ainfo, string defaultName, string defaultNamespace, int nestingLevel)
 {
 }
Esempio n. 28
0
 /// <include file='doc\SoapCodeExporter.uex' path='docs/doc[@for="SoapCodeExporter.AddMappingMetadata1"]/*' />
 /// <devdoc>
 ///    <para>[To be supplied.]</para>
 /// </devdoc>
 internal void AddMappingMetadata(CodeAttributeDeclarationCollection metadata, XmlMemberMapping member)
 {
     AddMemberMetadata(metadata, member.Mapping, false);
 }
Esempio n. 29
0
 protected virtual void GenerateTextElementAttribute(CodeAttributeDeclarationCollection attributes, XmlTypeMapElementInfo einfo, TypeData defaultType)
 {
 }
	// Output attribute declarations.
	protected virtual void OutputAttributeDeclarations
				(CodeAttributeDeclarationCollection attributes)
			{
				OutputAttributeDeclarations(null, attributes);
			}
Esempio n. 31
0
 protected virtual void GenerateUnnamedAnyElementAttribute(CodeAttributeDeclarationCollection attributes, XmlTypeMapElementInfo einfo, string defaultNamespace)
 {
 }
        public static CodeTypeReference GetCodegenType(CodeTypeDeclaration target, Schema schema, string name, out CodeAttributeDeclarationCollection attributes, out CodeExpression defaultValue)
        {
            var codegenType = CodegenTypeFactory.MakeCodegenType(name, schema);

            attributes   = codegenType.Attributes;
            defaultValue = codegenType.DefaultValue;
            target.Members.AddRange(codegenType.AdditionalMembers);

            return(codegenType.CodeType);
        }
Esempio n. 33
0
 public static CodeAttributeDeclaration Find(this CodeAttributeDeclarationCollection attributes, params string[] attributeTypes)
 {
     return(attributes.Cast <CodeAttributeDeclaration>().FirstOrDefault(attribute => attributeTypes.Contains(attribute.AttributeType.BaseType)));
 }
Esempio n. 34
0
 public void AddMappingMetadata(CodeAttributeDeclarationCollection metadata, XmlMemberMapping member, string ns)
 {
     AddMappingMetadata(metadata, member, ns, false);
 }
        private CodeTypeDeclaration CreateThisAssemblyClass()
        {
            var thisAssembly = new CodeTypeDeclaration("ThisAssembly")
            {
                IsClass        = true,
                IsPartial      = true,
                TypeAttributes = TypeAttributes.NotPublic | TypeAttributes.Sealed,
            };

            var codeAttributeDeclarationCollection = new CodeAttributeDeclarationCollection();

            codeAttributeDeclarationCollection.Add(new CodeAttributeDeclaration("System.CodeDom.Compiler.GeneratedCode",
                                                                                new CodeAttributeArgument(new CodePrimitiveExpression(GeneratorName)),
                                                                                new CodeAttributeArgument(new CodePrimitiveExpression(GeneratorVersion))));
            thisAssembly.CustomAttributes = codeAttributeDeclarationCollection;

            // CodeDOM doesn't support static classes, so hide the constructor instead.
            thisAssembly.Members.Add(new CodeConstructor {
                Attributes = MemberAttributes.Private
            });

            // Determine information about the public key used in the assembly name.
            string publicKey, publicKeyToken;
            bool   hasKeyInfo = this.TryReadKeyInfo(out publicKey, out publicKeyToken);

            // Define the constants.
            thisAssembly.Members.AddRange(CreateFields(new Dictionary <string, string>
            {
                { "AssemblyVersion", this.AssemblyVersion },
                { "AssemblyFileVersion", this.AssemblyFileVersion },
                { "AssemblyInformationalVersion", this.AssemblyInformationalVersion },
                { "AssemblyName", this.AssemblyName },
                { "AssemblyTitle", this.AssemblyTitle },
                { "AssemblyProduct", this.AssemblyProduct },
                { "AssemblyCopyright", this.AssemblyCopyright },
                { "AssemblyCompany", this.AssemblyCompany },
                { "AssemblyConfiguration", this.AssemblyConfiguration },
                { "GitCommitId", this.GitCommitId },
            }).ToArray());
            thisAssembly.Members.AddRange(CreateFields(new Dictionary <string, bool>
            {
                { "IsPublicRelease", this.PublicRelease },
                { "IsPrerelease", !string.IsNullOrEmpty(this.PrereleaseVersion) },
            }).ToArray());

            if (long.TryParse(this.GitCommitDateTicks, out long gitCommitDateTicks))
            {
                thisAssembly.Members.AddRange(CreateCommitDateProperty(gitCommitDateTicks).ToArray());
            }

            if (hasKeyInfo)
            {
                thisAssembly.Members.AddRange(CreateFields(new Dictionary <string, string>
                {
                    { "PublicKey", publicKey },
                    { "PublicKeyToken", publicKeyToken },
                }).ToArray());
            }

            // These properties should be defined even if they are empty.
            thisAssembly.Members.Add(CreateField("RootNamespace", this.RootNamespace));

            return(thisAssembly);
        }
Esempio n. 36
0
 public static void Add(this CodeAttributeDeclarationCollection collection, Type type)
 {
     collection.Add(new CodeAttributeDeclaration(new CodeTypeReference(type)));
 }
 void AddCustomAttribute(CodeAttributeDeclarationCollection attributes, Type type)
 {
     attributes.Add(new CodeAttributeDeclaration(new CodeTypeReference(type, CodeTypeReferenceOptions.GlobalReference)));
 }
	protected override void GenerateAttributeDeclarationsEnd
				(CodeAttributeDeclarationCollection attributes)
			{
				Output.Write("]");
			}
Esempio n. 39
0
        void AddCustomAttribute(CodeAttributeDeclarationCollection metadata, Type type, CodeAttributeArgument[] arguments)
        {
            CodeAttributeDeclaration attribute = new CodeAttributeDeclaration(type.FullName, arguments);

            metadata.Add(attribute);
        }
	public CodeAttributeDeclarationCollection(CodeAttributeDeclarationCollection value) {}
Esempio n. 41
0
 protected override void GenerateAttributeDeclarationsStart(CodeAttributeDeclarationCollection attributes)
 {
     Output.Write("attributeDeclarationsStart");
 }
Esempio n. 42
0
        protected virtual void OutputAttributeDeclarations(CodeAttributeDeclarationCollection attributes)
        {
            if (attributes.Count == 0) return;
            GenerateAttributeDeclarationsStart(attributes);
            bool first = true;
            foreach (CodeAttributeDeclaration current in attributes)
            {
                if (first)
                {
                    first = false;
                }
                else
                {
                    ContinueOnNewLine(", ");
                }

                Output.Write(current.Name);
                Output.Write('(');

                bool firstArg = true;
                foreach (CodeAttributeArgument arg in current.Arguments)
                {
                    if (firstArg)
                    {
                        firstArg = false;
                    }
                    else
                    {
                        Output.Write(", ");
                    }

                    OutputAttributeArgument(arg);
                }

                Output.Write(')');
            }
            GenerateAttributeDeclarationsEnd(attributes);
        }
Esempio n. 43
0
        private void ValidateAttributes(CodeAttributeDeclarationCollection attributes)
        {
            if (attributes.Count == 0) return;
            foreach (CodeAttributeDeclaration current in attributes)
            {
                ValidateTypeName(current, nameof(current.Name), current.Name);
                ValidateTypeReference(current.AttributeType);

                foreach (CodeAttributeArgument arg in current.Arguments)
                {
                    ValidateAttributeArgument(arg);
                }
            }
        }