public ReferenceAliasManager() { if (!typeof(T).IsEnum) { throw new InvalidOperationException("T must be an enumerated type"); } // Load all default ReferenceAlias foreach (T alias in Enum.GetValues(typeof(T))) { ReferenceAlias <T> referenceAlias = ReferenceAliasAttribute.Get <T>(alias); if (referenceAlias == null) { continue; } _referenceAliases.Add(alias, referenceAlias); } // Execute enum custom initialization if defined ReferenceAliasInitAttribute attr = typeof(T).GetCustomAttributes(typeof(ReferenceAliasInitAttribute), true).FirstOrDefault() as ReferenceAliasInitAttribute; if (attr != null) { attr.Invoke(typeof(T), this); } }
/// <summary> /// Main AddReference method called by extensions. /// This one is using aliasValue and call the proper add reference for sharpmake projet /// </summary> /// <param name="aliasValue"></param> /// <param name="conf"></param> /// <param name="target"></param> /// <param name="project"></param> public virtual void AddReference(T aliasValue, Project.Configuration conf, ITarget target, Project project) { if (!_referenceAliases.ContainsKey(aliasValue)) { // If aliasValue not defined and we have a FallbackAction, call it ! if (FallbackAction != null) { FallbackAction(aliasValue, conf, target, project); return; } throw new InvalidOperationException(string.Format("{0} reference is not defined in enum {1}", aliasValue, typeof(T).FullName)); } ReferenceAlias <T> reference = _referenceAliases[aliasValue]; if (reference.Type != null) { if (target == null) { throw new ArgumentNullException(nameof(target), string.Format("You need to specify target when adding {0} reference", aliasValue)); } if (reference.PublicReference) { conf.AddPublicDependency(target, reference.Type); } else { conf.AddPrivateDependency(target, reference.Type); } } else if (reference.Nuget != null && !reference.Nuget.Equals(default(Tuple <string, string>)) && !string.IsNullOrEmpty(reference.Nuget.Item1) && !string.IsNullOrEmpty(reference.Nuget.Item2)) { conf.ReferencesByNuGetPackage.Add(reference.Nuget.Item1, reference.Nuget.Item2); } else if (reference.Paths != null && reference.Paths.Any()) { foreach (string path in reference.Paths.Where(p => !string.IsNullOrEmpty(p))) { string filePath = Path.IsPathRooted(path) ? path : $"{BaseFilePath}\\{path}"; conf.ReferencesByPath.Add(filePath); } } else if (reference.CustomAction != null) { reference.CustomAction(aliasValue, conf, target, project); } else { throw new InvalidOperationException(string.Format("{0} reference found but not properly defined in enum {1}", aliasValue, typeof(T).FullName)); } }
public static ReferenceAlias <T> Get <T>(object enumValue) where T : struct, IConvertible { if (enumValue == null) { return(null); } MemberInfo[] mi = typeof(T).GetMember(enumValue.ToString()); if (mi.Length <= 0) { return(null); } ReferenceAliasAttribute attr = Attribute.GetCustomAttribute(mi[0], typeof(ReferenceAliasAttribute)) as ReferenceAliasAttribute; if (attr == null) { return(null); } return(ReferenceAlias <T> .FromAttribute(attr)); }
public void Set(T aliasValue, Action <T, Project.Configuration, ITarget, Project> customAction) { _referenceAliases.Add(aliasValue, ReferenceAlias <T> .FromCustomAction(customAction)); }
public void Set(T aliasValue, params string[] paths) { _referenceAliases.Add(aliasValue, ReferenceAlias <T> .FromPaths(paths)); }
public void Set(T aliasValue, Tuple <string, string> nuget) { _referenceAliases.Add(aliasValue, ReferenceAlias <T> .FromNuget(nuget)); }
public void Set(T aliasValue, Type type, bool publicReference = true) { _referenceAliases.Add(aliasValue, ReferenceAlias <T> .FromType(type, publicReference)); }