public override void OnGUI(Rect position, SerializedProperty property, GUIContent label) { AliasAttribute aliasAttribute = (AliasAttribute)attribute; label.text = aliasAttribute.Alias; EditorGUI.PropertyField(position, property, label, true); }
internal void Load(params Type[] builtIns) { ParameterExpression localEnv = Expression.Parameter(typeof(LispEnvironment), "env"); ParameterExpression args = Expression.Parameter(typeof(LispList), "args"); foreach (var builtIn in builtIns) { var methodInfos = builtIn.GetMethods(); foreach (var methodInfo in methodInfos) { if (methodInfo.IsStatic) { var method = Expression.Call(methodInfo, args, localEnv); var lambda = Expression.Lambda <Func <LispList, LispEnvironment, dynamic> >(method, args, localEnv); var cLambda = lambda.Compile(); if (methodInfo.GetCustomAttributes(typeof(AliasAttribute), false).Any()) { foreach (var attribute in methodInfo.GetCustomAttributes(typeof(AliasAttribute), false)) { AliasAttribute attr = (AliasAttribute)attribute; Add(new LispSymbol(attr.Alias), cLambda, builtIn.Name + "." + methodInfo.Name); } } else { Add(new LispSymbol(methodInfo.Name), cLambda, builtIn.Name + "." + methodInfo.Name); } } } } }
private string GetName(ICustomAttributeProvider attributeProvider) { AliasAttribute aliasAttr = attributeProvider.GetCustomAttributes(typeof(AliasAttribute), true) .FirstOrDefault() as AliasAttribute; return(aliasAttr?.Alias); }
public static void Alias_PropertyGet_MatchesCtorArgument() { const string aliasValue = "test"; var aliasAttr = new AliasAttribute(aliasValue); Assert.That(aliasAttr.Alias, Is.EqualTo(aliasValue)); }
protected override Expression VisitMember(MemberExpression m) { if (m.Expression != null && m.Expression.NodeType == ExpressionType.Parameter) { AliasAttribute alias = m.Member.GetCustomAttribute <AliasAttribute>(); var field = alias?.Name ?? m.Member.Name; if (_aliasMapper != null) { string mapper = _aliasMapper[_fieldMapper.Count]; if (mapper.Equals(field)) { _fieldMapper.Add(field); } else { _fieldMapper.Add($"{field} AS {mapper}"); } } else { _fieldMapper.Add(field); } return(m); } throw new NotSupportedException(string.Format("成员{0}不支持", m.Member.Name)); }
public static string[] GetShortOptionNames(this IConventions conventions, AliasAttribute aliasAttribute) { return(aliasAttribute .Aliases .Select(conventions.GetShortOptionName) .ToArray()); }
/// <summary> /// Convention to get the Name of the PropertyType from the AliasAttribute or the property itself /// </summary> /// <param name="attribute"></param> /// <param name="propertyName"></param> /// <returns></returns> public static string GetPropertyTypeName(AliasAttribute attribute, string propertyName) { if (attribute == null) { return(propertyName.SplitPascalCasing()); } return(string.IsNullOrEmpty(attribute.Name) ? propertyName.SplitPascalCasing() : attribute.Name); }
public void CtorTest() { AliasAttribute attr = new AliasAttribute(); Assert.Null(attr.Name); attr.Name = "a"; Assert.Equal("a", attr.Name); attr = new AliasAttribute("b"); Assert.Equal("b", attr.Name); }
private Command HandleCommandGroup(Type type) { CommandGroupAttribute commandGroupAttribute = type.GetCustomAttribute <CommandGroupAttribute>(false); AliasAttribute aliasAttribute = type.GetCustomAttribute <AliasAttribute>(false); SummaryAttribute summaryAttribute = type.GetCustomAttribute <SummaryAttribute>(false); // Get all methods that have a CommandAttribute IEnumerable <MethodInfo> methods = type.GetMethods() .Where(m => m.IsDefined(typeof(CommandAttribute), false)); // Get all nested classes with a CommandGroupAttribute IEnumerable <Type> subTypes = type.GetNestedTypes() .Where(t => t.IsDefined(typeof(CommandGroupAttribute), false)); // Default command is when a method in a group has a no name meaning its the default method to call List <Method> defaultCommandMethods = new List <Method>(); List <Command> subCommands = new List <Command>(); foreach (MethodInfo method in methods) { Command subCommand = HandleCommand(method); // Check if its the default command if (subCommand.Name == null) { // Should always be 1 method defaultCommandMethods.Add(subCommand.Methods[0]); } else { Command sameCommand = subCommands.FirstOrDefault(c => c.Name == subCommand.Name); if (sameCommand == null) { subCommands.Add(subCommand); } else { sameCommand.Methods.Add(subCommand.Methods[0]); sameCommand.Summary = sameCommand.Summary ?? subCommand.Summary; } } } foreach (Type subType in subTypes) { subCommands.Add(HandleCommandGroup(subType)); } return(new Command( name: commandGroupAttribute.Name, aliases: aliasAttribute?.Aliases, summary: summaryAttribute?.Summary, subCommands: subCommands, methods: defaultCommandMethods)); }
protected override Expression VisitMember(MemberExpression m) { if (m.Expression != null) { if (m.Expression.NodeType == ExpressionType.Parameter) { AliasAttribute alias = m.Member.GetCustomAttribute <AliasAttribute>(); if (alias != null) { this.Append(alias.Name); } else { this.Append(m.Member.Name); } return(m); } else if (m.Expression.NodeType == ExpressionType.Constant) { // 获取局部变量 var @object = ((ConstantExpression)m.Expression).Value; //这个是重点 if (m.Member.MemberType == MemberTypes.Field) { var value = ((FieldInfo)m.Member).GetValue(@object); this.Append(value); return(m); } else if (m.Member.MemberType == MemberTypes.Property) { var value = ((PropertyInfo)m.Member).GetValue(@object); this.Append(value); return(m); } } else if (m.Expression.NodeType == ExpressionType.MemberAccess) {// TODO 获取对象属性值 MemberExpression outerMember = m; PropertyInfo outerProp = (PropertyInfo)outerMember.Member; MemberExpression innerMember = (MemberExpression)outerMember.Expression; FieldInfo innerField = (FieldInfo)innerMember.Member; ConstantExpression ce = (ConstantExpression)innerMember.Expression; object innerObj = ce.Value; object outerObj = innerField.GetValue(innerObj); object value = outerProp.GetValue(outerObj, null); this.Append(value); return(m); } } throw new NotSupportedException(string.Format("成员{0}不支持", m.Member.Name)); //return base.VisitMember(m); }
public void BuildCommand(MethodInfo Method, ModuleInfo moduleInfo) { //DEBUG Type magicType = Method.DeclaringType; CommandAttribute CommandAttr = (CommandAttribute)Method.GetCustomAttribute(typeof(CommandAttribute)); Command.MainAlias = CommandAttr.Name; Command.Aliases = new List <string>(); AliasAttribute AliasAttr = (AliasAttribute)Method.GetCustomAttribute(typeof(AliasAttribute)); if (AliasAttr != null) { foreach (string alias in AliasAttr.Aliases) { Command.Aliases.Add(alias.ToLower()); } } OnlyRoleAttribute OnlyRolesAttr = (OnlyRoleAttribute)Method.GetCustomAttribute(typeof(OnlyRoleAttribute)); if (OnlyRolesAttr != null) { Command.OnlyRoles = new List <string>(); Command.OnlyRoles.AddRange(OnlyRolesAttr.Roles); } ExpectRoleAttribute expectRoleAttribute = (ExpectRoleAttribute)Method.GetCustomAttribute(typeof(ExpectRoleAttribute)); if (expectRoleAttribute != null) { Command.ExpectRoles = new List <string>(); Command.ExpectRoles.AddRange(expectRoleAttribute.Roles); } Command.Method = Method; Command.moduleInfo = moduleInfo; moduleInfo.AddCommand(Command); CommandService.RegisterCommand(Command); foreach (System.Reflection.ParameterInfo parameterinfo in Method.GetParameters()) { if (parameterinfo.ParameterType != typeof(CommandContext)) { AddParameter(parameterinfo); } } //CommandAttr. //Method.Invoke(magicClassObject, null); }
public StringBuilder CreateCommandString <T>(T data) { StringBuilder builder = new StringBuilder("INSERT INTO "); Type type = typeof(T); AliasAttribute tableAlias = typeof(T).GetCustomAttribute <AliasAttribute>(); if (tableAlias == null) { builder.AppendLine(type.Name); } else { builder.AppendLine(tableAlias.Name); } var fields = type.GetProperties().Where(u => { var value = u.GetValue(data); return(!(value == null || (bool)GetDefaultMethod.MakeGenericMethod(new[] { u.PropertyType }).Invoke(null, new object[] { value }))); }).Select(u => { var name = u.PropertyType.GetCustomAttribute <AliasAttribute>()?.Name ?? u.Name; return(new { Key = name, Value = u.Name }); }).ToArray(); builder.Append("("); builder.Append(string.Join(",", fields.Select(u => u.Key))); builder.AppendLine(")"); builder.Append(" VALUES("); builder.Append(string.Join(",", fields.Select(u => $"@{u.Value}"))); builder.Append(" );"); return(builder); }
protected override Expression VisitConstant(ConstantExpression c) { Type type = c.Value as Type; if (type == null) { throw new NotSupportedException($"尚不支持 {c.Value}"); } AliasAttribute aliasAttribute = type.GetCustomAttribute <AliasAttribute>(); if (aliasAttribute != null) { _tables.Add(aliasAttribute.Name); } else { _tables.Add(type.Name); } return(c); }
private Command HandleCommand(MethodInfo methodInfo) { if (!methodInfo.IsStatic) { throw new MethodNotStaticException(methodInfo); } if (methodInfo.ContainsGenericParameters) { throw new GenericParametersException(methodInfo); } CommandAttribute commandAttribute = methodInfo.GetCustomAttribute <CommandAttribute>(false); AliasAttribute aliasAttribute = methodInfo.GetCustomAttribute <AliasAttribute>(false); SummaryAttribute summaryAttribute = methodInfo.GetCustomAttribute <SummaryAttribute>(false); return(new Command( name: commandAttribute.Name, aliases: aliasAttribute?.Aliases, summary: summaryAttribute?.Summary, subCommands: new List <Command>(), methodInfo: methodInfo)); }
public static MethodInfo Find(string name) { Assembly assembly = Assembly.GetEntryAssembly(); foreach (Type item in assembly.GetExportedTypes()) { if (item.GetCustomAttribute <ConsoleEntryPointAttribute>() == null) { continue; } if (AliasAttribute.MatchName(item, name)) { MethodInfo result = item.GetMethod("Run", BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Static); if (result != null) { return(result); } } } return(null); }
public StringBuilder UpdateCommandString <T>(T data, IDictionary <string, object> dic) { StringBuilder builder = new StringBuilder("Update "); Type type = typeof(T); AliasAttribute tableAlias = typeof(T).GetCustomAttribute <AliasAttribute>(); if (tableAlias == null) { builder.AppendLine(type.Name); } else { builder.AppendLine(tableAlias.Name); } var fields = type.GetProperties().Where(u => { var value = u.GetValue(data); return(!(value == null || (bool)GetDefaultMethod.MakeGenericMethod(new[] { u.PropertyType }).Invoke(null, new object[] { value }))); }).Select(u => { var name = u.PropertyType.GetCustomAttribute <AliasAttribute>()?.Name ?? u.Name; dic.Add($"@{u.Name}", u.GetValue(data)); return(new { Key = name, Value = u.Name }); }).ToArray(); builder.AppendLine("SET"); builder.Append(string.Join(",", fields.Select(u => $"{u.Key}=@{u.Value}"))); return(builder); }
/// <summary> /// Convention to get the Alias of the PropertyType from the AliasAttribute or the property itself /// </summary> /// <param name="attribute"></param> /// <param name="propertyName"></param> /// <returns></returns> public static string GetPropertyTypeAlias(AliasAttribute attribute, string propertyName) { return attribute == null ? propertyName.ToUmbracoAlias() : attribute.Alias; }
public AliasOutput(AliasAttribute alias) { Alias = alias; }
public static AliasOutput ToAliasOutput(this AliasAttribute alias) => new AliasOutput(alias);
public ModuleInfo(Type type, AliasAttribute modAlias, IEnumerable <PropArg> props) { Type = type; ModuleAlias = modAlias; Props = props; }
private static object DeserializeObject(Type type, Dictionary <string, object> table) { MemberInfo[] members = type.GetMembers(BindingFlags.Instance | BindingFlags.Public); object v = Activator.CreateInstance(type); for (int i = 0; i < members.Length; i++) { MemberInfo member = members[i]; #if !NETFX_CORE MemberTypes memberType = member.MemberType; if (memberType != MemberTypes.Field && memberType != MemberTypes.Property) { continue; } #else MemberTypes memberType; if (member is PropertyInfo) { memberType = MemberTypes.Property; } else if (member is FieldInfo) { memberType = MemberTypes.Field; } else { continue; } #endif if (memberType == MemberTypes.Property && !((PropertyInfo)member).CanWrite) { continue; } object item; #if !NETFX_CORE object[] attributes = member.GetCustomAttributes(typeof(AliasAttribute), true); AliasAttribute alias = attributes.Length > 0 ? attributes[0] as AliasAttribute : null; #else IEnumerable <Attribute> attributes = member.GetCustomAttributes(typeof(AliasAttribute), true); AliasAttribute alias = null; foreach (Attribute a in attributes) { alias = a as AliasAttribute; break; } #endif if (alias == null || !alias.ignoreFieldName) { if (table.TryGetValue(member.Name, out item)) { object cv = null; Type t = memberType == MemberTypes.Field ? ((FieldInfo)member).FieldType : ((PropertyInfo)member).PropertyType; if (item is IDictionary) { cv = DeserializeObject(t, item as Dictionary <string, object>); } else if (item is IList) { cv = DeserializeArray(t, item as List <object>); } else { cv = DeserializeValue(t, item); } if (memberType == MemberTypes.Field) { ((FieldInfo)member).SetValue(v, cv); } else { ((PropertyInfo)member).SetValue(v, cv, null); } continue; } } if (alias != null) { for (int j = 0; j < alias.aliases.Length; j++) { if (table.TryGetValue(alias.aliases[j], out item)) { object cv = null; Type t = memberType == MemberTypes.Field ? ((FieldInfo)member).FieldType : ((PropertyInfo)member).PropertyType; if (item is IDictionary) { cv = DeserializeObject(t, item as Dictionary <string, object>); } else if (item is IList) { cv = DeserializeArray(t, item as List <object>); } else { cv = DeserializeValue(t, item); } if (memberType == MemberTypes.Field) { ((FieldInfo)member).SetValue(v, cv); } else { ((PropertyInfo)member).SetValue(v, cv, null); } break; } } } } return(v); }
public ConsoleWindow() { InitializeComponent(); isProgramEnded = 0; isWindowClosing = 0; resources = new ResourceDictionary(); resources.Source = new Uri("ConsoleResources.xaml", UriKind.Relative); listener = new TraceListener(this, listBoxLogs); Trace.Listeners.Add(listener); string classname = App.CommandLineArgs["class"]; programEntry = ConsoleEntryPointAttribute.Find(classname); if (programEntry == null) { Close(); return; } #region Command-Line에 입력한 인자들을 Console Program Parameter들에 맞게 변환합니다. ParameterInfo[] parameters = programEntry.GetParameters(); object[] args = new object[parameters.Length]; for (int i = 0; i < parameters.Length; i++) { foreach (KeyValuePair <string, string> item in App.CommandLineArgs) { if (AliasAttribute.MatchName(parameters[i], item.Key)) { try { args[i] = Convert.ChangeType(item.Value, parameters[i].ParameterType); } catch (FormatException) { args[i] = null; } catch (InvalidCastException) { args[i] = null; } break; } } } #endregion programThread = new Thread(() => { try { programEntry.Invoke(null, args); Interlocked.Exchange(ref isProgramEnded, 1); if (isWindowClosing == 0) { this.Dispatcher.Invoke(new Action(() => { OnProgramEnded(); })); } } catch (Exception ex) { Trace.WriteLine(ex); } }); programThread.Start(); }
public IRepositorioGenerico <T> GetRepositorio <T>() where T : class { string nombreTabla = null; string aliasTabla = null; string Uid = null; List <string> propiedadesTabla = new List <string>(); List <string> propiedadesTablaRequeridas = new List <string>(); List <string> propiedadesTablaRequeridasSoloInsert = new List <string>(); Dictionary <string, int> propiedadesTablaMaxLength = new Dictionary <string, int>(); List <PropertyInfo> relaciones1a1 = new List <PropertyInfo>(); List <PropertyInfo> relaciones1aMuchos = new List <PropertyInfo>(); PropertyInfo clavePrincipal = null; PropertyInfo propiedadInfoUid = null; Type tipoEntidad = typeof(T); TableAttribute customAttribute = tipoEntidad.GetCustomAttribute <TableAttribute>(); if (customAttribute != null) { nombreTabla = customAttribute.Name; aliasTabla = "_" + nombreTabla.Substring(0, nombreTabla.Length - 2); } AliasAttribute aliasAttribute = tipoEntidad.GetCustomAttribute <AliasAttribute>(); if (aliasAttribute != null) { aliasTabla = aliasAttribute.Nombre; } List <PropertyInfo> listInfo = tipoEntidad.GetProperties().ToList(); var listInfoPropiedadesTabla = new List <PropertyInfo>(); listInfo.ForEach((PropertyInfo p) => { if (p.GetCustomAttribute <NotMappedAttribute>() == null) { if (Uid == null && p.PropertyType.FullName.Contains("System.Guid")) { Uid = p.Name; propiedadInfoUid = p; } if (p.GetCustomAttribute <OneToOneAttribute>() != null) { relaciones1a1.Add(p); } else if (p.GetCustomAttribute <OneToManyAttribute>() != null) { relaciones1aMuchos.Add(p); } else if (p.GetCustomAttribute <KeyAttribute>() == null) { propiedadesTabla.Add(p.Name); listInfoPropiedadesTabla.Add(p); if (!p.PropertyType.FullName.Contains("hierarchyid")) { if (p.GetCustomAttribute <RequiredAttribute>() != null) { propiedadesTablaRequeridas.Add(p.Name); } if (p.GetCustomAttribute <RequiredOnlyInsertAttribute>() != null) { propiedadesTablaRequeridasSoloInsert.Add(p.Name); } var maxLen = p.GetCustomAttribute <MaxLengthAttribute>(); if (maxLen != null && maxLen.Length > 0) { propiedadesTablaMaxLength.Add(p.Name, maxLen.Length); } } } else { clavePrincipal = p; } } }); if (string.IsNullOrEmpty(nombreTabla) || clavePrincipal == null) { throw new ArgumentException("Definicion Tabla invalida. (Anotacion necesaria: Table y Key)"); } bool softDelete = propiedadesTabla.Contains(propiedadSoftDelete); listInfoPropiedadesTabla = listInfoPropiedadesTabla.Where(i => { var nombre = i.Name; if (nombre == propiedadSoftDelete) { return(false); } if (propiedadesAuditoria.Contains(nombre)) { return(false); } return(true); }).ToList(); var heredaAuditoria = propiedadesAuditoria.All(pa => propiedadesTabla.Contains(pa)); IRepositorioGenerico <T> repositorioBase = new RepositorioGenerico <T>(clavePrincipal.Name, nombreTabla, aliasTabla, listInfoPropiedadesTabla, clavePrincipal, relaciones1a1, relaciones1aMuchos, databaseConnectionFactory, trazaLoggerInterceptor, heredaAuditoria, softDelete, propiedadesTablaRequeridas, propiedadesTablaRequeridasSoloInsert, propiedadesTablaMaxLength, Uid, propiedadInfoUid); return(repositorioBase); }
/// <summary> /// Convention to get the Name of the PropertyType from the AliasAttribute or the property itself /// </summary> /// <param name="attribute"></param> /// <param name="propertyName"></param> /// <returns></returns> public static string GetPropertyTypeName(AliasAttribute attribute, string propertyName) { if (attribute == null) return propertyName.SplitPascalCasing(); return string.IsNullOrEmpty(attribute.Name) ? propertyName.SplitPascalCasing() : attribute.Name; }
public static T Map <T>(this DataTable table, string colKey, string colValue) { try { T instance = Activator.CreateInstance <T>(); string value = string.Empty; AliasAttribute alias = null; PropertyInfo[] pi = instance.GetType().GetProperties(); Func <PropertyInfo, DataRow, string, bool> compare = (p, r, key) => { if (key.Equals((value ?? string.Empty).ToString(), StringComparison.InvariantCultureIgnoreCase)) { try { value = (r[colValue] ?? string.Empty).ToString(); p.SetValue(instance, Convert.ChangeType(value, p.PropertyType)); } catch { } return(true); } return(false); }; foreach (PropertyInfo p in pi) { foreach (DataRow row in table.Rows) { value = (row[colKey] ?? string.Empty).ToString(); if (compare(p, row, p.Name)) { break; } else { alias = p.GetAttribute <AliasAttribute>(); if (alias.HasValue()) { if (compare(p, row, (alias.Value ?? string.Empty))) { break; } } } } } return(instance); } catch { return(default(T)); } }
private void ProcessAliasAttribute(AliasAttribute attribute) { foreach (string str in attribute.aliasNames) { this.aliases.Add(str); } }
public async Task Commandlist(params string[] parameters) { string dm = "\nList of Commands\n" + "━━━━━━━━━━━━━━━━━━━━━━" + "\n\n"; Type type = typeof(Tools); foreach (var method in type.GetMethods()) { var attrs = System.Attribute.GetCustomAttributes(method); foreach (var attrib in attrs) { if (attrib is CommandAttribute) { CommandAttribute a = (CommandAttribute)attrib; dm += "!!" + a.Text + "\n"; } if (attrib is AliasAttribute) { AliasAttribute a = (AliasAttribute)attrib; dm += "aliases: "; foreach (var alias in a.Aliases) { dm += "!!" + alias + ", "; } dm = dm.Remove(dm.Count() - 2); dm += "\n"; } if (attrib is SummaryAttribute) { SummaryAttribute a = (SummaryAttribute)attrib; dm += a.Text + "\n"; } if (attrib is RequireOwnerAttribute) { RequireOwnerAttribute a = (RequireOwnerAttribute)attrib; dm += "Permitted users - Bot owner" + "\n"; } if (attrib is RequireUserPermissionAttribute) { RequireUserPermissionAttribute a = (RequireUserPermissionAttribute)attrib; dm += "Permitted users - "; if (a.GuildPermission.Value == GuildPermission.Administrator) { dm += "Server Admins"; } dm += "\n"; } if (attrib is RequireRoleAttribute) { RequireRoleAttribute a = (RequireRoleAttribute)attrib; dm += "Permitted users - " + a.name + "\n"; } } dm += "\n"; } dm += "\n\n"; await DmSplit(dm); await CommandStatus("DM Sent.", "Command List"); }
/// <summary> /// Convention to get the Alias of the PropertyType from the AliasAttribute or the property itself /// </summary> /// <param name="attribute"></param> /// <param name="propertyName"></param> /// <returns></returns> public static string GetPropertyTypeAlias(AliasAttribute attribute, string propertyName) { return(attribute == null?propertyName.ToUmbracoAlias() : attribute.Alias); }
private static object DeserializeObject(Type type, Dictionary <string, object> table) { IEnumerable <MemberInfo> members = OnlineMapsReflectionHelper.GetMembers(type, BindingFlags.Instance | BindingFlags.Public); object v = Activator.CreateInstance(type); foreach (MemberInfo member in members) { #if !NETFX_CORE MemberTypes memberType = member.MemberType; if (memberType != MemberTypes.Field && memberType != MemberTypes.Property) { continue; } #else MemberTypes memberType; if (member is PropertyInfo) { memberType = MemberTypes.Property; } else if (member is FieldInfo) { memberType = MemberTypes.Field; } else { continue; } #endif if (memberType == MemberTypes.Property && !((PropertyInfo)member).CanWrite) { continue; } object item; #if !NETFX_CORE object[] attributes = member.GetCustomAttributes(typeof(AliasAttribute), true); AliasAttribute alias = attributes.Length > 0 ? attributes[0] as AliasAttribute : null; #else IEnumerable <Attribute> attributes = member.GetCustomAttributes(typeof(AliasAttribute), true); AliasAttribute alias = null; foreach (Attribute a in attributes) { alias = a as AliasAttribute; break; } #endif if (alias == null || !alias.ignoreFieldName) { if (table.TryGetValue(member.Name, out item)) { DeserializeValue(memberType, member, item, v); continue; } } if (alias != null) { for (int j = 0; j < alias.aliases.Length; j++) { if (table.TryGetValue(alias.aliases[j], out item)) { DeserializeValue(memberType, member, item, v); break; } } } } return(v); }
/// <summary> /// Processes the Attribute metadata to generate a CompiledCommandAttribute. /// </summary> /// <exception cref="MetadataException"> /// If the attribute is a parameter attribute and another parameter attribute /// has been processed with the same parameter-set name. /// </exception> private void ProcessAttribute( string memberName, Attribute attribute, ref Collection <ValidateArgumentsAttribute> validationAttributes, ref Collection <ArgumentTransformationAttribute> argTransformationAttributes, ref string[] aliases) { if (attribute == null) { return; } CompiledAttributes.Add(attribute); // Now process the attribute based on it's type if (attribute is ParameterAttribute paramAttr) { ProcessParameterAttribute(memberName, paramAttr); return; } ValidateArgumentsAttribute validateAttr = attribute as ValidateArgumentsAttribute; if (validateAttr != null) { if (validationAttributes == null) { validationAttributes = new Collection <ValidateArgumentsAttribute>(); } validationAttributes.Add(validateAttr); if ((attribute is ValidateNotNullAttribute) || (attribute is ValidateNotNullOrEmptyAttribute)) { this.CannotBeNull = true; } return; } AliasAttribute aliasAttr = attribute as AliasAttribute; if (aliasAttr != null) { if (aliases == null) { aliases = aliasAttr.aliasNames; } else { var prevAliasNames = aliases; var newAliasNames = aliasAttr.aliasNames; aliases = new string[prevAliasNames.Length + newAliasNames.Length]; Array.Copy(prevAliasNames, aliases, prevAliasNames.Length); Array.Copy(newAliasNames, 0, aliases, prevAliasNames.Length, newAliasNames.Length); } return; } ArgumentTransformationAttribute argumentAttr = attribute as ArgumentTransformationAttribute; if (argumentAttr != null) { if (argTransformationAttributes == null) { argTransformationAttributes = new Collection <ArgumentTransformationAttribute>(); } argTransformationAttributes.Add(argumentAttr); return; } AllowNullAttribute allowNullAttribute = attribute as AllowNullAttribute; if (allowNullAttribute != null) { this.AllowsNullArgument = true; return; } AllowEmptyStringAttribute allowEmptyStringAttribute = attribute as AllowEmptyStringAttribute; if (allowEmptyStringAttribute != null) { this.AllowsEmptyStringArgument = true; return; } AllowEmptyCollectionAttribute allowEmptyCollectionAttribute = attribute as AllowEmptyCollectionAttribute; if (allowEmptyCollectionAttribute != null) { this.AllowsEmptyCollectionArgument = true; return; } ObsoleteAttribute obsoleteAttr = attribute as ObsoleteAttribute; if (obsoleteAttr != null) { ObsoleteAttribute = obsoleteAttr; return; } PSTypeNameAttribute psTypeNameAttribute = attribute as PSTypeNameAttribute; if (psTypeNameAttribute != null) { this.PSTypeName = psTypeNameAttribute.PSTypeName; } }