示例#1
0
文件: CSharp.cs 项目: Victov/NClass
        /// <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( ));
        }
示例#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());
        }
示例#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);
            }
        }
示例#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--;
 }
示例#6
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(IsUnsafePointer(nrAttribute.Name) ? false : filter.Reflect(nrAttribute));
 }
示例#7
0
 public bool Reflect(NRAttribute nrAttribute)
 {
   return filter.Reflect(nrAttribute); // TODO: improve
 }
示例#8
0
文件: CSharp.cs 项目: Victov/NClass
 /// <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));
 }
示例#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));
 }
示例#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));
 }
示例#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);
 }
示例#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));
 }
示例#13
0
 /// <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);
 }