public static string GenerateCode(this IPersistentAttributeCreator persistentAttributeCreator) { AttributeInfoAttribute attributeInfoAttribute = persistentAttributeCreator.Create(); var argumentValues = attributeInfoAttribute.InitializedArgumentValues; var attribute = (Attribute)ReflectionHelper.CreateObject(attributeInfoAttribute.Constructor.DeclaringType, argumentValues); var args = argumentValues.Length > 0 ? string.Join(",", argumentValues.Select(GetArgumentCode)) : null; string assemblyDecleration = null; if (persistentAttributeCreator is IPersistentAssemblyAttributeInfo) { assemblyDecleration = "assembly: "; if (persistentAttributeCreator is IPersistentAssemblyVersionAttributeInfo attributeInfo) { args = @"""" + attributeInfo.Owner.Version() + @""""; } } string properties = GetPropertiesCode(attributeInfoAttribute); args = (args != null && properties != null) ? args + ", " : args; return($"[{assemblyDecleration}{attribute.GetType().FullName}({args}{properties})]"); }
public static string GenerateCode(IPersistentAttributeCreator persistentAttributeCreator) { AttributeInfoAttribute attributeInfoAttribute = persistentAttributeCreator.Create(); var attribute = (Attribute)ReflectionHelper.CreateObject(attributeInfoAttribute.Constructor.DeclaringType, attributeInfoAttribute.InitializedArgumentValues); Func <object, object> argSelector = GetArgumentCode; string args = attributeInfoAttribute.InitializedArgumentValues.Length > 0 ? attributeInfoAttribute.InitializedArgumentValues.Select(argSelector).Aggregate <object, string>(null, (current, o) => current + (o + ",")).TrimEnd(',') : null; string assemblyDecleration = null; if (persistentAttributeCreator is IPersistentAssemblyAttributeInfo) { assemblyDecleration = "assembly: "; if (persistentAttributeCreator is IPersistentAssemblyVersionAttributeInfo) { ////args = CalculateVersion(args); } } string properties = GetPropertiesCode(attributeInfoAttribute); return(string.Format("[{0}{1}({2}{3})]", assemblyDecleration, attribute.GetType().FullName, args, properties)); }
public static string GenerateCode(IPersistentAttributeCreator persistentAttributeCreator) { AttributeInfo attributeInfo = persistentAttributeCreator.Create(); var attribute = (Attribute)ReflectionHelper.CreateObject(attributeInfo.Constructor.DeclaringType, attributeInfo.InitializedArgumentValues); Func<object, object> argSelector = GetArgumentCode; string args = attributeInfo.InitializedArgumentValues.Length > 0 ? attributeInfo.InitializedArgumentValues.Select(argSelector).Aggregate <object, string>(null, (current, o) => current + (o + ",")).TrimEnd(',') : null; string assemblyDecleration = null; if (persistentAttributeCreator is IPersistentAssemblyAttributeInfo) { assemblyDecleration = "assembly: "; if (persistentAttributeCreator is IPersistentAssemblyVersionAttributeInfo) { ////args = CalculateVersion(args); } } return string.Format("[{0}{1}({2})]", assemblyDecleration, attribute.GetType().FullName, args); }