Exemple #1
0
        /// <summary>
        ///     Gets a string representing the C#-Code for an attribute.
        /// </summary>
        /// <param name="nrAttribute">The attribute to show.</param>
        /// <param name="returnAttribute">Set to true if the attribute is taken from a return value.</param>
        /// <returns>A string representing the C#-Code for an attribute.</returns>
        private static string GetAttribute(NRAttribute nrAttribute, bool returnAttribute = false)
        {
            if (!CreateAttributes)
            {
                return("");
            }
            StringBuilder result = new StringBuilder("[");

            if (returnAttribute)
            {
                result.Append("return: ");
            }
            result.Append(string.IsNullOrWhiteSpace(nrAttribute.Namespace) || !UseNamespaces || ((KnownNamespaces != null) && KnownNamespaces.Contains(nrAttribute.Namespace)) ? "" : nrAttribute.Namespace + ".");
            result.Append(nrAttribute.Name.EndsWith("Attribute") ? nrAttribute.Name.Substring(0, nrAttribute.Name.Length - "Attribute".Length) : nrAttribute.Name);
            if ((nrAttribute.Values.Count > 0) || (nrAttribute.NamedValues.Count > 0))
            {
                result.Append("(");
                foreach (NRAttributeValue value in nrAttribute.Values)
                {
                    result.Append(GetAttributeValueString(value) + ", ");
                }
                foreach (string key in nrAttribute.NamedValues.Keys)
                {
                    result.AppendFormat("{0} = {1}, ", key, GetAttributeValueString(nrAttribute.NamedValues[key]));
                }
                result.Length -= 2;
                result.Append(")");
            }
            result.Append("]");
            return(result.ToString( ));
        }
Exemple #2
0
        /// <summary>
        /// Gets a string representing the C#-Code for an attribute.
        /// </summary>
        /// <param name="nrAttribute">The attribute to show.</param>
        /// <param name="returnAttribute">Set to true if the attribute is taken from a return value.</param>
        /// <returns>A string representing the C#-Code for an attribute.</returns>
        private static string GetAttribute(NRAttribute nrAttribute, bool returnAttribute = false)
        {
            StringBuilder result = new StringBuilder("[");

            if (returnAttribute)
            {
                result.Append("return: ");
            }
            result.Append(nrAttribute.Name.EndsWith("Attribute")
                      ? nrAttribute.Name.Substring(0, nrAttribute.Name.Length - "Attribute".Length)
                      : nrAttribute.Name);
            if (nrAttribute.Values.Count > 0 || nrAttribute.NamedValues.Count > 0)
            {
                result.Append("(");
                foreach (NRAttributeValue value in nrAttribute.Values)
                {
                    result.Append(GetAttributeValueString(value) + ", ");
                }
                foreach (string key in nrAttribute.NamedValues.Keys)
                {
                    result.AppendFormat("{0} = {1}, ", key, GetAttributeValueString(nrAttribute.NamedValues[key]));
                }
                result.Length -= 2;
                result.Append(")");
            }
            result.Append("]");
            return(result.ToString());
        }
Exemple #3
0
        /// <summary>
        /// Visit a <see cref="NRAttribute"/>.
        /// </summary>
        /// <param name="nrAttribute">The <see cref="NRAttribute"/> to visit.</param>
        public void Visit(NRAttribute nrAttribute)
        {
            string attribute = nrAttribute.Declaration();

            if (!string.IsNullOrWhiteSpace(attribute))
            {
                OutputLine(attribute);
            }
        }
