Skip to content

Instantly share code, notes, and snippets.

@smarenich
Created August 15, 2016 09:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save smarenich/39843e1bfe06a08dc29b396c4ce44fc9 to your computer and use it in GitHub Desktop.
Save smarenich/39843e1bfe06a08dc29b396c4ce44fc9 to your computer and use it in GitHub Desktop.
public class PXSYProviderSelector : PXCustomSelectorAttribute
{
[Serializable]
public class ProviderRec : IBqlTable
{
#region TypeName
public abstract class typeName : PX.Data.IBqlField { }
[PXString(128, InputMask = "", IsKey = true)]
[PXUIField(DisplayName = "Type Name", Visibility = PXUIVisibility.SelectorVisible)]
public virtual string TypeName { get; set; }
#endregion
#region Description
public abstract class description : PX.Data.IBqlField { }
[PXDBString(128, InputMask = "", IsUnicode = true)]
[PXUIField(DisplayName = "Description", Visibility = PXUIVisibility.SelectorVisible)]
public virtual string Description { get; set; }
#endregion
}
public PXSYProviderSelector()
: base(typeof(ProviderRec.typeName))
{
DescriptionField = typeof(ProviderRec.description);
}
protected IEnumerable GetRecords()
{
foreach (Assembly ass in AppDomain.CurrentDomain.GetAssemblies())
{
if (PXSubstManager.IsSuitableTypeExportAssembly(ass, true))
{
Type[] types = null;
try
{
if ( !ass.IsDynamic )
types = ass.GetExportedTypes();
}
catch (ReflectionTypeLoadException te)
{
types = te.Types;
}
catch
{
continue;
}
if (types != null)
{
foreach (Type t in types)
{
if (t != null && typeof(IPXSYProvider).IsAssignableFrom(t) && !t.IsInterface)
{
String description = t.Name;
string defaultFileExtension = null;
try
{
IPXSYProvider prov = (IPXSYProvider)Activator.CreateInstance(t);
description = prov.ProviderName;
defaultFileExtension = prov.DefaultFileExtension;
}
catch{/* Skip Exceptions */}
yield return new ProviderRec { TypeName = t.FullName, Description = description, DefaultFileExtension = defaultFileExtension };
}
}
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment