/*
* QUANTCONNECT.COM - Democratizing Finance, Empowering Individuals.
* Lean Algorithmic Trading Engine v2.0. Copyright 2014 QuantConnect Corporation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
using System;
using System.Linq;
using Newtonsoft.Json;
using System.Reflection;
namespace QuantConnect
{
///
/// Custom attribute used for documentation
///
[AttributeUsage(AttributeTargets.All, AllowMultiple = true)]
[DocumentationAttribute("Reference")]
public sealed class DocumentationAttribute : Attribute
{
private static readonly DocumentationAttribute Attribute =
typeof(DocumentationAttribute).GetCustomAttributes().Single();
private static readonly string BasePath =
Attribute.FileName.Substring(0, Attribute.FileName.LastIndexOf("Common", StringComparison.Ordinal));
///
/// The documentation tag
///
[JsonProperty(PropertyName = "tag")]
public string Tag { get; }
///
/// The associated weight of this attribute and tag
///
[JsonProperty(PropertyName = "weight")]
public int Weight { get; }
///
/// The associated line of this attribute
///
[JsonProperty(PropertyName = "line")]
public int Line { get; }
///
/// The associated file name of this attribute
///
[JsonProperty(PropertyName = "fileName")]
public string FileName { get; }
///
/// The attributes type id, we override it to ignore it when serializing
///
[JsonIgnore]
public override object TypeId => base.TypeId;
///
/// Creates a new instance
///
public DocumentationAttribute(string tag, int weight = 0,
[System.Runtime.CompilerServices.CallerLineNumber] int line = 0,
[System.Runtime.CompilerServices.CallerFilePath] string fileName = "")
{
Tag = tag;
Line = line;
Weight = weight;
// will be null for the attribute of DocumentationAttribute itself
if (BasePath != null)
{
FileName = fileName.Replace(BasePath, string.Empty, StringComparison.InvariantCultureIgnoreCase);
}
else
{
FileName = fileName;
}
}
}
}