Exemple #4
0
 /// <summary>
 ///     Determines if an attribute will be reflected.
 /// </summary>
 /// <param name="nrAttribute">The attribute to test.</param>
 /// <returns><c>True</c> if the attribute should be reflected.</returns>
 public bool Reflect(NRAttribute nrAttribute)
 {
     if (Filter.Reflect(nrAttribute))
     {
         ReflectedAttributes++;
         return(true);
     }
     IgnoredAttributes++;
     return(false);
 }
 /// <summary>
 /// Visit a <see cref="NRAttribute"/>.
 /// </summary>
 /// <param name="nrAttribute">The <see cref="NRAttribute"/> to visit.</param>
 public void Visit(NRAttribute nrAttribute)
 {
     OutputLine("NRAttribute");
     indent++;
     OutputLine("Name: " + nrAttribute.Name);
     foreach (NRAttributeValue nrAttributeValue in nrAttribute.Values)
     {
         OutputLine("Value: " + nrAttributeValue.Value + " : " + nrAttributeValue.Type);
     }
     foreach (string key in nrAttribute.NamedValues.Keys)
     {
         OutputLine("NamedValue " + key + ": " + nrAttribute.NamedValues[key].Value + " : " + nrAttribute.NamedValues[key].Type);
     }
     indent--;
 }
 /// <summary>
 /// Determines if an attribute will be reflected.
 /// </summary>
 /// <param name="nrAttribute">The attribute to test.</param>
 /// <returns><c>True</c> if the attribute should be reflected.</returns>
 public bool Reflect(NRAttribute nrAttribute)
 {
     return(IsUnsafePointer(nrAttribute.Name) ? false : filter.Reflect(nrAttribute));
 }
 public bool Reflect(NRAttribute nrAttribute)
 {
   return filter.Reflect(nrAttribute); // TODO: improve
 }
Exemple #8
0
 /// <summary>
 ///     Gets the <see cref="NRAttribute" /> as a C# string.
 /// </summary>
 /// <param name="attribute">The <see cref="NRAttribute" /> to convert.</param>
 /// <param name="returnAttribute">Set to true if the attribute is taken from a return value.</param>
 /// <returns>The <see cref="NRAttribute" /> as a string.</returns>
 public static string Declaration(this NRAttribute attribute, bool returnAttribute = false)
 {
     return(GetAttribute(attribute, returnAttribute));
 }
Exemple #9
0
 /// <summary>
 ///     Determines if an attribute will be reflected.
 /// </summary>
 /// <param name="nrAttribute">The attribute to test.</param>
 /// <returns><c>True</c> if the attribute should be reflected.</returns>
 public bool Reflect(NRAttribute nrAttribute)
 {
     return(Rules.Any(filterRule => filterRule.Element == FilterElements.Attribute) | Rules.Any(filterRule => filterRule.Element == FilterElements.AllElements));
 }
Exemple #10
0
 /// <summary>
 /// Visit a <see cref="NRAttribute"/>.
 /// </summary>
 /// <param name="nrAttribute">The <see cref="NRAttribute"/> to visit.</param>
 public void Visit(NRAttribute nrAttribute)
 {
     OutputLine(GetAttribute(nrAttribute));
 }
Exemple #11
0
 /// <summary>
 ///     Determines if an attribute will be reflected.
 /// </summary>
 /// <param name="nrAttribute">The attribute to test.</param>
 /// <returns><c>True</c> if the attribute should be reflected.</returns>
 public bool Reflect(NRAttribute nrAttribute)
 {
     return(true);
 }
Exemple #12
0
 /// <summary>
 ///     Determines if an attribute will be reflected.
 /// </summary>
 /// <param name="nrAttribute">The attribute to test.</param>
 /// <returns><c>True</c> if the attribute should be reflected.</returns>
 public bool Reflect(NRAttribute nrAttribute)
 {
     return(!Filter.Reflect(nrAttribute));
 }
 /// <summary>
 /// Determines if an attribute will be reflected.
 /// </summary>
 /// <param name="nrAttribute">The attribute to test.</param>
 /// <returns>
 /// <c>False</c> since NClass don't know attributes.
 /// </returns>
 public bool Reflect(NRAttribute nrAttribute)
 {
     return(false);
 }