Example #1
0
        protected Plug(string _name, string _description, string _documentation, bool _isMultiplex, IActor actor)
        {
            DocumentationAttribute docAttribute  = new DocumentationAttribute(_description, _documentation);
            PlugAttribute          plugAttribute = new PlugAttribute(_name);

            Initialize(docAttribute, plugAttribute, _isMultiplex, actor);
        }
Example #2
0
        protected Plug(Type type, bool _isMultiplex, IActor actor)
        {
            name = type.Name;

            DocumentationAttribute _documentation = Attribute.GetCustomAttribute(type, typeof(DocumentationAttribute)) as DocumentationAttribute;
            PlugAttribute          _plug          = Attribute.GetCustomAttribute(type, typeof(PlugAttribute)) as PlugAttribute;

            Initialize(_documentation, _plug, _isMultiplex, actor);
        }
        public void JsonRoundTrip()
        {
            var documentationAttribute = new DocumentationAttribute("Tag", 1);
            var serialized             = JsonConvert.SerializeObject(documentationAttribute);

            var result = JsonConvert.DeserializeObject <DocumentationAttribute>(serialized);

            Assert.AreEqual(documentationAttribute.Tag, result.Tag);
            Assert.AreEqual(documentationAttribute.Weight, result.Weight);
        }
Example #4
0
        protected Plug(MemberInfo info, bool _isMultiplex, IActor actor)
        {
            // Store the name
            name = info.Name;

            DocumentationAttribute _documentation = Attribute.GetCustomAttribute(info, typeof(DocumentationAttribute)) as DocumentationAttribute;
            PlugAttribute          _plug          = Attribute.GetCustomAttribute(info, typeof(PlugAttribute)) as PlugAttribute;

            Initialize(_documentation, _plug, _isMultiplex, actor);
        }
        public void Constructor2TestMethod()
        {
            DocumentationAttribute _attribute = new DocumentationAttribute("name", typeof(StringGetter));

            Assert.IsNotNull(_attribute);
            Assert.AreEqual <string>("name", _attribute.Name);
            IConverterToDocumentationString _converter = _attribute.ConverterToDocumentationString;

            Assert.IsNotNull(_converter);
            Assert.AreSame(_converter.GetType(), typeof(StringGetter));
        }
Example #6
0
        public DynamicMetaObject GetDocumentation(DynamicMetaObject target)
        {
            BindingRestrictions restrictions = BindingRestrictions.GetTypeRestriction(target.Expression, target.LimitType);

            DocumentationAttribute attr = target.LimitType.GetCustomAttribute <DocumentationAttribute>();
            string documentation        = (attr != null) ? attr.Documentation : string.Empty;

            return(new DynamicMetaObject(
                       AstUtils.Constant(documentation),
                       restrictions
                       ));
        }
Example #7
0
        private Property( PropertyInfo info,IActor actor )
        {
            // Get all attributes we need.
            propertyInfo            = info;
            propertyAttribute       = Attribute.GetCustomAttribute(info, typeof(PropertyAttribute)) as PropertyAttribute;
            propertyDocumentation   = Attribute.GetCustomAttribute(info, typeof(DocumentationAttribute)) as DocumentationAttribute;
            propertyOwner           = actor;

            if (propertyDocumentation == null)
            {
                propertyDocumentation = new DocumentationAttribute();
            }
        }
Example #8
0
        private Property(PropertyInfo info, IActor actor)
        {
            // Get all attributes we need.
            propertyInfo          = info;
            propertyAttribute     = Attribute.GetCustomAttribute(info, typeof(PropertyAttribute)) as PropertyAttribute;
            propertyDocumentation = Attribute.GetCustomAttribute(info, typeof(DocumentationAttribute)) as DocumentationAttribute;
            propertyOwner         = actor;

            if (propertyDocumentation == null)
            {
                propertyDocumentation = new DocumentationAttribute();
            }
        }
Example #9
0
        protected Actor()
        {
            actorPlugs = new PlugCollection(this);

            DocumentationAttribute documentation
                = Attribute.GetCustomAttribute(this.GetType(), typeof(DocumentationAttribute)) as DocumentationAttribute;

            if (documentation != null)
            {
                actorDescription   = documentation.Description;
                actorDocumentation = documentation.Documentation;
            }
        }
Example #10
0
    public static void Main(string[] args)
    {
        System.Reflection.MemberInfo tp = typeof(Attr);
        object[] attrs =
            tp.GetCustomAttributes(typeof(DocumentationAttribute), false);
        // false means don't search ancestor classes and interfaces
        DocumentationAttribute a = (DocumentationAttribute)attrs[0];

        Console.WriteLine("author:    " + a.author);
        Console.WriteLine("date:      " + a.date);
        Console.WriteLine("revision:  " + a.revision);
        Console.WriteLine("docString: " + a.docString);
    }
        public void Constructor1TestMethod()
        {
            DocumentationAttribute _attribute = new DocumentationAttribute("name");

            Assert.IsNotNull(_attribute);
            Assert.AreEqual <string>("name", _attribute.Name);
            IConverterToDocumentationString _converter = _attribute.ConverterToDocumentationString;

            Assert.IsNotNull(_converter);
            Assert.AreSame(_converter.GetType(), typeof(StringGetter));
            TestClass _TestClass = new TestClass();

            Assert.AreEqual <string>(_TestClass.TestString, _converter.ConvertToString(_TestClass, String.Empty));
        }
Example #12
0
        void DrawDocumentationButton(Rect p_rect, Type p_type)
        {
            DocumentationAttribute documentation = p_type.GetCustomAttribute <DocumentationAttribute>();

            if (documentation != null)
            {
                if (GUI.Button(new Rect(p_rect.x + 270, p_rect.y + 7, 16, 16),
                               IconManager.GetIcon("help_icon"), GUIStyle.none))
                {
                    Application.OpenURL(
                        "https://github.com/pshtif/Dash/blob/main/Documentation/" + documentation.url);
                }
            }
        }
        public void DateTimeGetterTest()
        {
            DocumentationAttribute _attribute = new DocumentationAttribute("name", typeof(DateTimeGetter));

            Assert.IsNotNull(_attribute);
            Assert.AreEqual <string>("name", _attribute.Name);
            IConverterToDocumentationString _converter = _attribute.ConverterToDocumentationString;

            Assert.IsNotNull(_converter);
            Assert.AreSame(_converter.GetType(), typeof(DateTimeGetter));
            DateTime?_TestDate = DateTime.Today;

            Assert.AreEqual <string>(_TestDate.ToString(), _converter.ConvertToString(_TestDate, String.Empty));
            Assert.AreEqual <string>("Null date", _converter.ConvertToString(new Nullable <DateTime>(), "Null date"));
            Assert.AreEqual <string>("Null date", _converter.ConvertToString(null, "Null date"));
            Assert.AreEqual <string>("Null date", _converter.ConvertToString(new TestClass(), "Null date"));
        }
        public static HelperResult DocumentationLink <T>(this HtmlHelper <T> htmlHelper, string label)
        {
            DocumentationAttribute attribute = null;
            var viewContext = htmlHelper.ViewContext;

            var controllerDescriptor = new ReflectedControllerDescriptor(viewContext.Controller.GetType());

            var actionName       = viewContext.RouteData.Values["action"] as string;
            var actionDescriptor = controllerDescriptor
                                   .GetCanonicalActions()
                                   .Where(x => String.Equals(x.ActionName, actionName, StringComparison.OrdinalIgnoreCase))
                                   .FirstOrDefault();

            if (actionDescriptor != null)
            {
                attribute = actionDescriptor
                            .GetCustomAttributes(typeof(DocumentationAttribute), true)
                            .Cast <DocumentationAttribute>()
                            .FirstOrDefault();
            }

            if (attribute == null)
            {
                attribute = controllerDescriptor
                            .GetCustomAttributes(typeof(DocumentationAttribute), true)
                            .Cast <DocumentationAttribute>()
                            .FirstOrDefault();
            }

            var link = attribute == null
                ? BaseUrl
                : string.Format("{0}{1}", BaseUrl, attribute.DocumentPath);

            return(new HelperResult(writer =>
            {
                var builder = new TagBuilder("a");
                builder.MergeAttribute("href", link);
                builder.MergeAttribute("target", "_blank");
                writer.Write(builder.ToString(TagRenderMode.StartTag));
                writer.Write(label);
                writer.Write(builder.ToString(TagRenderMode.EndTag));
            }));
        }
Example #15
0
        /// <summary>
        /// Gets the documentation.
        /// </summary>
        /// <param name="o">The object</param>
        /// <returns></returns>
        private static Dictionary <string, string> GetDocumentation(object o)
        {
            Dictionary <string, string> listOfRowFields = new Dictionary <string, string>();

            foreach (System.Reflection.PropertyInfo el in o.GetType().GetProperties())
            {
                object[] attributes = (el.GetCustomAttributes(typeof(DocumentationAttribute), true));
                if (attributes.Length > 0)
                {
                    string val = string.Empty;
                    foreach (object at in attributes)
                    {
                        DocumentationAttribute dat = at as DocumentationAttribute;
                        val = dat.ConverterToDocumentationString.ConvertToString(el.GetValue(o, null), dat.DefaultValue);
                        listOfRowFields.Add(dat.Name, val);
                    }
                }
            }
            return(listOfRowFields);
        }
Example #16
0
        public static string DocOneInfo(MethodBase info, string name, bool includeSelf)
        {
            // Look for methods tagged with [Documentation("doc string for foo")]
            object[] attrs = info.GetCustomAttributes(typeof(DocumentationAttribute), false);
            if (attrs.Length > 0)
            {
                Debug.Assert(attrs.Length == 1);
                DocumentationAttribute doc = attrs[0] as DocumentationAttribute;
                return(doc.Documentation);
            }

            string defaultDoc = GetDefaultDocumentation(name);

            if (defaultDoc != null)
            {
                return(defaultDoc);
            }

            return(CreateAutoDoc(info, name, 0, includeSelf));
        }
Example #17
0
        private void Initialize(DocumentationAttribute _documentation,
                                PlugAttribute _plug,
                                bool _isMultiplex,
                                IActor actor)
        {
            owner       = actor;
            isMultiplex = _isMultiplex;

            if (_plug != null)
            {
                if (_plug.Name != string.Empty)
                {
                    name = _plug.Name;
                }
            }

            // Store the documentation.
            documentationAttribute = _documentation;

            if (documentationAttribute == null)
            {
                documentationAttribute = new DocumentationAttribute();
            }
        }
        public void ConstructorWithStringParameterTest()
        {
            var item = new DocumentationAttribute("abs");

            Assert.AreEqual("abs", item.DocumentationBody);
        }