diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..ea5ebf9 --- /dev/null +++ b/.gitignore @@ -0,0 +1,205 @@ +## Ignore Visual Studio temporary files, build results, and +## files generated by popular Visual Studio add-ons. + +# User-specific files +*.suo +*.user +*.sln.docstates + +# Build results +[Dd]ebug/ +[Dd]ebugPublic/ +[Rr]elease/ +x64/ +bld/ +[Bb]in/ +[Oo]bj/ + +# Roslyn cache directories +*.ide/ + +# AWS +*.aws-sam/ + +# MSTest test Results +[Tt]est[Rr]esult*/ +[Bb]uild[Ll]og.* + +#NUNIT +*.VisualState.xml +TestResult.xml + +# Build Results of an ATL Project +[Dd]ebugPS/ +[Rr]eleasePS/ +dlldata.c + +*_i.c +*_p.c +*_i.h +*.ilk +*.meta +*.obj +*.pch +*.pdb +*.pgc +*.pgd +*.rsp +*.sbr +*.tlb +*.tli +*.tlh +*.tmp +*.tmp_proj +*.log +*.vspscc +*.vssscc +.builds +*.pidb +*.svclog +*.scc + +# Chutzpah Test files +_Chutzpah* + +# Visual C++ cache files +ipch/ +*.aps +*.ncb +*.opensdf +*.sdf +*.cachefile + +# Visual Studio profiler +*.psess +*.vsp +*.vspx + +# TFS 2012 Local Workspace +$tf/ + +# Guidance Automation Toolkit +*.gpState + +# ReSharper is a .NET coding add-in +_ReSharper*/ +*.[Rr]e[Ss]harper +*.DotSettings.user + +# JustCode is a .NET coding addin-in +.JustCode + +# TeamCity is a build add-in +_TeamCity* + +# DotCover is a Code Coverage Tool +*.dotCover + +# NCrunch +_NCrunch_* +.*crunch*.local.xml + +# MightyMoose +*.mm.* +AutoTest.Net/ + +# Web workbench (sass) +.sass-cache/ + +# Installshield output folder +[Ee]xpress/ + +# DocProject is a documentation generator add-in +DocProject/buildhelp/ +DocProject/Help/*.HxT +DocProject/Help/*.HxC +DocProject/Help/*.hhc +DocProject/Help/*.hhk +DocProject/Help/*.hhp +DocProject/Help/Html2 +DocProject/Help/html + +# Click-Once directory +publish/ + +# Publish Web Output +*.[Pp]ublish.xml +*.azurePubxml +## TODO: Comment the next line if you want to checkin your +## web deploy settings but do note that will include unencrypted +## passwords +#*.pubxml + +# NuGet Packages Directory +#packages/* +## TODO: If the tool you use requires repositories.config +## uncomment the next line +#!packages/repositories.config + +# Enable "build/" folder in the NuGet Packages folder since +# NuGet packages use it for MSBuild targets. +# This line needs to be after the ignore of the build folder +# (and the packages folder if the line above has been uncommented) +#!packages/build/ + +!src/packages/**/*.dll +!src/packages/**/*.pdb + +# Windows Azure Build Output +csx/ +*.build.csdef + +# Windows Store app package directory +AppPackages/ + +# Others +*.Cache +ClientBin/ +[Ss]tyle[Cc]op.* +~$* +*~ +*.dbmdl +*.dbproj.schemaview +*.pfx +*.publishsettings +node_modules/ + +# RIA/Silverlight projects +Generated_Code/ + +# Backup & report files from converting an old project file +# to a newer Visual Studio version. Backup files are not needed, +# because we have git ;-) +_UpgradeReport_Files/ +Backup*/ +UpgradeLog*.XML +UpgradeLog*.htm + +# SQL Server files +*.mdf +*.ldf + +# Business Intelligence projects +*.rdl.data +*.bim.layout +*.bim_*.settings + +# Microsoft Fakes +FakesAssemblies/ + +# LightSwitch generated files +GeneratedArtifacts/ +_Pvt_Extensions/ +ModelManifest.xml +src/packages/EventStore.Client.3.3.1/lib/net40/EventStore.ClientAPI.xml + +# JetBrains Rider +.idea/ +*.sln.iml + +# Vagrant VM files +.vagrant +vagrant/dbv/data/meta/revision + +# Visual Studio 2015 cache/options directory +.vs/ \ No newline at end of file diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..ea5ebf9 --- /dev/null +++ b/.gitignore @@ -0,0 +1,205 @@ +## Ignore Visual Studio temporary files, build results, and +## files generated by popular Visual Studio add-ons. + +# User-specific files +*.suo +*.user +*.sln.docstates + +# Build results +[Dd]ebug/ +[Dd]ebugPublic/ +[Rr]elease/ +x64/ +bld/ +[Bb]in/ +[Oo]bj/ + +# Roslyn cache directories +*.ide/ + +# AWS +*.aws-sam/ + +# MSTest test Results +[Tt]est[Rr]esult*/ +[Bb]uild[Ll]og.* + +#NUNIT +*.VisualState.xml +TestResult.xml + +# Build Results of an ATL Project +[Dd]ebugPS/ +[Rr]eleasePS/ +dlldata.c + +*_i.c +*_p.c +*_i.h +*.ilk +*.meta +*.obj +*.pch +*.pdb +*.pgc +*.pgd +*.rsp +*.sbr +*.tlb +*.tli +*.tlh +*.tmp +*.tmp_proj +*.log +*.vspscc +*.vssscc +.builds +*.pidb +*.svclog +*.scc + +# Chutzpah Test files +_Chutzpah* + +# Visual C++ cache files +ipch/ +*.aps +*.ncb +*.opensdf +*.sdf +*.cachefile + +# Visual Studio profiler +*.psess +*.vsp +*.vspx + +# TFS 2012 Local Workspace +$tf/ + +# Guidance Automation Toolkit +*.gpState + +# ReSharper is a .NET coding add-in +_ReSharper*/ +*.[Rr]e[Ss]harper +*.DotSettings.user + +# JustCode is a .NET coding addin-in +.JustCode + +# TeamCity is a build add-in +_TeamCity* + +# DotCover is a Code Coverage Tool +*.dotCover + +# NCrunch +_NCrunch_* +.*crunch*.local.xml + +# MightyMoose +*.mm.* +AutoTest.Net/ + +# Web workbench (sass) +.sass-cache/ + +# Installshield output folder +[Ee]xpress/ + +# DocProject is a documentation generator add-in +DocProject/buildhelp/ +DocProject/Help/*.HxT +DocProject/Help/*.HxC +DocProject/Help/*.hhc +DocProject/Help/*.hhk +DocProject/Help/*.hhp +DocProject/Help/Html2 +DocProject/Help/html + +# Click-Once directory +publish/ + +# Publish Web Output +*.[Pp]ublish.xml +*.azurePubxml +## TODO: Comment the next line if you want to checkin your +## web deploy settings but do note that will include unencrypted +## passwords +#*.pubxml + +# NuGet Packages Directory +#packages/* +## TODO: If the tool you use requires repositories.config +## uncomment the next line +#!packages/repositories.config + +# Enable "build/" folder in the NuGet Packages folder since +# NuGet packages use it for MSBuild targets. +# This line needs to be after the ignore of the build folder +# (and the packages folder if the line above has been uncommented) +#!packages/build/ + +!src/packages/**/*.dll +!src/packages/**/*.pdb + +# Windows Azure Build Output +csx/ +*.build.csdef + +# Windows Store app package directory +AppPackages/ + +# Others +*.Cache +ClientBin/ +[Ss]tyle[Cc]op.* +~$* +*~ +*.dbmdl +*.dbproj.schemaview +*.pfx +*.publishsettings +node_modules/ + +# RIA/Silverlight projects +Generated_Code/ + +# Backup & report files from converting an old project file +# to a newer Visual Studio version. Backup files are not needed, +# because we have git ;-) +_UpgradeReport_Files/ +Backup*/ +UpgradeLog*.XML +UpgradeLog*.htm + +# SQL Server files +*.mdf +*.ldf + +# Business Intelligence projects +*.rdl.data +*.bim.layout +*.bim_*.settings + +# Microsoft Fakes +FakesAssemblies/ + +# LightSwitch generated files +GeneratedArtifacts/ +_Pvt_Extensions/ +ModelManifest.xml +src/packages/EventStore.Client.3.3.1/lib/net40/EventStore.ClientAPI.xml + +# JetBrains Rider +.idea/ +*.sln.iml + +# Vagrant VM files +.vagrant +vagrant/dbv/data/meta/revision + +# Visual Studio 2015 cache/options directory +.vs/ \ No newline at end of file diff --git a/Extension.cs b/Extension.cs new file mode 100644 index 0000000..6cac789 --- /dev/null +++ b/Extension.cs @@ -0,0 +1,65 @@ +namespace ExtensionExample; + +public static class Extensions +{ + public static bool IsDownloadable(this OfferingType offeringType) + { + var validOfferings = new List() + { + OfferingType.Template, + OfferingType.Ebook, + OfferingType.OfflineCourse + }; + + return validOfferings.Contains(offeringType); + } +} + +public enum OfferingType +{ + Course, + Ebook, + Book, + Template, + OfflineCourse, +} + +public sealed record Product(int Id, OfferingType Type); + +public sealed class ProductHandler(ResourcesHelper resourcesHelper) +{ + public void DoStuff(Product product) + { + if (product.Type.IsDownloadable()) + { + var fileName = resourcesHelper.GetDefaultDownloadFileName(product.Type); + var downloadUrl = resourcesHelper.GetDownloadUrl(product.Type); + } + + } +} + +public sealed class ResourcesHelper +{ + public string? GetDownloadUrl(OfferingType offeringType) + { + if (offeringType.IsDownloadable()) + { + // some code to do this... + return "TODO: get the download URL"; + } + + return null; + } + + public string? GetDefaultDownloadFileName(OfferingType offeringType) + { + if (offeringType.IsDownloadable()) + { + // some code to do this... + return "TODO: get the file name"; + } + + return null; + } +} \ No newline at end of file diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..ea5ebf9 --- /dev/null +++ b/.gitignore @@ -0,0 +1,205 @@ +## Ignore Visual Studio temporary files, build results, and +## files generated by popular Visual Studio add-ons. + +# User-specific files +*.suo +*.user +*.sln.docstates + +# Build results +[Dd]ebug/ +[Dd]ebugPublic/ +[Rr]elease/ +x64/ +bld/ +[Bb]in/ +[Oo]bj/ + +# Roslyn cache directories +*.ide/ + +# AWS +*.aws-sam/ + +# MSTest test Results +[Tt]est[Rr]esult*/ +[Bb]uild[Ll]og.* + +#NUNIT +*.VisualState.xml +TestResult.xml + +# Build Results of an ATL Project +[Dd]ebugPS/ +[Rr]eleasePS/ +dlldata.c + +*_i.c +*_p.c +*_i.h +*.ilk +*.meta +*.obj +*.pch +*.pdb +*.pgc +*.pgd +*.rsp +*.sbr +*.tlb +*.tli +*.tlh +*.tmp +*.tmp_proj +*.log +*.vspscc +*.vssscc +.builds +*.pidb +*.svclog +*.scc + +# Chutzpah Test files +_Chutzpah* + +# Visual C++ cache files +ipch/ +*.aps +*.ncb +*.opensdf +*.sdf +*.cachefile + +# Visual Studio profiler +*.psess +*.vsp +*.vspx + +# TFS 2012 Local Workspace +$tf/ + +# Guidance Automation Toolkit +*.gpState + +# ReSharper is a .NET coding add-in +_ReSharper*/ +*.[Rr]e[Ss]harper +*.DotSettings.user + +# JustCode is a .NET coding addin-in +.JustCode + +# TeamCity is a build add-in +_TeamCity* + +# DotCover is a Code Coverage Tool +*.dotCover + +# NCrunch +_NCrunch_* +.*crunch*.local.xml + +# MightyMoose +*.mm.* +AutoTest.Net/ + +# Web workbench (sass) +.sass-cache/ + +# Installshield output folder +[Ee]xpress/ + +# DocProject is a documentation generator add-in +DocProject/buildhelp/ +DocProject/Help/*.HxT +DocProject/Help/*.HxC +DocProject/Help/*.hhc +DocProject/Help/*.hhk +DocProject/Help/*.hhp +DocProject/Help/Html2 +DocProject/Help/html + +# Click-Once directory +publish/ + +# Publish Web Output +*.[Pp]ublish.xml +*.azurePubxml +## TODO: Comment the next line if you want to checkin your +## web deploy settings but do note that will include unencrypted +## passwords +#*.pubxml + +# NuGet Packages Directory +#packages/* +## TODO: If the tool you use requires repositories.config +## uncomment the next line +#!packages/repositories.config + +# Enable "build/" folder in the NuGet Packages folder since +# NuGet packages use it for MSBuild targets. +# This line needs to be after the ignore of the build folder +# (and the packages folder if the line above has been uncommented) +#!packages/build/ + +!src/packages/**/*.dll +!src/packages/**/*.pdb + +# Windows Azure Build Output +csx/ +*.build.csdef + +# Windows Store app package directory +AppPackages/ + +# Others +*.Cache +ClientBin/ +[Ss]tyle[Cc]op.* +~$* +*~ +*.dbmdl +*.dbproj.schemaview +*.pfx +*.publishsettings +node_modules/ + +# RIA/Silverlight projects +Generated_Code/ + +# Backup & report files from converting an old project file +# to a newer Visual Studio version. Backup files are not needed, +# because we have git ;-) +_UpgradeReport_Files/ +Backup*/ +UpgradeLog*.XML +UpgradeLog*.htm + +# SQL Server files +*.mdf +*.ldf + +# Business Intelligence projects +*.rdl.data +*.bim.layout +*.bim_*.settings + +# Microsoft Fakes +FakesAssemblies/ + +# LightSwitch generated files +GeneratedArtifacts/ +_Pvt_Extensions/ +ModelManifest.xml +src/packages/EventStore.Client.3.3.1/lib/net40/EventStore.ClientAPI.xml + +# JetBrains Rider +.idea/ +*.sln.iml + +# Vagrant VM files +.vagrant +vagrant/dbv/data/meta/revision + +# Visual Studio 2015 cache/options directory +.vs/ \ No newline at end of file diff --git a/Extension.cs b/Extension.cs new file mode 100644 index 0000000..6cac789 --- /dev/null +++ b/Extension.cs @@ -0,0 +1,65 @@ +namespace ExtensionExample; + +public static class Extensions +{ + public static bool IsDownloadable(this OfferingType offeringType) + { + var validOfferings = new List() + { + OfferingType.Template, + OfferingType.Ebook, + OfferingType.OfflineCourse + }; + + return validOfferings.Contains(offeringType); + } +} + +public enum OfferingType +{ + Course, + Ebook, + Book, + Template, + OfflineCourse, +} + +public sealed record Product(int Id, OfferingType Type); + +public sealed class ProductHandler(ResourcesHelper resourcesHelper) +{ + public void DoStuff(Product product) + { + if (product.Type.IsDownloadable()) + { + var fileName = resourcesHelper.GetDefaultDownloadFileName(product.Type); + var downloadUrl = resourcesHelper.GetDownloadUrl(product.Type); + } + + } +} + +public sealed class ResourcesHelper +{ + public string? GetDownloadUrl(OfferingType offeringType) + { + if (offeringType.IsDownloadable()) + { + // some code to do this... + return "TODO: get the download URL"; + } + + return null; + } + + public string? GetDefaultDownloadFileName(OfferingType offeringType) + { + if (offeringType.IsDownloadable()) + { + // some code to do this... + return "TODO: get the file name"; + } + + return null; + } +} \ No newline at end of file diff --git a/Original.cs b/Original.cs new file mode 100644 index 0000000..d9ddda2 --- /dev/null +++ b/Original.cs @@ -0,0 +1,80 @@ +namespace Original; + +public enum OfferingType +{ + Course, + Ebook, + Book, + Offline, + Template, +} + +public sealed record Product(int Id, OfferingType Type); + +public sealed class ProductHandler(ResourcesHelper resourcesHelper) +{ + public void Handle(Product product) + { + if (product.Type == OfferingType.Template || + product.Type == OfferingType.Ebook || + product.Type == OfferingType.Offline) + { + var fileName = resourcesHelper.GetDefaultDownloadFileName(product.Type); + var downloadUrl = resourcesHelper.GetDownloadUrl(product.Type); + } + + } +} + +public sealed class ResourcesHelper +{ + public string? GetDownloadUrl(OfferingType offeringType) + { + if (offeringType == OfferingType.Template || + offeringType == OfferingType.Ebook) + { + // some code to do this... + return "TODO: get the download URL"; + } + + return null; + } + + public string? GetDefaultDownloadFileName(OfferingType offeringType) + { + if (offeringType == OfferingType.Template || + offeringType == OfferingType.Ebook) + { + // some code to do this... + return "TODO: get the file name"; + } + + return null; + } +} + +/* +public sealed record DownloadableResource( + int Id, + int ProductId, + string DownloadUrl, + string DefaultDownloadFilename); + +public sealed class ProductHandler2(ResourcesHelper2 resourcesHelper) +{ + public void DoStuff(Product product) + { + var downloadableResource = resourcesHelper.GetDownloadable(product.Id); + // do stuff with downloadable resource + } +} + +public sealed class ResourcesHelper2 +{ + public DownloadableResource? GetDownloadable(int productId) + { + // TODO: go fetch this... + return null; + } +} +*/ \ No newline at end of file diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..ea5ebf9 --- /dev/null +++ b/.gitignore @@ -0,0 +1,205 @@ +## Ignore Visual Studio temporary files, build results, and +## files generated by popular Visual Studio add-ons. + +# User-specific files +*.suo +*.user +*.sln.docstates + +# Build results +[Dd]ebug/ +[Dd]ebugPublic/ +[Rr]elease/ +x64/ +bld/ +[Bb]in/ +[Oo]bj/ + +# Roslyn cache directories +*.ide/ + +# AWS +*.aws-sam/ + +# MSTest test Results +[Tt]est[Rr]esult*/ +[Bb]uild[Ll]og.* + +#NUNIT +*.VisualState.xml +TestResult.xml + +# Build Results of an ATL Project +[Dd]ebugPS/ +[Rr]eleasePS/ +dlldata.c + +*_i.c +*_p.c +*_i.h +*.ilk +*.meta +*.obj +*.pch +*.pdb +*.pgc +*.pgd +*.rsp +*.sbr +*.tlb +*.tli +*.tlh +*.tmp +*.tmp_proj +*.log +*.vspscc +*.vssscc +.builds +*.pidb +*.svclog +*.scc + +# Chutzpah Test files +_Chutzpah* + +# Visual C++ cache files +ipch/ +*.aps +*.ncb +*.opensdf +*.sdf +*.cachefile + +# Visual Studio profiler +*.psess +*.vsp +*.vspx + +# TFS 2012 Local Workspace +$tf/ + +# Guidance Automation Toolkit +*.gpState + +# ReSharper is a .NET coding add-in +_ReSharper*/ +*.[Rr]e[Ss]harper +*.DotSettings.user + +# JustCode is a .NET coding addin-in +.JustCode + +# TeamCity is a build add-in +_TeamCity* + +# DotCover is a Code Coverage Tool +*.dotCover + +# NCrunch +_NCrunch_* +.*crunch*.local.xml + +# MightyMoose +*.mm.* +AutoTest.Net/ + +# Web workbench (sass) +.sass-cache/ + +# Installshield output folder +[Ee]xpress/ + +# DocProject is a documentation generator add-in +DocProject/buildhelp/ +DocProject/Help/*.HxT +DocProject/Help/*.HxC +DocProject/Help/*.hhc +DocProject/Help/*.hhk +DocProject/Help/*.hhp +DocProject/Help/Html2 +DocProject/Help/html + +# Click-Once directory +publish/ + +# Publish Web Output +*.[Pp]ublish.xml +*.azurePubxml +## TODO: Comment the next line if you want to checkin your +## web deploy settings but do note that will include unencrypted +## passwords +#*.pubxml + +# NuGet Packages Directory +#packages/* +## TODO: If the tool you use requires repositories.config +## uncomment the next line +#!packages/repositories.config + +# Enable "build/" folder in the NuGet Packages folder since +# NuGet packages use it for MSBuild targets. +# This line needs to be after the ignore of the build folder +# (and the packages folder if the line above has been uncommented) +#!packages/build/ + +!src/packages/**/*.dll +!src/packages/**/*.pdb + +# Windows Azure Build Output +csx/ +*.build.csdef + +# Windows Store app package directory +AppPackages/ + +# Others +*.Cache +ClientBin/ +[Ss]tyle[Cc]op.* +~$* +*~ +*.dbmdl +*.dbproj.schemaview +*.pfx +*.publishsettings +node_modules/ + +# RIA/Silverlight projects +Generated_Code/ + +# Backup & report files from converting an old project file +# to a newer Visual Studio version. Backup files are not needed, +# because we have git ;-) +_UpgradeReport_Files/ +Backup*/ +UpgradeLog*.XML +UpgradeLog*.htm + +# SQL Server files +*.mdf +*.ldf + +# Business Intelligence projects +*.rdl.data +*.bim.layout +*.bim_*.settings + +# Microsoft Fakes +FakesAssemblies/ + +# LightSwitch generated files +GeneratedArtifacts/ +_Pvt_Extensions/ +ModelManifest.xml +src/packages/EventStore.Client.3.3.1/lib/net40/EventStore.ClientAPI.xml + +# JetBrains Rider +.idea/ +*.sln.iml + +# Vagrant VM files +.vagrant +vagrant/dbv/data/meta/revision + +# Visual Studio 2015 cache/options directory +.vs/ \ No newline at end of file diff --git a/Extension.cs b/Extension.cs new file mode 100644 index 0000000..6cac789 --- /dev/null +++ b/Extension.cs @@ -0,0 +1,65 @@ +namespace ExtensionExample; + +public static class Extensions +{ + public static bool IsDownloadable(this OfferingType offeringType) + { + var validOfferings = new List() + { + OfferingType.Template, + OfferingType.Ebook, + OfferingType.OfflineCourse + }; + + return validOfferings.Contains(offeringType); + } +} + +public enum OfferingType +{ + Course, + Ebook, + Book, + Template, + OfflineCourse, +} + +public sealed record Product(int Id, OfferingType Type); + +public sealed class ProductHandler(ResourcesHelper resourcesHelper) +{ + public void DoStuff(Product product) + { + if (product.Type.IsDownloadable()) + { + var fileName = resourcesHelper.GetDefaultDownloadFileName(product.Type); + var downloadUrl = resourcesHelper.GetDownloadUrl(product.Type); + } + + } +} + +public sealed class ResourcesHelper +{ + public string? GetDownloadUrl(OfferingType offeringType) + { + if (offeringType.IsDownloadable()) + { + // some code to do this... + return "TODO: get the download URL"; + } + + return null; + } + + public string? GetDefaultDownloadFileName(OfferingType offeringType) + { + if (offeringType.IsDownloadable()) + { + // some code to do this... + return "TODO: get the file name"; + } + + return null; + } +} \ No newline at end of file diff --git a/Original.cs b/Original.cs new file mode 100644 index 0000000..d9ddda2 --- /dev/null +++ b/Original.cs @@ -0,0 +1,80 @@ +namespace Original; + +public enum OfferingType +{ + Course, + Ebook, + Book, + Offline, + Template, +} + +public sealed record Product(int Id, OfferingType Type); + +public sealed class ProductHandler(ResourcesHelper resourcesHelper) +{ + public void Handle(Product product) + { + if (product.Type == OfferingType.Template || + product.Type == OfferingType.Ebook || + product.Type == OfferingType.Offline) + { + var fileName = resourcesHelper.GetDefaultDownloadFileName(product.Type); + var downloadUrl = resourcesHelper.GetDownloadUrl(product.Type); + } + + } +} + +public sealed class ResourcesHelper +{ + public string? GetDownloadUrl(OfferingType offeringType) + { + if (offeringType == OfferingType.Template || + offeringType == OfferingType.Ebook) + { + // some code to do this... + return "TODO: get the download URL"; + } + + return null; + } + + public string? GetDefaultDownloadFileName(OfferingType offeringType) + { + if (offeringType == OfferingType.Template || + offeringType == OfferingType.Ebook) + { + // some code to do this... + return "TODO: get the file name"; + } + + return null; + } +} + +/* +public sealed record DownloadableResource( + int Id, + int ProductId, + string DownloadUrl, + string DefaultDownloadFilename); + +public sealed class ProductHandler2(ResourcesHelper2 resourcesHelper) +{ + public void DoStuff(Product product) + { + var downloadableResource = resourcesHelper.GetDownloadable(product.Id); + // do stuff with downloadable resource + } +} + +public sealed class ResourcesHelper2 +{ + public DownloadableResource? GetDownloadable(int productId) + { + // TODO: go fetch this... + return null; + } +} +*/ \ No newline at end of file diff --git a/Types.cs b/Types.cs new file mode 100644 index 0000000..1d58ddc --- /dev/null +++ b/Types.cs @@ -0,0 +1,77 @@ +namespace TypesExample; + +public abstract class Product(int id) +{ + public int Id { get; } = id; +} +public class Template(int id) : Product(id) { } +public class Ebook(int id) : Product(id) { } +public class OfflineCourse(int id) : Product(id) { } + +public sealed class ProductHandler(ResourcesHelper resourcesHelper) +{ + public void DoStuff(Product product) + { + if (product is Template || + product is Ebook|| + product is OfflineCourse) + { + var fileName = resourcesHelper.GetDefaultDownloadFileName(product); + var downloadUrl = resourcesHelper.GetDownloadUrl(product); + } + } +} + +public sealed class ResourcesHelper +{ + public string? GetDownloadUrl(Product product) + { + if (product is Template || + product is Ebook|| + product is OfflineCourse) + { + // some code to do this... + return "TODO: get the download URL"; + } + + return null; + } + + public string? GetDefaultDownloadFileName(Product product) + { + if (product is Template || + product is Ebook|| + product is OfflineCourse) + { + // some code to do this... + return "TODO: get the file name"; + } + + return null; + } +} + + +public sealed record DownloadableResource( + int Id, + int ProductId, + string DownloadUrl, + string DefaultDownloadFilename); + +public sealed class ProductHandler2(ResourcesHelper2 resourcesHelper) +{ + public void DoStuff(Product product) + { + var downloadableResource = resourcesHelper.GetDownloadable(product.Id); + // do stuff with downloadable resource + } +} + +public sealed class ResourcesHelper2 +{ + public DownloadableResource? GetDownloadable(int productId) + { + // TODO: go fetch this... + return null; + } +} \ No newline at end of file diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..ea5ebf9 --- /dev/null +++ b/.gitignore @@ -0,0 +1,205 @@ +## Ignore Visual Studio temporary files, build results, and +## files generated by popular Visual Studio add-ons. + +# User-specific files +*.suo +*.user +*.sln.docstates + +# Build results +[Dd]ebug/ +[Dd]ebugPublic/ +[Rr]elease/ +x64/ +bld/ +[Bb]in/ +[Oo]bj/ + +# Roslyn cache directories +*.ide/ + +# AWS +*.aws-sam/ + +# MSTest test Results +[Tt]est[Rr]esult*/ +[Bb]uild[Ll]og.* + +#NUNIT +*.VisualState.xml +TestResult.xml + +# Build Results of an ATL Project +[Dd]ebugPS/ +[Rr]eleasePS/ +dlldata.c + +*_i.c +*_p.c +*_i.h +*.ilk +*.meta +*.obj +*.pch +*.pdb +*.pgc +*.pgd +*.rsp +*.sbr +*.tlb +*.tli +*.tlh +*.tmp +*.tmp_proj +*.log +*.vspscc +*.vssscc +.builds +*.pidb +*.svclog +*.scc + +# Chutzpah Test files +_Chutzpah* + +# Visual C++ cache files +ipch/ +*.aps +*.ncb +*.opensdf +*.sdf +*.cachefile + +# Visual Studio profiler +*.psess +*.vsp +*.vspx + +# TFS 2012 Local Workspace +$tf/ + +# Guidance Automation Toolkit +*.gpState + +# ReSharper is a .NET coding add-in +_ReSharper*/ +*.[Rr]e[Ss]harper +*.DotSettings.user + +# JustCode is a .NET coding addin-in +.JustCode + +# TeamCity is a build add-in +_TeamCity* + +# DotCover is a Code Coverage Tool +*.dotCover + +# NCrunch +_NCrunch_* +.*crunch*.local.xml + +# MightyMoose +*.mm.* +AutoTest.Net/ + +# Web workbench (sass) +.sass-cache/ + +# Installshield output folder +[Ee]xpress/ + +# DocProject is a documentation generator add-in +DocProject/buildhelp/ +DocProject/Help/*.HxT +DocProject/Help/*.HxC +DocProject/Help/*.hhc +DocProject/Help/*.hhk +DocProject/Help/*.hhp +DocProject/Help/Html2 +DocProject/Help/html + +# Click-Once directory +publish/ + +# Publish Web Output +*.[Pp]ublish.xml +*.azurePubxml +## TODO: Comment the next line if you want to checkin your +## web deploy settings but do note that will include unencrypted +## passwords +#*.pubxml + +# NuGet Packages Directory +#packages/* +## TODO: If the tool you use requires repositories.config +## uncomment the next line +#!packages/repositories.config + +# Enable "build/" folder in the NuGet Packages folder since +# NuGet packages use it for MSBuild targets. +# This line needs to be after the ignore of the build folder +# (and the packages folder if the line above has been uncommented) +#!packages/build/ + +!src/packages/**/*.dll +!src/packages/**/*.pdb + +# Windows Azure Build Output +csx/ +*.build.csdef + +# Windows Store app package directory +AppPackages/ + +# Others +*.Cache +ClientBin/ +[Ss]tyle[Cc]op.* +~$* +*~ +*.dbmdl +*.dbproj.schemaview +*.pfx +*.publishsettings +node_modules/ + +# RIA/Silverlight projects +Generated_Code/ + +# Backup & report files from converting an old project file +# to a newer Visual Studio version. Backup files are not needed, +# because we have git ;-) +_UpgradeReport_Files/ +Backup*/ +UpgradeLog*.XML +UpgradeLog*.htm + +# SQL Server files +*.mdf +*.ldf + +# Business Intelligence projects +*.rdl.data +*.bim.layout +*.bim_*.settings + +# Microsoft Fakes +FakesAssemblies/ + +# LightSwitch generated files +GeneratedArtifacts/ +_Pvt_Extensions/ +ModelManifest.xml +src/packages/EventStore.Client.3.3.1/lib/net40/EventStore.ClientAPI.xml + +# JetBrains Rider +.idea/ +*.sln.iml + +# Vagrant VM files +.vagrant +vagrant/dbv/data/meta/revision + +# Visual Studio 2015 cache/options directory +.vs/ \ No newline at end of file diff --git a/Extension.cs b/Extension.cs new file mode 100644 index 0000000..6cac789 --- /dev/null +++ b/Extension.cs @@ -0,0 +1,65 @@ +namespace ExtensionExample; + +public static class Extensions +{ + public static bool IsDownloadable(this OfferingType offeringType) + { + var validOfferings = new List() + { + OfferingType.Template, + OfferingType.Ebook, + OfferingType.OfflineCourse + }; + + return validOfferings.Contains(offeringType); + } +} + +public enum OfferingType +{ + Course, + Ebook, + Book, + Template, + OfflineCourse, +} + +public sealed record Product(int Id, OfferingType Type); + +public sealed class ProductHandler(ResourcesHelper resourcesHelper) +{ + public void DoStuff(Product product) + { + if (product.Type.IsDownloadable()) + { + var fileName = resourcesHelper.GetDefaultDownloadFileName(product.Type); + var downloadUrl = resourcesHelper.GetDownloadUrl(product.Type); + } + + } +} + +public sealed class ResourcesHelper +{ + public string? GetDownloadUrl(OfferingType offeringType) + { + if (offeringType.IsDownloadable()) + { + // some code to do this... + return "TODO: get the download URL"; + } + + return null; + } + + public string? GetDefaultDownloadFileName(OfferingType offeringType) + { + if (offeringType.IsDownloadable()) + { + // some code to do this... + return "TODO: get the file name"; + } + + return null; + } +} \ No newline at end of file diff --git a/Original.cs b/Original.cs new file mode 100644 index 0000000..d9ddda2 --- /dev/null +++ b/Original.cs @@ -0,0 +1,80 @@ +namespace Original; + +public enum OfferingType +{ + Course, + Ebook, + Book, + Offline, + Template, +} + +public sealed record Product(int Id, OfferingType Type); + +public sealed class ProductHandler(ResourcesHelper resourcesHelper) +{ + public void Handle(Product product) + { + if (product.Type == OfferingType.Template || + product.Type == OfferingType.Ebook || + product.Type == OfferingType.Offline) + { + var fileName = resourcesHelper.GetDefaultDownloadFileName(product.Type); + var downloadUrl = resourcesHelper.GetDownloadUrl(product.Type); + } + + } +} + +public sealed class ResourcesHelper +{ + public string? GetDownloadUrl(OfferingType offeringType) + { + if (offeringType == OfferingType.Template || + offeringType == OfferingType.Ebook) + { + // some code to do this... + return "TODO: get the download URL"; + } + + return null; + } + + public string? GetDefaultDownloadFileName(OfferingType offeringType) + { + if (offeringType == OfferingType.Template || + offeringType == OfferingType.Ebook) + { + // some code to do this... + return "TODO: get the file name"; + } + + return null; + } +} + +/* +public sealed record DownloadableResource( + int Id, + int ProductId, + string DownloadUrl, + string DefaultDownloadFilename); + +public sealed class ProductHandler2(ResourcesHelper2 resourcesHelper) +{ + public void DoStuff(Product product) + { + var downloadableResource = resourcesHelper.GetDownloadable(product.Id); + // do stuff with downloadable resource + } +} + +public sealed class ResourcesHelper2 +{ + public DownloadableResource? GetDownloadable(int productId) + { + // TODO: go fetch this... + return null; + } +} +*/ \ No newline at end of file diff --git a/Types.cs b/Types.cs new file mode 100644 index 0000000..1d58ddc --- /dev/null +++ b/Types.cs @@ -0,0 +1,77 @@ +namespace TypesExample; + +public abstract class Product(int id) +{ + public int Id { get; } = id; +} +public class Template(int id) : Product(id) { } +public class Ebook(int id) : Product(id) { } +public class OfflineCourse(int id) : Product(id) { } + +public sealed class ProductHandler(ResourcesHelper resourcesHelper) +{ + public void DoStuff(Product product) + { + if (product is Template || + product is Ebook|| + product is OfflineCourse) + { + var fileName = resourcesHelper.GetDefaultDownloadFileName(product); + var downloadUrl = resourcesHelper.GetDownloadUrl(product); + } + } +} + +public sealed class ResourcesHelper +{ + public string? GetDownloadUrl(Product product) + { + if (product is Template || + product is Ebook|| + product is OfflineCourse) + { + // some code to do this... + return "TODO: get the download URL"; + } + + return null; + } + + public string? GetDefaultDownloadFileName(Product product) + { + if (product is Template || + product is Ebook|| + product is OfflineCourse) + { + // some code to do this... + return "TODO: get the file name"; + } + + return null; + } +} + + +public sealed record DownloadableResource( + int Id, + int ProductId, + string DownloadUrl, + string DefaultDownloadFilename); + +public sealed class ProductHandler2(ResourcesHelper2 resourcesHelper) +{ + public void DoStuff(Product product) + { + var downloadableResource = resourcesHelper.GetDownloadable(product.Id); + // do stuff with downloadable resource + } +} + +public sealed class ResourcesHelper2 +{ + public DownloadableResource? GetDownloadable(int productId) + { + // TODO: go fetch this... + return null; + } +} \ No newline at end of file diff --git a/enum.csproj b/enum.csproj new file mode 100644 index 0000000..c40e829 --- /dev/null +++ b/enum.csproj @@ -0,0 +1,14 @@ + + + + Exe + net8.0 + enable + enable + + + + + + + diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..ea5ebf9 --- /dev/null +++ b/.gitignore @@ -0,0 +1,205 @@ +## Ignore Visual Studio temporary files, build results, and +## files generated by popular Visual Studio add-ons. + +# User-specific files +*.suo +*.user +*.sln.docstates + +# Build results +[Dd]ebug/ +[Dd]ebugPublic/ +[Rr]elease/ +x64/ +bld/ +[Bb]in/ +[Oo]bj/ + +# Roslyn cache directories +*.ide/ + +# AWS +*.aws-sam/ + +# MSTest test Results +[Tt]est[Rr]esult*/ +[Bb]uild[Ll]og.* + +#NUNIT +*.VisualState.xml +TestResult.xml + +# Build Results of an ATL Project +[Dd]ebugPS/ +[Rr]eleasePS/ +dlldata.c + +*_i.c +*_p.c +*_i.h +*.ilk +*.meta +*.obj +*.pch +*.pdb +*.pgc +*.pgd +*.rsp +*.sbr +*.tlb +*.tli +*.tlh +*.tmp +*.tmp_proj +*.log +*.vspscc +*.vssscc +.builds +*.pidb +*.svclog +*.scc + +# Chutzpah Test files +_Chutzpah* + +# Visual C++ cache files +ipch/ +*.aps +*.ncb +*.opensdf +*.sdf +*.cachefile + +# Visual Studio profiler +*.psess +*.vsp +*.vspx + +# TFS 2012 Local Workspace +$tf/ + +# Guidance Automation Toolkit +*.gpState + +# ReSharper is a .NET coding add-in +_ReSharper*/ +*.[Rr]e[Ss]harper +*.DotSettings.user + +# JustCode is a .NET coding addin-in +.JustCode + +# TeamCity is a build add-in +_TeamCity* + +# DotCover is a Code Coverage Tool +*.dotCover + +# NCrunch +_NCrunch_* +.*crunch*.local.xml + +# MightyMoose +*.mm.* +AutoTest.Net/ + +# Web workbench (sass) +.sass-cache/ + +# Installshield output folder +[Ee]xpress/ + +# DocProject is a documentation generator add-in +DocProject/buildhelp/ +DocProject/Help/*.HxT +DocProject/Help/*.HxC +DocProject/Help/*.hhc +DocProject/Help/*.hhk +DocProject/Help/*.hhp +DocProject/Help/Html2 +DocProject/Help/html + +# Click-Once directory +publish/ + +# Publish Web Output +*.[Pp]ublish.xml +*.azurePubxml +## TODO: Comment the next line if you want to checkin your +## web deploy settings but do note that will include unencrypted +## passwords +#*.pubxml + +# NuGet Packages Directory +#packages/* +## TODO: If the tool you use requires repositories.config +## uncomment the next line +#!packages/repositories.config + +# Enable "build/" folder in the NuGet Packages folder since +# NuGet packages use it for MSBuild targets. +# This line needs to be after the ignore of the build folder +# (and the packages folder if the line above has been uncommented) +#!packages/build/ + +!src/packages/**/*.dll +!src/packages/**/*.pdb + +# Windows Azure Build Output +csx/ +*.build.csdef + +# Windows Store app package directory +AppPackages/ + +# Others +*.Cache +ClientBin/ +[Ss]tyle[Cc]op.* +~$* +*~ +*.dbmdl +*.dbproj.schemaview +*.pfx +*.publishsettings +node_modules/ + +# RIA/Silverlight projects +Generated_Code/ + +# Backup & report files from converting an old project file +# to a newer Visual Studio version. Backup files are not needed, +# because we have git ;-) +_UpgradeReport_Files/ +Backup*/ +UpgradeLog*.XML +UpgradeLog*.htm + +# SQL Server files +*.mdf +*.ldf + +# Business Intelligence projects +*.rdl.data +*.bim.layout +*.bim_*.settings + +# Microsoft Fakes +FakesAssemblies/ + +# LightSwitch generated files +GeneratedArtifacts/ +_Pvt_Extensions/ +ModelManifest.xml +src/packages/EventStore.Client.3.3.1/lib/net40/EventStore.ClientAPI.xml + +# JetBrains Rider +.idea/ +*.sln.iml + +# Vagrant VM files +.vagrant +vagrant/dbv/data/meta/revision + +# Visual Studio 2015 cache/options directory +.vs/ \ No newline at end of file diff --git a/Extension.cs b/Extension.cs new file mode 100644 index 0000000..6cac789 --- /dev/null +++ b/Extension.cs @@ -0,0 +1,65 @@ +namespace ExtensionExample; + +public static class Extensions +{ + public static bool IsDownloadable(this OfferingType offeringType) + { + var validOfferings = new List() + { + OfferingType.Template, + OfferingType.Ebook, + OfferingType.OfflineCourse + }; + + return validOfferings.Contains(offeringType); + } +} + +public enum OfferingType +{ + Course, + Ebook, + Book, + Template, + OfflineCourse, +} + +public sealed record Product(int Id, OfferingType Type); + +public sealed class ProductHandler(ResourcesHelper resourcesHelper) +{ + public void DoStuff(Product product) + { + if (product.Type.IsDownloadable()) + { + var fileName = resourcesHelper.GetDefaultDownloadFileName(product.Type); + var downloadUrl = resourcesHelper.GetDownloadUrl(product.Type); + } + + } +} + +public sealed class ResourcesHelper +{ + public string? GetDownloadUrl(OfferingType offeringType) + { + if (offeringType.IsDownloadable()) + { + // some code to do this... + return "TODO: get the download URL"; + } + + return null; + } + + public string? GetDefaultDownloadFileName(OfferingType offeringType) + { + if (offeringType.IsDownloadable()) + { + // some code to do this... + return "TODO: get the file name"; + } + + return null; + } +} \ No newline at end of file diff --git a/Original.cs b/Original.cs new file mode 100644 index 0000000..d9ddda2 --- /dev/null +++ b/Original.cs @@ -0,0 +1,80 @@ +namespace Original; + +public enum OfferingType +{ + Course, + Ebook, + Book, + Offline, + Template, +} + +public sealed record Product(int Id, OfferingType Type); + +public sealed class ProductHandler(ResourcesHelper resourcesHelper) +{ + public void Handle(Product product) + { + if (product.Type == OfferingType.Template || + product.Type == OfferingType.Ebook || + product.Type == OfferingType.Offline) + { + var fileName = resourcesHelper.GetDefaultDownloadFileName(product.Type); + var downloadUrl = resourcesHelper.GetDownloadUrl(product.Type); + } + + } +} + +public sealed class ResourcesHelper +{ + public string? GetDownloadUrl(OfferingType offeringType) + { + if (offeringType == OfferingType.Template || + offeringType == OfferingType.Ebook) + { + // some code to do this... + return "TODO: get the download URL"; + } + + return null; + } + + public string? GetDefaultDownloadFileName(OfferingType offeringType) + { + if (offeringType == OfferingType.Template || + offeringType == OfferingType.Ebook) + { + // some code to do this... + return "TODO: get the file name"; + } + + return null; + } +} + +/* +public sealed record DownloadableResource( + int Id, + int ProductId, + string DownloadUrl, + string DefaultDownloadFilename); + +public sealed class ProductHandler2(ResourcesHelper2 resourcesHelper) +{ + public void DoStuff(Product product) + { + var downloadableResource = resourcesHelper.GetDownloadable(product.Id); + // do stuff with downloadable resource + } +} + +public sealed class ResourcesHelper2 +{ + public DownloadableResource? GetDownloadable(int productId) + { + // TODO: go fetch this... + return null; + } +} +*/ \ No newline at end of file diff --git a/Types.cs b/Types.cs new file mode 100644 index 0000000..1d58ddc --- /dev/null +++ b/Types.cs @@ -0,0 +1,77 @@ +namespace TypesExample; + +public abstract class Product(int id) +{ + public int Id { get; } = id; +} +public class Template(int id) : Product(id) { } +public class Ebook(int id) : Product(id) { } +public class OfflineCourse(int id) : Product(id) { } + +public sealed class ProductHandler(ResourcesHelper resourcesHelper) +{ + public void DoStuff(Product product) + { + if (product is Template || + product is Ebook|| + product is OfflineCourse) + { + var fileName = resourcesHelper.GetDefaultDownloadFileName(product); + var downloadUrl = resourcesHelper.GetDownloadUrl(product); + } + } +} + +public sealed class ResourcesHelper +{ + public string? GetDownloadUrl(Product product) + { + if (product is Template || + product is Ebook|| + product is OfflineCourse) + { + // some code to do this... + return "TODO: get the download URL"; + } + + return null; + } + + public string? GetDefaultDownloadFileName(Product product) + { + if (product is Template || + product is Ebook|| + product is OfflineCourse) + { + // some code to do this... + return "TODO: get the file name"; + } + + return null; + } +} + + +public sealed record DownloadableResource( + int Id, + int ProductId, + string DownloadUrl, + string DefaultDownloadFilename); + +public sealed class ProductHandler2(ResourcesHelper2 resourcesHelper) +{ + public void DoStuff(Product product) + { + var downloadableResource = resourcesHelper.GetDownloadable(product.Id); + // do stuff with downloadable resource + } +} + +public sealed class ResourcesHelper2 +{ + public DownloadableResource? GetDownloadable(int productId) + { + // TODO: go fetch this... + return null; + } +} \ No newline at end of file diff --git a/enum.csproj b/enum.csproj new file mode 100644 index 0000000..c40e829 --- /dev/null +++ b/enum.csproj @@ -0,0 +1,14 @@ + + + + Exe + net8.0 + enable + enable + + + + + + + diff --git a/oo.cs b/oo.cs new file mode 100644 index 0000000..dbe05d2 --- /dev/null +++ b/oo.cs @@ -0,0 +1,47 @@ +using Optional; + +namespace OO; + +public enum OfferingType +{ + Course, + Ebook, + Book, + Template, + OfflineCourse, +} + +public class Product(int id, OfferingType type) +{ + public virtual Option GetDownloadUrl() + { + return Option.None(); + } + + public virtual Option GetDefaultDownloadFileName() + { + return Option.None(); + } +} + +public class DownloadProduct(int id, OfferingType type) : Product(id, type) +{ + public override Option GetDefaultDownloadFileName() + { + return Option.Some("Some Value"); + } + + public override Option GetDownloadUrl() + { + return Option.Some("Some Value"); + } +} + +public sealed class ProductHandler() +{ + public void DoStuff(Product product) + { + var fileName = product.GetDefaultDownloadFileName(); + var downloadUrl = product.GetDownloadUrl(); + } +} \ No newline at end of file diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..ea5ebf9 --- /dev/null +++ b/.gitignore @@ -0,0 +1,205 @@ +## Ignore Visual Studio temporary files, build results, and +## files generated by popular Visual Studio add-ons. + +# User-specific files +*.suo +*.user +*.sln.docstates + +# Build results +[Dd]ebug/ +[Dd]ebugPublic/ +[Rr]elease/ +x64/ +bld/ +[Bb]in/ +[Oo]bj/ + +# Roslyn cache directories +*.ide/ + +# AWS +*.aws-sam/ + +# MSTest test Results +[Tt]est[Rr]esult*/ +[Bb]uild[Ll]og.* + +#NUNIT +*.VisualState.xml +TestResult.xml + +# Build Results of an ATL Project +[Dd]ebugPS/ +[Rr]eleasePS/ +dlldata.c + +*_i.c +*_p.c +*_i.h +*.ilk +*.meta +*.obj +*.pch +*.pdb +*.pgc +*.pgd +*.rsp +*.sbr +*.tlb +*.tli +*.tlh +*.tmp +*.tmp_proj +*.log +*.vspscc +*.vssscc +.builds +*.pidb +*.svclog +*.scc + +# Chutzpah Test files +_Chutzpah* + +# Visual C++ cache files +ipch/ +*.aps +*.ncb +*.opensdf +*.sdf +*.cachefile + +# Visual Studio profiler +*.psess +*.vsp +*.vspx + +# TFS 2012 Local Workspace +$tf/ + +# Guidance Automation Toolkit +*.gpState + +# ReSharper is a .NET coding add-in +_ReSharper*/ +*.[Rr]e[Ss]harper +*.DotSettings.user + +# JustCode is a .NET coding addin-in +.JustCode + +# TeamCity is a build add-in +_TeamCity* + +# DotCover is a Code Coverage Tool +*.dotCover + +# NCrunch +_NCrunch_* +.*crunch*.local.xml + +# MightyMoose +*.mm.* +AutoTest.Net/ + +# Web workbench (sass) +.sass-cache/ + +# Installshield output folder +[Ee]xpress/ + +# DocProject is a documentation generator add-in +DocProject/buildhelp/ +DocProject/Help/*.HxT +DocProject/Help/*.HxC +DocProject/Help/*.hhc +DocProject/Help/*.hhk +DocProject/Help/*.hhp +DocProject/Help/Html2 +DocProject/Help/html + +# Click-Once directory +publish/ + +# Publish Web Output +*.[Pp]ublish.xml +*.azurePubxml +## TODO: Comment the next line if you want to checkin your +## web deploy settings but do note that will include unencrypted +## passwords +#*.pubxml + +# NuGet Packages Directory +#packages/* +## TODO: If the tool you use requires repositories.config +## uncomment the next line +#!packages/repositories.config + +# Enable "build/" folder in the NuGet Packages folder since +# NuGet packages use it for MSBuild targets. +# This line needs to be after the ignore of the build folder +# (and the packages folder if the line above has been uncommented) +#!packages/build/ + +!src/packages/**/*.dll +!src/packages/**/*.pdb + +# Windows Azure Build Output +csx/ +*.build.csdef + +# Windows Store app package directory +AppPackages/ + +# Others +*.Cache +ClientBin/ +[Ss]tyle[Cc]op.* +~$* +*~ +*.dbmdl +*.dbproj.schemaview +*.pfx +*.publishsettings +node_modules/ + +# RIA/Silverlight projects +Generated_Code/ + +# Backup & report files from converting an old project file +# to a newer Visual Studio version. Backup files are not needed, +# because we have git ;-) +_UpgradeReport_Files/ +Backup*/ +UpgradeLog*.XML +UpgradeLog*.htm + +# SQL Server files +*.mdf +*.ldf + +# Business Intelligence projects +*.rdl.data +*.bim.layout +*.bim_*.settings + +# Microsoft Fakes +FakesAssemblies/ + +# LightSwitch generated files +GeneratedArtifacts/ +_Pvt_Extensions/ +ModelManifest.xml +src/packages/EventStore.Client.3.3.1/lib/net40/EventStore.ClientAPI.xml + +# JetBrains Rider +.idea/ +*.sln.iml + +# Vagrant VM files +.vagrant +vagrant/dbv/data/meta/revision + +# Visual Studio 2015 cache/options directory +.vs/ \ No newline at end of file diff --git a/Extension.cs b/Extension.cs new file mode 100644 index 0000000..6cac789 --- /dev/null +++ b/Extension.cs @@ -0,0 +1,65 @@ +namespace ExtensionExample; + +public static class Extensions +{ + public static bool IsDownloadable(this OfferingType offeringType) + { + var validOfferings = new List() + { + OfferingType.Template, + OfferingType.Ebook, + OfferingType.OfflineCourse + }; + + return validOfferings.Contains(offeringType); + } +} + +public enum OfferingType +{ + Course, + Ebook, + Book, + Template, + OfflineCourse, +} + +public sealed record Product(int Id, OfferingType Type); + +public sealed class ProductHandler(ResourcesHelper resourcesHelper) +{ + public void DoStuff(Product product) + { + if (product.Type.IsDownloadable()) + { + var fileName = resourcesHelper.GetDefaultDownloadFileName(product.Type); + var downloadUrl = resourcesHelper.GetDownloadUrl(product.Type); + } + + } +} + +public sealed class ResourcesHelper +{ + public string? GetDownloadUrl(OfferingType offeringType) + { + if (offeringType.IsDownloadable()) + { + // some code to do this... + return "TODO: get the download URL"; + } + + return null; + } + + public string? GetDefaultDownloadFileName(OfferingType offeringType) + { + if (offeringType.IsDownloadable()) + { + // some code to do this... + return "TODO: get the file name"; + } + + return null; + } +} \ No newline at end of file diff --git a/Original.cs b/Original.cs new file mode 100644 index 0000000..d9ddda2 --- /dev/null +++ b/Original.cs @@ -0,0 +1,80 @@ +namespace Original; + +public enum OfferingType +{ + Course, + Ebook, + Book, + Offline, + Template, +} + +public sealed record Product(int Id, OfferingType Type); + +public sealed class ProductHandler(ResourcesHelper resourcesHelper) +{ + public void Handle(Product product) + { + if (product.Type == OfferingType.Template || + product.Type == OfferingType.Ebook || + product.Type == OfferingType.Offline) + { + var fileName = resourcesHelper.GetDefaultDownloadFileName(product.Type); + var downloadUrl = resourcesHelper.GetDownloadUrl(product.Type); + } + + } +} + +public sealed class ResourcesHelper +{ + public string? GetDownloadUrl(OfferingType offeringType) + { + if (offeringType == OfferingType.Template || + offeringType == OfferingType.Ebook) + { + // some code to do this... + return "TODO: get the download URL"; + } + + return null; + } + + public string? GetDefaultDownloadFileName(OfferingType offeringType) + { + if (offeringType == OfferingType.Template || + offeringType == OfferingType.Ebook) + { + // some code to do this... + return "TODO: get the file name"; + } + + return null; + } +} + +/* +public sealed record DownloadableResource( + int Id, + int ProductId, + string DownloadUrl, + string DefaultDownloadFilename); + +public sealed class ProductHandler2(ResourcesHelper2 resourcesHelper) +{ + public void DoStuff(Product product) + { + var downloadableResource = resourcesHelper.GetDownloadable(product.Id); + // do stuff with downloadable resource + } +} + +public sealed class ResourcesHelper2 +{ + public DownloadableResource? GetDownloadable(int productId) + { + // TODO: go fetch this... + return null; + } +} +*/ \ No newline at end of file diff --git a/Types.cs b/Types.cs new file mode 100644 index 0000000..1d58ddc --- /dev/null +++ b/Types.cs @@ -0,0 +1,77 @@ +namespace TypesExample; + +public abstract class Product(int id) +{ + public int Id { get; } = id; +} +public class Template(int id) : Product(id) { } +public class Ebook(int id) : Product(id) { } +public class OfflineCourse(int id) : Product(id) { } + +public sealed class ProductHandler(ResourcesHelper resourcesHelper) +{ + public void DoStuff(Product product) + { + if (product is Template || + product is Ebook|| + product is OfflineCourse) + { + var fileName = resourcesHelper.GetDefaultDownloadFileName(product); + var downloadUrl = resourcesHelper.GetDownloadUrl(product); + } + } +} + +public sealed class ResourcesHelper +{ + public string? GetDownloadUrl(Product product) + { + if (product is Template || + product is Ebook|| + product is OfflineCourse) + { + // some code to do this... + return "TODO: get the download URL"; + } + + return null; + } + + public string? GetDefaultDownloadFileName(Product product) + { + if (product is Template || + product is Ebook|| + product is OfflineCourse) + { + // some code to do this... + return "TODO: get the file name"; + } + + return null; + } +} + + +public sealed record DownloadableResource( + int Id, + int ProductId, + string DownloadUrl, + string DefaultDownloadFilename); + +public sealed class ProductHandler2(ResourcesHelper2 resourcesHelper) +{ + public void DoStuff(Product product) + { + var downloadableResource = resourcesHelper.GetDownloadable(product.Id); + // do stuff with downloadable resource + } +} + +public sealed class ResourcesHelper2 +{ + public DownloadableResource? GetDownloadable(int productId) + { + // TODO: go fetch this... + return null; + } +} \ No newline at end of file diff --git a/enum.csproj b/enum.csproj new file mode 100644 index 0000000..c40e829 --- /dev/null +++ b/enum.csproj @@ -0,0 +1,14 @@ + + + + Exe + net8.0 + enable + enable + + + + + + + diff --git a/oo.cs b/oo.cs new file mode 100644 index 0000000..dbe05d2 --- /dev/null +++ b/oo.cs @@ -0,0 +1,47 @@ +using Optional; + +namespace OO; + +public enum OfferingType +{ + Course, + Ebook, + Book, + Template, + OfflineCourse, +} + +public class Product(int id, OfferingType type) +{ + public virtual Option GetDownloadUrl() + { + return Option.None(); + } + + public virtual Option GetDefaultDownloadFileName() + { + return Option.None(); + } +} + +public class DownloadProduct(int id, OfferingType type) : Product(id, type) +{ + public override Option GetDefaultDownloadFileName() + { + return Option.Some("Some Value"); + } + + public override Option GetDownloadUrl() + { + return Option.Some("Some Value"); + } +} + +public sealed class ProductHandler() +{ + public void DoStuff(Product product) + { + var fileName = product.GetDefaultDownloadFileName(); + var downloadUrl = product.GetDownloadUrl(); + } +} \ No newline at end of file diff --git a/oo2.cs b/oo2.cs new file mode 100644 index 0000000..b2580d1 --- /dev/null +++ b/oo2.cs @@ -0,0 +1,39 @@ +using Optional; + +namespace OO2; + +public enum OfferingType +{ + Course, + Ebook, + Book, + Template, + OfflineCourse, +} + +public abstract class Product(int id, OfferingType type) +{ + +} + +public class DownloadableProduct(int id, OfferingType type) : Product(id, type) +{ + public Option GetDefaultDownloadFileName() + { + return Option.Some("Some Value"); + } + + public Option GetDownloadUrl() + { + return Option.Some("Some Value"); + } +} + +public sealed class ProductHandler() +{ + public void DoStuff(DownloadableProduct product) + { + var fileName = product.GetDefaultDownloadFileName(); + var downloadUrl = product.GetDownloadUrl(); + } +} \ No newline at end of file diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..ea5ebf9 --- /dev/null +++ b/.gitignore @@ -0,0 +1,205 @@ +## Ignore Visual Studio temporary files, build results, and +## files generated by popular Visual Studio add-ons. + +# User-specific files +*.suo +*.user +*.sln.docstates + +# Build results +[Dd]ebug/ +[Dd]ebugPublic/ +[Rr]elease/ +x64/ +bld/ +[Bb]in/ +[Oo]bj/ + +# Roslyn cache directories +*.ide/ + +# AWS +*.aws-sam/ + +# MSTest test Results +[Tt]est[Rr]esult*/ +[Bb]uild[Ll]og.* + +#NUNIT +*.VisualState.xml +TestResult.xml + +# Build Results of an ATL Project +[Dd]ebugPS/ +[Rr]eleasePS/ +dlldata.c + +*_i.c +*_p.c +*_i.h +*.ilk +*.meta +*.obj +*.pch +*.pdb +*.pgc +*.pgd +*.rsp +*.sbr +*.tlb +*.tli +*.tlh +*.tmp +*.tmp_proj +*.log +*.vspscc +*.vssscc +.builds +*.pidb +*.svclog +*.scc + +# Chutzpah Test files +_Chutzpah* + +# Visual C++ cache files +ipch/ +*.aps +*.ncb +*.opensdf +*.sdf +*.cachefile + +# Visual Studio profiler +*.psess +*.vsp +*.vspx + +# TFS 2012 Local Workspace +$tf/ + +# Guidance Automation Toolkit +*.gpState + +# ReSharper is a .NET coding add-in +_ReSharper*/ +*.[Rr]e[Ss]harper +*.DotSettings.user + +# JustCode is a .NET coding addin-in +.JustCode + +# TeamCity is a build add-in +_TeamCity* + +# DotCover is a Code Coverage Tool +*.dotCover + +# NCrunch +_NCrunch_* +.*crunch*.local.xml + +# MightyMoose +*.mm.* +AutoTest.Net/ + +# Web workbench (sass) +.sass-cache/ + +# Installshield output folder +[Ee]xpress/ + +# DocProject is a documentation generator add-in +DocProject/buildhelp/ +DocProject/Help/*.HxT +DocProject/Help/*.HxC +DocProject/Help/*.hhc +DocProject/Help/*.hhk +DocProject/Help/*.hhp +DocProject/Help/Html2 +DocProject/Help/html + +# Click-Once directory +publish/ + +# Publish Web Output +*.[Pp]ublish.xml +*.azurePubxml +## TODO: Comment the next line if you want to checkin your +## web deploy settings but do note that will include unencrypted +## passwords +#*.pubxml + +# NuGet Packages Directory +#packages/* +## TODO: If the tool you use requires repositories.config +## uncomment the next line +#!packages/repositories.config + +# Enable "build/" folder in the NuGet Packages folder since +# NuGet packages use it for MSBuild targets. +# This line needs to be after the ignore of the build folder +# (and the packages folder if the line above has been uncommented) +#!packages/build/ + +!src/packages/**/*.dll +!src/packages/**/*.pdb + +# Windows Azure Build Output +csx/ +*.build.csdef + +# Windows Store app package directory +AppPackages/ + +# Others +*.Cache +ClientBin/ +[Ss]tyle[Cc]op.* +~$* +*~ +*.dbmdl +*.dbproj.schemaview +*.pfx +*.publishsettings +node_modules/ + +# RIA/Silverlight projects +Generated_Code/ + +# Backup & report files from converting an old project file +# to a newer Visual Studio version. Backup files are not needed, +# because we have git ;-) +_UpgradeReport_Files/ +Backup*/ +UpgradeLog*.XML +UpgradeLog*.htm + +# SQL Server files +*.mdf +*.ldf + +# Business Intelligence projects +*.rdl.data +*.bim.layout +*.bim_*.settings + +# Microsoft Fakes +FakesAssemblies/ + +# LightSwitch generated files +GeneratedArtifacts/ +_Pvt_Extensions/ +ModelManifest.xml +src/packages/EventStore.Client.3.3.1/lib/net40/EventStore.ClientAPI.xml + +# JetBrains Rider +.idea/ +*.sln.iml + +# Vagrant VM files +.vagrant +vagrant/dbv/data/meta/revision + +# Visual Studio 2015 cache/options directory +.vs/ \ No newline at end of file diff --git a/Extension.cs b/Extension.cs new file mode 100644 index 0000000..6cac789 --- /dev/null +++ b/Extension.cs @@ -0,0 +1,65 @@ +namespace ExtensionExample; + +public static class Extensions +{ + public static bool IsDownloadable(this OfferingType offeringType) + { + var validOfferings = new List() + { + OfferingType.Template, + OfferingType.Ebook, + OfferingType.OfflineCourse + }; + + return validOfferings.Contains(offeringType); + } +} + +public enum OfferingType +{ + Course, + Ebook, + Book, + Template, + OfflineCourse, +} + +public sealed record Product(int Id, OfferingType Type); + +public sealed class ProductHandler(ResourcesHelper resourcesHelper) +{ + public void DoStuff(Product product) + { + if (product.Type.IsDownloadable()) + { + var fileName = resourcesHelper.GetDefaultDownloadFileName(product.Type); + var downloadUrl = resourcesHelper.GetDownloadUrl(product.Type); + } + + } +} + +public sealed class ResourcesHelper +{ + public string? GetDownloadUrl(OfferingType offeringType) + { + if (offeringType.IsDownloadable()) + { + // some code to do this... + return "TODO: get the download URL"; + } + + return null; + } + + public string? GetDefaultDownloadFileName(OfferingType offeringType) + { + if (offeringType.IsDownloadable()) + { + // some code to do this... + return "TODO: get the file name"; + } + + return null; + } +} \ No newline at end of file diff --git a/Original.cs b/Original.cs new file mode 100644 index 0000000..d9ddda2 --- /dev/null +++ b/Original.cs @@ -0,0 +1,80 @@ +namespace Original; + +public enum OfferingType +{ + Course, + Ebook, + Book, + Offline, + Template, +} + +public sealed record Product(int Id, OfferingType Type); + +public sealed class ProductHandler(ResourcesHelper resourcesHelper) +{ + public void Handle(Product product) + { + if (product.Type == OfferingType.Template || + product.Type == OfferingType.Ebook || + product.Type == OfferingType.Offline) + { + var fileName = resourcesHelper.GetDefaultDownloadFileName(product.Type); + var downloadUrl = resourcesHelper.GetDownloadUrl(product.Type); + } + + } +} + +public sealed class ResourcesHelper +{ + public string? GetDownloadUrl(OfferingType offeringType) + { + if (offeringType == OfferingType.Template || + offeringType == OfferingType.Ebook) + { + // some code to do this... + return "TODO: get the download URL"; + } + + return null; + } + + public string? GetDefaultDownloadFileName(OfferingType offeringType) + { + if (offeringType == OfferingType.Template || + offeringType == OfferingType.Ebook) + { + // some code to do this... + return "TODO: get the file name"; + } + + return null; + } +} + +/* +public sealed record DownloadableResource( + int Id, + int ProductId, + string DownloadUrl, + string DefaultDownloadFilename); + +public sealed class ProductHandler2(ResourcesHelper2 resourcesHelper) +{ + public void DoStuff(Product product) + { + var downloadableResource = resourcesHelper.GetDownloadable(product.Id); + // do stuff with downloadable resource + } +} + +public sealed class ResourcesHelper2 +{ + public DownloadableResource? GetDownloadable(int productId) + { + // TODO: go fetch this... + return null; + } +} +*/ \ No newline at end of file diff --git a/Types.cs b/Types.cs new file mode 100644 index 0000000..1d58ddc --- /dev/null +++ b/Types.cs @@ -0,0 +1,77 @@ +namespace TypesExample; + +public abstract class Product(int id) +{ + public int Id { get; } = id; +} +public class Template(int id) : Product(id) { } +public class Ebook(int id) : Product(id) { } +public class OfflineCourse(int id) : Product(id) { } + +public sealed class ProductHandler(ResourcesHelper resourcesHelper) +{ + public void DoStuff(Product product) + { + if (product is Template || + product is Ebook|| + product is OfflineCourse) + { + var fileName = resourcesHelper.GetDefaultDownloadFileName(product); + var downloadUrl = resourcesHelper.GetDownloadUrl(product); + } + } +} + +public sealed class ResourcesHelper +{ + public string? GetDownloadUrl(Product product) + { + if (product is Template || + product is Ebook|| + product is OfflineCourse) + { + // some code to do this... + return "TODO: get the download URL"; + } + + return null; + } + + public string? GetDefaultDownloadFileName(Product product) + { + if (product is Template || + product is Ebook|| + product is OfflineCourse) + { + // some code to do this... + return "TODO: get the file name"; + } + + return null; + } +} + + +public sealed record DownloadableResource( + int Id, + int ProductId, + string DownloadUrl, + string DefaultDownloadFilename); + +public sealed class ProductHandler2(ResourcesHelper2 resourcesHelper) +{ + public void DoStuff(Product product) + { + var downloadableResource = resourcesHelper.GetDownloadable(product.Id); + // do stuff with downloadable resource + } +} + +public sealed class ResourcesHelper2 +{ + public DownloadableResource? GetDownloadable(int productId) + { + // TODO: go fetch this... + return null; + } +} \ No newline at end of file diff --git a/enum.csproj b/enum.csproj new file mode 100644 index 0000000..c40e829 --- /dev/null +++ b/enum.csproj @@ -0,0 +1,14 @@ + + + + Exe + net8.0 + enable + enable + + + + + + + diff --git a/oo.cs b/oo.cs new file mode 100644 index 0000000..dbe05d2 --- /dev/null +++ b/oo.cs @@ -0,0 +1,47 @@ +using Optional; + +namespace OO; + +public enum OfferingType +{ + Course, + Ebook, + Book, + Template, + OfflineCourse, +} + +public class Product(int id, OfferingType type) +{ + public virtual Option GetDownloadUrl() + { + return Option.None(); + } + + public virtual Option GetDefaultDownloadFileName() + { + return Option.None(); + } +} + +public class DownloadProduct(int id, OfferingType type) : Product(id, type) +{ + public override Option GetDefaultDownloadFileName() + { + return Option.Some("Some Value"); + } + + public override Option GetDownloadUrl() + { + return Option.Some("Some Value"); + } +} + +public sealed class ProductHandler() +{ + public void DoStuff(Product product) + { + var fileName = product.GetDefaultDownloadFileName(); + var downloadUrl = product.GetDownloadUrl(); + } +} \ No newline at end of file diff --git a/oo2.cs b/oo2.cs new file mode 100644 index 0000000..b2580d1 --- /dev/null +++ b/oo2.cs @@ -0,0 +1,39 @@ +using Optional; + +namespace OO2; + +public enum OfferingType +{ + Course, + Ebook, + Book, + Template, + OfflineCourse, +} + +public abstract class Product(int id, OfferingType type) +{ + +} + +public class DownloadableProduct(int id, OfferingType type) : Product(id, type) +{ + public Option GetDefaultDownloadFileName() + { + return Option.Some("Some Value"); + } + + public Option GetDownloadUrl() + { + return Option.Some("Some Value"); + } +} + +public sealed class ProductHandler() +{ + public void DoStuff(DownloadableProduct product) + { + var fileName = product.GetDefaultDownloadFileName(); + var downloadUrl = product.GetDownloadUrl(); + } +} \ No newline at end of file diff --git a/oo3.cs b/oo3.cs new file mode 100644 index 0000000..a49248a --- /dev/null +++ b/oo3.cs @@ -0,0 +1,40 @@ +using Optional; + +namespace OO3; + +public class OfferingType +{ + public virtual Option GetDownloadUrl() + { + return Option.None(); + } + + public virtual Option GetDefaultDownloadFileName() + { + return Option.None(); + } +} + +public class DownloadableContent : OfferingType +{ + public override Option GetDownloadUrl() + { + return Option.Some("Some value"); + } + + public override Option GetDefaultDownloadFileName() + { + return Option.Some("Some value"); + } +} + +public sealed record Product(int Id, OfferingType Type); + +public sealed class ProductHandler() +{ + public void DoStuff(Product product) + { + var fileName = product.Type.GetDefaultDownloadFileName(); + var downloadUrl = product.Type.GetDownloadUrl(); + } +} \ No newline at end of file