Generator { get; private set; }
41 |
42 | public object Generate()
43 | {
44 | return Generator.Generate();
45 | }
46 | }
47 |
48 | public class Mapping : IMapping
49 | {
50 | public Mapping(PropertyInfo propertyInfo, IGenerator generator)
51 | {
52 | PropertyName = propertyInfo.Name;
53 | PropertyInfo = propertyInfo;
54 | Generator = generator;
55 | }
56 |
57 | public string PropertyName { get; private set; }
58 | public PropertyInfo PropertyInfo { get; private set; }
59 | public IGenerator Generator { get; private set; }
60 |
61 | public object Generate()
62 | {
63 | return Generator.Generate();
64 | }
65 | }
66 | }
67 |
--------------------------------------------------------------------------------
/Foundation.ObjectHydrator/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | using System.Reflection;
2 | using System.Runtime.InteropServices;
3 |
4 | // General Information about an assembly is controlled through the following
5 | // set of attributes. Change these attribute values to modify the information
6 | // associated with an assembly.
7 | [assembly: AssemblyTitle("Foundation.ObjectHydrator")]
8 | [assembly: AssemblyDescription("")]
9 | [assembly: AssemblyConfiguration("")]
10 | [assembly: AssemblyCompany("")]
11 | [assembly: AssemblyProduct("Foundation.ObjectHydrator")]
12 | [assembly: AssemblyCopyright("Copyright © 2009")]
13 | [assembly: AssemblyTrademark("")]
14 | [assembly: AssemblyCulture("")]
15 |
16 | // Setting ComVisible to false makes the types in this assembly not visible
17 | // to COM components. If you need to access a type in this assembly from
18 | // COM, set the ComVisible attribute to true on that type.
19 | [assembly: ComVisible(false)]
20 |
21 | // The following GUID is for the ID of the typelib if this project is exposed to COM
22 | [assembly: Guid("688a0d31-a745-4722-95fb-1eb94964b042")]
23 |
24 | // Version information for an assembly consists of the following four values:
25 | //
26 | // Major Version
27 | // Minor Version
28 | // Build Number
29 | // Revision
30 | //
31 | // You can specify all the values or you can default the Build and Revision Numbers
32 | // by using the '*' as shown below:
33 | // [assembly: AssemblyVersion("1.0.*")]
34 | [assembly: AssemblyVersion("1.3.0.0")]
35 | [assembly: AssemblyFileVersion("1.3.0.0")]
36 |
--------------------------------------------------------------------------------
/Foundation.ObjectHydrator/RandomSingleton.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace Foundation.ObjectHydrator
4 | {
5 | public sealed class RandomSingleton
6 | {
7 | private static readonly object SyncRoot = new Object();
8 | private static volatile RandomSingleton instance;
9 |
10 | public Random Random { get; private set; }
11 |
12 | private RandomSingleton()
13 | {
14 | Random = new Random();
15 | }
16 |
17 | public static RandomSingleton Instance
18 | {
19 | get
20 | {
21 | if (instance == null)
22 | {
23 | lock (SyncRoot)
24 | {
25 | if (instance == null)
26 | instance = new RandomSingleton();
27 | }
28 | }
29 |
30 | return instance;
31 | }
32 | }
33 | }
34 | }
--------------------------------------------------------------------------------
/Foundation.ObjectHydrator/Readme.htm:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 | Object Hydrator
10 |
11 | Version 0.6
12 | 10/28/2009
13 |
14 | Introduction:
15 | Object Hydrator is a tool to ease the "Model First" development style and
16 | testing scenarios, by generating objects with pre-filled data. Doing so
17 | allows you the freedom of working in your application with 'realistic' data at
18 | the same time giving you the flexibility to make changes to your model on the
19 | fly.
20 |
21 | Using convention over configuration, Object Hydrator will pick an appropriate
22 | data type based on the type in the model and/or the name of the property and
23 | generate the data for you automatically. With a fluent interface you can
24 | override these conventions easily and smoothly.
25 |
26 | A very simple example is as follows:
27 | Given this class
28 |
29 | public class Customer
30 | {
31 | public string FirstName {get;set;}
32 | }
33 |
34 | You can populate an instance of this class with a random real-world first name
35 | by first creating an instance of the Hydrator like so...
36 |
37 | Hydrator<Customer> hydrator=new Hydrator<Customer>();
38 |
39 | And then call the GetSingle method assigning it to a new customer object like
40 | this....
41 |
42 | Customer mynewcustomer=hydrator.GetSingle();
43 |
44 | You can also inject your own generators at instantiation time, as long as the implement the IGenerator interface. See Hydrator_InjectedGenerator_Test.cs
45 |
46 |
47 | For more detailed examples please see the unit tests in
48 | Hydrator_SimpleCustomerTests.cs or the SampleWebApplication
49 |
50 | Please see
51 | http://objecthydrator.codeplex.com for samples and documentation.
52 |
53 | Special Thanks for his excellent code to:
54 | Scott Monnig
55 |
56 |
57 |
--------------------------------------------------------------------------------
/Foundation.ObjectHydrator/_CreateNewNuGetPackage/Config.ps1:
--------------------------------------------------------------------------------
1 | #==========================================================
2 | # Edit the variable values below to configure how your .nupkg file is packed (i.e. created) and pushed (i.e. uploaded) to the NuGet gallery.
3 | #
4 | # If you have modified this script:
5 | # - if you uninstall the "Create New NuGet Package From Project After Each Build" package, this file may not be removed automatically; you may need to manually delete it.
6 | # - if you update the "Create New NuGet Package From Project After Each Build" package, this file may not be updated unless you specify it to be overwritten, either by
7 | # confirming the overwrite if prompted, or by providing the "-FileConflictAction Overwrite" parameter when installing from the command line.
8 | # If you overwrite this file then your custom changes will be lost, and you will need to manually reapply your changes.
9 | # If you are not using source control, I recommend backing up this file before updating the package so you can see what changes you had made to it.
10 | #==========================================================
11 |
12 | #------------------------------------------------
13 | # Pack parameters used to create the .nupkg file.
14 | #------------------------------------------------
15 |
16 | # Specify the Version Number to use for the NuGet package. If not specified, the version number of the assembly being packed will be used.
17 | # NuGet version number guidance: https://docs.nuget.org/docs/reference/versioning and the Semantic Versioning spec: http://semver.org/
18 | # e.g. "" (use assembly's version), "1.2.3" (stable version), "1.2.3-alpha" (prerelease version).
19 | $versionNumber = "1.3.0"
20 |
21 | # Specify any Release Notes for this package.
22 | # These will only be included in the package if you have a .nuspec file for the project in the same directory as the project file.
23 | $releaseNotes = ""
24 |
25 | # Specify a specific Configuration and/or Platform to only create a NuGet package when building the project with this Configuration and/or Platform.
26 | # e.g. $configuration = "Release"
27 | # $platform = "AnyCPU"
28 | $configuration = ""
29 | $platform = ""
30 |
31 | # Specify any NuGet Pack Properties to pass to MsBuild.
32 | # e.g. $packProperties = "TargetFrameworkVersion=v3.5;Optimize=true"
33 | # Do not specify the "Configuration" or "Platform" here; use the $configuration and $platform variables above.
34 | # MsBuild Properties that can be specified: http://msdn.microsoft.com/en-us/library/vstudio/bb629394.aspx
35 | $packProperties = ""
36 |
37 | # Specify any NuGet Pack options to pass to nuget.exe.
38 | # e.g. $packOptions = "-Symbols"
39 | # e.g. $packOptions = "-IncludeReferencedProjects -Symbols"
40 | # Do not specify a "-Version" (use $versionNumber above), "-OutputDirectory", or "-NonInteractive", as these are already provided.
41 | # Do not specify any "-Properties" here; instead use the $packProperties variable above.
42 | # Do not specify "-Build", as this may result in an infinite build loop.
43 | # NuGet Pack options that can be specified: http://docs.nuget.org/docs/reference/command-line-reference#Pack_Command_Options
44 | # Use "-Symbols" to also create a symbols package. When pushing your package, the symbols package will automatically be detected and pushed as well: https://www.symbolsource.org/Public/Wiki/Publishing
45 | $packOptions = ""
46 |
47 | # Specify $true if the generated .nupkg file should be renamed to include the Configuration and Platform that was used to build the project, $false if not.
48 | # e.g. If $true, MyProject.1.1.5.6.nupkg might be renamed to MyProject.1.1.5.6.Debug.AnyCPU.nupkg
49 | # e.g. If $true, MyProject.1.1.5.6-beta1.nupkg might re renamed to MyProject.1.1.5.6-beta1.Release.x86.nupkg
50 | $appendConfigurationAndPlatformToNuGetPackageFileName = $true
51 |
52 |
53 | #------------------------------------------------
54 | # Push parameters used to upload the .nupkg file to the NuGet gallery.
55 | #------------------------------------------------
56 |
57 | # The NuGet gallery to upload to. If not provided, the DefaultPushSource in your NuGet.config file is used (typically nuget.org).
58 | $sourceToUploadTo = ""
59 |
60 | # The API Key to use to upload the package to the gallery. If not provided and a system-level one does not exist for the specified Source, you will be prompted for it.
61 | $apiKey = ""
62 |
63 | # Specify any NuGet Push options to pass to nuget.exe.
64 | # e.g. $pushOptions = "-Timeout 120"
65 | # Do not specify the "-Source" or "-ApiKey" here; use the variables above.
66 | # NuGet Push options that can be specified: http://docs.nuget.org/docs/reference/command-line-reference#Push_Command_Options
67 | $pushOptions = ""
68 |
--------------------------------------------------------------------------------
/Foundation.ObjectHydrator/_CreateNewNuGetPackage/DoNotModify/NuGet.exe:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/PrintsCharming/ObjectHydrator/bfe5f4cc59675c110916dda70e11068f68808eb5/Foundation.ObjectHydrator/_CreateNewNuGetPackage/DoNotModify/NuGet.exe
--------------------------------------------------------------------------------
/Foundation.ObjectHydrator/_CreateNewNuGetPackage/DoNotModify/UploadNuGetPackage.ps1:
--------------------------------------------------------------------------------
1 | #==========================================================
2 | # DO NOT EDIT THIS FILE.
3 | # If you want to configure how your package is uploaded, modify the Config.ps1 file.
4 | # To run this script from inside Visual Studio, right-click on the "RunMeToUploadNuGetPackage.cmd" file and choose "Run".
5 | #==========================================================
6 |
7 | # Turn on Strict Mode to help catch syntax-related errors.
8 | # This must come after a script's/function's param section.
9 | # Forces a function to be the first non-comment code to appear in a PowerShell Module.
10 | Set-StrictMode -Version Latest
11 |
12 | # PowerShell v2.0 compatible version of [string]::IsNullOrWhitespace.
13 | function Test-StringIsNullOrWhitespace([string]$string)
14 | {
15 | if ($string -ne $null) { $string = $string.Trim() }
16 | return [string]::IsNullOrEmpty($string)
17 | }
18 |
19 | # Get the directory that this script is in.
20 | $THIS_SCRIPTS_DIRECTORY_PATH = Split-Path $script:MyInvocation.MyCommand.Path
21 |
22 | # Get the path to the Config file and dot source it into this script.
23 | # The variables below should be defined in the Config file, but if they aren't we initialize them with default values.
24 | $CONFIG_FILE_PATH = Join-Path -Path (Split-Path -Path $THIS_SCRIPTS_DIRECTORY_PATH -Parent) -ChildPath 'Config.ps1'
25 | if (Test-Path -Path $CONFIG_FILE_PATH) { . $CONFIG_FILE_PATH }
26 | else { Write-Warning "Could not find Config file at '$CONFIG_FILE_PATH'. Default values will be used instead." }
27 |
28 | # The NuGet gallery to upload to. If not provided, the DefaultPushSource in your NuGet.config file is used (typically nuget.org).
29 | if (!(Test-Path Variable:Private:sourceToUploadTo) -or (Test-StringIsNullOrWhitespace $sourceToUploadTo)) { $sourceToUploadTo = ""; Write-Output "Using default Source To Upload To value." }
30 | else { Write-Output "Using user-specified Source To Update To value '$sourceToUploadTo'." }
31 |
32 | # The API Key to use to upload the package to the gallery. If not provided and a system-level one does not exist for the specified Source, you will be prompted for it.
33 | if (!(Test-Path Variable:Private:apiKey) -or (Test-StringIsNullOrWhitespace $apiKey)) { $apiKey = ""; Write-Output "Using default API Key value." }
34 | else { Write-Output "Using user-specified API Key value [value not shown here for security purposes]." }
35 |
36 | # Specify any NuGet Push options to pass to nuget.exe.
37 | # Do not specify the "-Source" or "-ApiKey" here; use the variables above.
38 | if (!(Test-Path Variable:Private:pushOptions) -or (Test-StringIsNullOrWhitespace $pushOptions)) { $pushOptions = ""; Write-Output "Using default Push Options value." }
39 | else { Write-Output "Using user-specified Push Options value '$pushOptions'." }
40 |
41 | # Add the Source and ApiKey to the Push Options if there were provided.
42 | if (!(Test-StringIsNullOrWhitespace $sourceToUploadTo)) { $pushOptions += " -Source ""$sourceToUploadTo"" " }
43 | if (!(Test-StringIsNullOrWhitespace $apiKey)) { $pushOptions += " -ApiKey ""$apiKey"" " }
44 |
45 | # Upload the new NuGet package.
46 | & "$THIS_SCRIPTS_DIRECTORY_PATH\New-NuGetPackage.ps1" -PushOptions "$pushOptions" -Verbose
--------------------------------------------------------------------------------
/Foundation.ObjectHydrator/_CreateNewNuGetPackage/RunMeToUploadNuGetPackage.cmd:
--------------------------------------------------------------------------------
1 | @ECHO OFF
2 | REM === DO NOT EDIT THIS FILE ===
3 | REM Run this script to upload a NuGet package to the NuGet gallery.
4 | REM When you run this script it will prompt you for a NuGet package file (.nupkg) and then upload it to the NuGet gallery.
5 | REM The project's .nupkg file should be in the same directory as the project's .dll/.exe file (typically bin\Debug or bin\Release).
6 | REM You may edit the Config.ps1 file to adjust the settings used to upload the package to the NuGet gallery.
7 | REM To run this script from within Visual Studio, right-click on this file from the Solution Explorer and choose Run.
8 | SET THIS_SCRIPTS_DIRECTORY=%~dp0
9 | PowerShell -NoProfile -ExecutionPolicy Bypass -Command "& '%THIS_SCRIPTS_DIRECTORY%DoNotModify\UploadNuGetPackage.ps1'"
--------------------------------------------------------------------------------
/Foundation.ObjectHydrator/packages.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
--------------------------------------------------------------------------------
/Foundation.sln:
--------------------------------------------------------------------------------
1 |
2 | Microsoft Visual Studio Solution File, Format Version 12.00
3 | # Visual Studio 2013
4 | VisualStudioVersion = 12.0.30723.0
5 | MinimumVisualStudioVersion = 10.0.40219.1
6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Foundation.ObjectHydrator", "Foundation.ObjectHydrator\Foundation.ObjectHydrator.csproj", "{8B60029E-DC22-4019-8AD6-E6A6A0CAEBFA}"
7 | EndProject
8 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Foundation.ObjectHydrator.Tests", "Foundation.ObjectHydrator.Tests\Foundation.ObjectHydrator.Tests.csproj", "{44E61D49-4DA0-448C-928E-2907951DD381}"
9 | EndProject
10 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SampleWebApplication", "SampleWebApplication\SampleWebApplication.csproj", "{D43EF567-08DE-479D-9D03-1820595911CF}"
11 | EndProject
12 | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = ".nuget", ".nuget", "{9DD54A53-8184-44B1-AF98-0FEAC42B6EA1}"
13 | ProjectSection(SolutionItems) = preProject
14 | .nuget\packages.config = .nuget\packages.config
15 | EndProjectSection
16 | EndProject
17 | Global
18 | GlobalSection(SolutionConfigurationPlatforms) = preSolution
19 | Debug|Any CPU = Debug|Any CPU
20 | Release|Any CPU = Release|Any CPU
21 | EndGlobalSection
22 | GlobalSection(ProjectConfigurationPlatforms) = postSolution
23 | {8B60029E-DC22-4019-8AD6-E6A6A0CAEBFA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
24 | {8B60029E-DC22-4019-8AD6-E6A6A0CAEBFA}.Debug|Any CPU.Build.0 = Debug|Any CPU
25 | {8B60029E-DC22-4019-8AD6-E6A6A0CAEBFA}.Release|Any CPU.ActiveCfg = Release|Any CPU
26 | {8B60029E-DC22-4019-8AD6-E6A6A0CAEBFA}.Release|Any CPU.Build.0 = Release|Any CPU
27 | {44E61D49-4DA0-448C-928E-2907951DD381}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
28 | {44E61D49-4DA0-448C-928E-2907951DD381}.Debug|Any CPU.Build.0 = Debug|Any CPU
29 | {44E61D49-4DA0-448C-928E-2907951DD381}.Release|Any CPU.ActiveCfg = Release|Any CPU
30 | {44E61D49-4DA0-448C-928E-2907951DD381}.Release|Any CPU.Build.0 = Release|Any CPU
31 | {D43EF567-08DE-479D-9D03-1820595911CF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
32 | {D43EF567-08DE-479D-9D03-1820595911CF}.Debug|Any CPU.Build.0 = Debug|Any CPU
33 | {D43EF567-08DE-479D-9D03-1820595911CF}.Release|Any CPU.ActiveCfg = Release|Any CPU
34 | {D43EF567-08DE-479D-9D03-1820595911CF}.Release|Any CPU.Build.0 = Release|Any CPU
35 | EndGlobalSection
36 | GlobalSection(SolutionProperties) = preSolution
37 | HideSolutionNode = FALSE
38 | EndGlobalSection
39 | GlobalSection(SubversionScc) = preSolution
40 | Svn-Managed = True
41 | Manager = AnkhSVN - Subversion Support for Visual Studio
42 | EndGlobalSection
43 | EndGlobal
44 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | Apache License
2 | Version 2.0, January 2004
3 | http://www.apache.org/licenses/
4 |
5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6 |
7 | 1. Definitions.
8 |
9 | "License" shall mean the terms and conditions for use, reproduction,
10 | and distribution as defined by Sections 1 through 9 of this document.
11 |
12 | "Licensor" shall mean the copyright owner or entity authorized by
13 | the copyright owner that is granting the License.
14 |
15 | "Legal Entity" shall mean the union of the acting entity and all
16 | other entities that control, are controlled by, or are under common
17 | control with that entity. For the purposes of this definition,
18 | "control" means (i) the power, direct or indirect, to cause the
19 | direction or management of such entity, whether by contract or
20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the
21 | outstanding shares, or (iii) beneficial ownership of such entity.
22 |
23 | "You" (or "Your") shall mean an individual or Legal Entity
24 | exercising permissions granted by this License.
25 |
26 | "Source" form shall mean the preferred form for making modifications,
27 | including but not limited to software source code, documentation
28 | source, and configuration files.
29 |
30 | "Object" form shall mean any form resulting from mechanical
31 | transformation or translation of a Source form, including but
32 | not limited to compiled object code, generated documentation,
33 | and conversions to other media types.
34 |
35 | "Work" shall mean the work of authorship, whether in Source or
36 | Object form, made available under the License, as indicated by a
37 | copyright notice that is included in or attached to the work
38 | (an example is provided in the Appendix below).
39 |
40 | "Derivative Works" shall mean any work, whether in Source or Object
41 | form, that is based on (or derived from) the Work and for which the
42 | editorial revisions, annotations, elaborations, or other modifications
43 | represent, as a whole, an original work of authorship. For the purposes
44 | of this License, Derivative Works shall not include works that remain
45 | separable from, or merely link (or bind by name) to the interfaces of,
46 | the Work and Derivative Works thereof.
47 |
48 | "Contribution" shall mean any work of authorship, including
49 | the original version of the Work and any modifications or additions
50 | to that Work or Derivative Works thereof, that is intentionally
51 | submitted to Licensor for inclusion in the Work by the copyright owner
52 | or by an individual or Legal Entity authorized to submit on behalf of
53 | the copyright owner. For the purposes of this definition, "submitted"
54 | means any form of electronic, verbal, or written communication sent
55 | to the Licensor or its representatives, including but not limited to
56 | communication on electronic mailing lists, source code control systems,
57 | and issue tracking systems that are managed by, or on behalf of, the
58 | Licensor for the purpose of discussing and improving the Work, but
59 | excluding communication that is conspicuously marked or otherwise
60 | designated in writing by the copyright owner as "Not a Contribution."
61 |
62 | "Contributor" shall mean Licensor and any individual or Legal Entity
63 | on behalf of whom a Contribution has been received by Licensor and
64 | subsequently incorporated within the Work.
65 |
66 | 2. Grant of Copyright License. Subject to the terms and conditions of
67 | this License, each Contributor hereby grants to You a perpetual,
68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69 | copyright license to reproduce, prepare Derivative Works of,
70 | publicly display, publicly perform, sublicense, and distribute the
71 | Work and such Derivative Works in Source or Object form.
72 |
73 | 3. Grant of Patent License. Subject to the terms and conditions of
74 | this License, each Contributor hereby grants to You a perpetual,
75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76 | (except as stated in this section) patent license to make, have made,
77 | use, offer to sell, sell, import, and otherwise transfer the Work,
78 | where such license applies only to those patent claims licensable
79 | by such Contributor that are necessarily infringed by their
80 | Contribution(s) alone or by combination of their Contribution(s)
81 | with the Work to which such Contribution(s) was submitted. If You
82 | institute patent litigation against any entity (including a
83 | cross-claim or counterclaim in a lawsuit) alleging that the Work
84 | or a Contribution incorporated within the Work constitutes direct
85 | or contributory patent infringement, then any patent licenses
86 | granted to You under this License for that Work shall terminate
87 | as of the date such litigation is filed.
88 |
89 | 4. Redistribution. You may reproduce and distribute copies of the
90 | Work or Derivative Works thereof in any medium, with or without
91 | modifications, and in Source or Object form, provided that You
92 | meet the following conditions:
93 |
94 | (a) You must give any other recipients of the Work or
95 | Derivative Works a copy of this License; and
96 |
97 | (b) You must cause any modified files to carry prominent notices
98 | stating that You changed the files; and
99 |
100 | (c) You must retain, in the Source form of any Derivative Works
101 | that You distribute, all copyright, patent, trademark, and
102 | attribution notices from the Source form of the Work,
103 | excluding those notices that do not pertain to any part of
104 | the Derivative Works; and
105 |
106 | (d) If the Work includes a "NOTICE" text file as part of its
107 | distribution, then any Derivative Works that You distribute must
108 | include a readable copy of the attribution notices contained
109 | within such NOTICE file, excluding those notices that do not
110 | pertain to any part of the Derivative Works, in at least one
111 | of the following places: within a NOTICE text file distributed
112 | as part of the Derivative Works; within the Source form or
113 | documentation, if provided along with the Derivative Works; or,
114 | within a display generated by the Derivative Works, if and
115 | wherever such third-party notices normally appear. The contents
116 | of the NOTICE file are for informational purposes only and
117 | do not modify the License. You may add Your own attribution
118 | notices within Derivative Works that You distribute, alongside
119 | or as an addendum to the NOTICE text from the Work, provided
120 | that such additional attribution notices cannot be construed
121 | as modifying the License.
122 |
123 | You may add Your own copyright statement to Your modifications and
124 | may provide additional or different license terms and conditions
125 | for use, reproduction, or distribution of Your modifications, or
126 | for any such Derivative Works as a whole, provided Your use,
127 | reproduction, and distribution of the Work otherwise complies with
128 | the conditions stated in this License.
129 |
130 | 5. Submission of Contributions. Unless You explicitly state otherwise,
131 | any Contribution intentionally submitted for inclusion in the Work
132 | by You to the Licensor shall be under the terms and conditions of
133 | this License, without any additional terms or conditions.
134 | Notwithstanding the above, nothing herein shall supersede or modify
135 | the terms of any separate license agreement you may have executed
136 | with Licensor regarding such Contributions.
137 |
138 | 6. Trademarks. This License does not grant permission to use the trade
139 | names, trademarks, service marks, or product names of the Licensor,
140 | except as required for reasonable and customary use in describing the
141 | origin of the Work and reproducing the content of the NOTICE file.
142 |
143 | 7. Disclaimer of Warranty. Unless required by applicable law or
144 | agreed to in writing, Licensor provides the Work (and each
145 | Contributor provides its Contributions) on an "AS IS" BASIS,
146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147 | implied, including, without limitation, any warranties or conditions
148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149 | PARTICULAR PURPOSE. You are solely responsible for determining the
150 | appropriateness of using or redistributing the Work and assume any
151 | risks associated with Your exercise of permissions under this License.
152 |
153 | 8. Limitation of Liability. In no event and under no legal theory,
154 | whether in tort (including negligence), contract, or otherwise,
155 | unless required by applicable law (such as deliberate and grossly
156 | negligent acts) or agreed to in writing, shall any Contributor be
157 | liable to You for damages, including any direct, indirect, special,
158 | incidental, or consequential damages of any character arising as a
159 | result of this License or out of the use or inability to use the
160 | Work (including but not limited to damages for loss of goodwill,
161 | work stoppage, computer failure or malfunction, or any and all
162 | other commercial damages or losses), even if such Contributor
163 | has been advised of the possibility of such damages.
164 |
165 | 9. Accepting Warranty or Additional Liability. While redistributing
166 | the Work or Derivative Works thereof, You may choose to offer,
167 | and charge a fee for, acceptance of support, warranty, indemnity,
168 | or other liability obligations and/or rights consistent with this
169 | License. However, in accepting such obligations, You may act only
170 | on Your own behalf and on Your sole responsibility, not on behalf
171 | of any other Contributor, and only if You agree to indemnify,
172 | defend, and hold each Contributor harmless for any liability
173 | incurred by, or claims asserted against, such Contributor by reason
174 | of your accepting any such warranty or additional liability.
175 |
176 | END OF TERMS AND CONDITIONS
177 |
178 | APPENDIX: How to apply the Apache License to your work.
179 |
180 | To apply the Apache License to your work, attach the following
181 | boilerplate notice, with the fields enclosed by brackets "{}"
182 | replaced with your own identifying information. (Don't include
183 | the brackets!) The text should be enclosed in the appropriate
184 | comment syntax for the file format. We also recommend that a
185 | file or class name and description of purpose be included on the
186 | same "printed page" as the copyright notice for easier
187 | identification within third-party archives.
188 |
189 | Copyright {yyyy} {name of copyright owner}
190 |
191 | Licensed under the Apache License, Version 2.0 (the "License");
192 | you may not use this file except in compliance with the License.
193 | You may obtain a copy of the License at
194 |
195 | http://www.apache.org/licenses/LICENSE-2.0
196 |
197 | Unless required by applicable law or agreed to in writing, software
198 | distributed under the License is distributed on an "AS IS" BASIS,
199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200 | See the License for the specific language governing permissions and
201 | limitations under the License.
--------------------------------------------------------------------------------
/Packages.dgml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
19 |
20 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | ObjectHydrator
2 | ==============
3 |
4 | This project allows you to pass custom POCO's to it, and have it return an instance of the class populated with randomly generated but real-world looking data. This random data can be overridden by convention.
5 |
6 | **Basic syntax looks like this:**
7 |
8 | ```csharp
9 | Hydrator _customerHydrator = new Hydrator();
10 | Customer customer = _customerHydrator.GetSingle();
11 | List customerlist=_customerHydrator.GetList(20);
12 | ```
13 |
14 | **Advanced syntax looks like:**
15 |
16 | ```csharp
17 | Hydrator _customerHydrator = new Hydrator()
18 | .WithInteger(x => x.CustomerAge, 1, 100)
19 | .WithAmericanPhone(x=>x.CustomerPhone);
20 | ```
21 |
22 | **A custom generator looks like:**
23 |
24 | ```csharp
25 | public class FullNameGenerator : IGenerator
26 | {
27 | static readonly IGenerator FirstNameGen = new FirstNameGenerator();
28 | static readonly IGenerator LastNameGen = new LastNameGenerator();
29 |
30 | public string Generate()
31 | {
32 | return FirstNameGen.Generate() + " " + LastNameGen.Generate();
33 | }
34 | }
35 | ```
36 |
37 | Use a custom generator like this:
38 |
39 | ```csharp
40 | Hydrator _customerHydrator = new Hydrator()
41 | .With(x => x.FullName, new FullNameGenerator());
42 | ```
43 |
44 | ## Changes
45 |
46 | Version 1.3.0
47 | * Added 3 new generators UnitedKingdomPhoneNumberGenerator, UnitedKingdomInsuranceNumberGenerator, and CulturesGenerator thanks to rikrak and ushenkodmitry
48 | * "Do" method to allow a property to be set from the generated values in other properties, thanks to rikrak
49 | * Fixed randomization method which was excluding the last possible, thanks to rikrak and ushenkodmitry
50 |
51 | Version 1.1.0
52 | * Added the ability to respect the StringLength property attribute from System.ComponentModel.DataAnnotations (more annotations are welcome and likely)
53 |
54 | Version 1.0.0
55 |
56 | * Added the ability to inject Generators at instantiation time. Which looks like this:
57 | `var hydrator = new Hydrator().WithCustomGenerator(x=>x.State, new InjectedGenerator());`
58 |
59 | Version 0.7.0
60 |
61 | * Added new generators: UnitedKingdomCityGenerator, UnitedKingdomCountyGenerator, UnitedKingdomPostcodeGenerator, AlphaNumericGenerator.
62 |
63 | ## NuGet [#objecthydrator](http://www.nuget.org/packages/objecthydrator/)
64 |
65 | Install-Package objecthydrator
66 |
67 | This version is for Visual Studio 2010 .Net 4. I'll switch to a newer version and use 2013 if there is interest.
68 |
69 | ## Summary
70 |
71 | So basically, you create a class and invoke the Hydrator object with that class type. Then call the `GetSingle` or `GetList` functions and you are returned an instance of the object populated with realistic data. The idea behind it is to use it to replace a database call to use in your UI.
72 |
73 | ## Generators
74 |
75 | Presently the generators are pretty simple and can generate limited values, they include:
76 |
77 | Generator | Description | Notes
78 | ----------|-------------|--------
79 | FirstName | Returns a random english First Name
80 | LastName | Return a random english Last Name
81 | DateTimeGenerator | Returns a random Date within a given range.
82 | AmericanPhone | Returns a randon American Phone Number
83 | AmericanAddress | Returns a random American Address (street part)
84 | AmericanCity | Returns a random American City
85 | AmericanPostalCode | Returns a random Postal Code (including optional +4 component)
86 | Integer Generator | Returns an int within a range
87 | Enum Generator | Define the enum and it will return the string value of a random one
88 | Boolean Generator | Returns a random boolean
89 | AmericanState | Returns a random US abbreviation
90 | EmailAddress | Returns a random email address | Thanks ScottMonnig!
91 | Business Name Generator | Returns a random 3 part business name
92 | URL Generator | Returns random URL based on BusinessName Generator
93 | IPAddress Generator | Returns a random ip address
94 | TextGenerator | Random Greek Text
95 | CountryCode | Random Country Code
96 | ByteArray Generator | Returns an array of random bytes
97 | GUID Generator | Returns a new GUID
98 | TypeGenerator | Return a hydrated object of Type
99 | TypeListGenerator | Return a list of objects
100 | PasswordGenerator | Returns a string of random pw characters with length parameter
101 | UnitedKingdomCityGenerator | Returns a UK City | Thanks to fuzzy-afterlife
102 | UnitedKingdomCountyGenerator | Returns a UK County | Thanks to fuzzy-afterlife
103 | UnitedKingdomPostcodeGenerator | Returns a UK Post Code | Thanks to fuzzy-afterlife
104 | UnitedKingdomPhoneNumberGenerator | Returns a UK Phone | Thanks to rikrak
105 | UnitedKingdomInsuranceNumberGenerator | Returns a UK Ins Number | Thanks to rikrak
106 | AlphaNumericGenerator | Returns an string with alpha chars of n length | Thanks to fuzzy-afterlife
107 | CulturesGenerator | Returns a Culture Info property | Thanks to ushenkodmitry
108 |
109 | All values can be overridden so you can do things like fake search results etc...
110 |
--------------------------------------------------------------------------------
/SampleWebApplication/AddCustomer.aspx:
--------------------------------------------------------------------------------
1 | <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="AddCustomer.aspx.cs" Inherits="SampleWebApplication.AddCustomer" %>
2 |
3 | <%@ Register src="Menu.ascx" tagname="Menu" tagprefix="uc1" %>
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
32 |
33 |
34 |
--------------------------------------------------------------------------------
/SampleWebApplication/AddCustomer.aspx.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using Foundation.ObjectHydrator;
3 |
4 | namespace SampleWebApplication
5 | {
6 | public partial class AddCustomer : System.Web.UI.Page
7 | {
8 | protected void Page_Load(object sender, EventArgs e)
9 | {
10 | if (!IsPostBack)
11 | {
12 | Hydrator hydrator = new Hydrator();
13 | Customer startwithme = hydrator.GetSingle();
14 | txtFirstName.Text = startwithme.FirstName;
15 | txtLastName.Text = startwithme.LastName;
16 | txtStreetAddress.Text = startwithme.StreetAddress;
17 | txtCity.Text = startwithme.City;
18 | txtState.Text = startwithme.State;
19 | txtZip.Text = startwithme.Zip;
20 | }
21 | }
22 |
23 | protected void Button1_Click(object sender, EventArgs e)
24 | {
25 |
26 | //Normally I wouldn't put code like this here
27 | //But I'm just doing this for simplicity
28 | //Ryan
29 | Hydrator hydrator = new Hydrator()
30 | .With(x=>x.FirstName, txtFirstName.Text)
31 | .With(x => x.LastName, txtLastName.Text)
32 | .With(x=>x.StreetAddress,txtStreetAddress.Text)
33 | .With(x=>x.City,txtCity.Text)
34 | .With(x=>x.State,txtState.Text)
35 | .With(x=>x.Zip,txtZip.Text);
36 |
37 | Customer savethis = hydrator.GetSingle();
38 |
39 | CustomerRepository cr = new CustomerRepository();
40 | cr.SaveCustomer(savethis);
41 | Response.Redirect("/");
42 | }
43 | }
44 | }
45 |
--------------------------------------------------------------------------------
/SampleWebApplication/AddCustomer.aspx.designer.cs:
--------------------------------------------------------------------------------
1 | //------------------------------------------------------------------------------
2 | //
3 | // This code was generated by a tool.
4 | // Runtime Version:2.0.50727.4016
5 | //
6 | // Changes to this file may cause incorrect behavior and will be lost if
7 | // the code is regenerated.
8 | //
9 | //------------------------------------------------------------------------------
10 |
11 | namespace SampleWebApplication {
12 |
13 |
14 | public partial class AddCustomer {
15 |
16 | ///
17 | /// form1 control.
18 | ///
19 | ///
20 | /// Auto-generated field.
21 | /// To modify move field declaration from designer file to code-behind file.
22 | ///
23 | protected global::System.Web.UI.HtmlControls.HtmlForm form1;
24 |
25 | ///
26 | /// Menu1 control.
27 | ///
28 | ///
29 | /// Auto-generated field.
30 | /// To modify move field declaration from designer file to code-behind file.
31 | ///
32 | protected global::SampleWebApplication.Menu Menu1;
33 |
34 | ///
35 | /// txtFirstName control.
36 | ///
37 | ///
38 | /// Auto-generated field.
39 | /// To modify move field declaration from designer file to code-behind file.
40 | ///
41 | protected global::System.Web.UI.WebControls.TextBox txtFirstName;
42 |
43 | ///
44 | /// txtLastName control.
45 | ///
46 | ///
47 | /// Auto-generated field.
48 | /// To modify move field declaration from designer file to code-behind file.
49 | ///
50 | protected global::System.Web.UI.WebControls.TextBox txtLastName;
51 |
52 | ///
53 | /// txtStreetAddress control.
54 | ///
55 | ///
56 | /// Auto-generated field.
57 | /// To modify move field declaration from designer file to code-behind file.
58 | ///
59 | protected global::System.Web.UI.WebControls.TextBox txtStreetAddress;
60 |
61 | ///
62 | /// txtCity control.
63 | ///
64 | ///
65 | /// Auto-generated field.
66 | /// To modify move field declaration from designer file to code-behind file.
67 | ///
68 | protected global::System.Web.UI.WebControls.TextBox txtCity;
69 |
70 | ///
71 | /// txtState control.
72 | ///
73 | ///
74 | /// Auto-generated field.
75 | /// To modify move field declaration from designer file to code-behind file.
76 | ///
77 | protected global::System.Web.UI.WebControls.TextBox txtState;
78 |
79 | ///
80 | /// txtZip control.
81 | ///
82 | ///
83 | /// Auto-generated field.
84 | /// To modify move field declaration from designer file to code-behind file.
85 | ///
86 | protected global::System.Web.UI.WebControls.TextBox txtZip;
87 |
88 | ///
89 | /// Button1 control.
90 | ///
91 | ///
92 | /// Auto-generated field.
93 | /// To modify move field declaration from designer file to code-behind file.
94 | ///
95 | protected global::System.Web.UI.WebControls.Button Button1;
96 | }
97 | }
98 |
--------------------------------------------------------------------------------
/SampleWebApplication/Company.cs:
--------------------------------------------------------------------------------
1 | namespace SampleWebApplication
2 | {
3 | public class Company
4 | {
5 | private int _companyID;
6 | public int CompanyID
7 | {
8 | get { return _companyID; }
9 | set
10 | {
11 | _companyID = value;
12 | }
13 | }
14 |
15 | private string _companyName;
16 | public string CompanyName
17 | {
18 | get { return _companyName; }
19 | set
20 | {
21 | _companyName = value;
22 | }
23 | }
24 |
25 | private string _addressLine;
26 | public string AddressLine
27 | {
28 | get { return _addressLine; }
29 | set
30 | {
31 | _addressLine = value;
32 | }
33 | }
34 |
35 | private string _city;
36 | public string City
37 | {
38 | get { return _city; }
39 | set
40 | {
41 | _city = value;
42 | }
43 | }
44 |
45 | private string _state;
46 | public string State
47 | {
48 | get { return _state; }
49 | set
50 | {
51 | _state = value;
52 | }
53 | }
54 |
55 | private string _zip;
56 | public string Zip
57 | {
58 | get { return _zip; }
59 | set
60 | {
61 | _zip = value;
62 | }
63 | }
64 |
65 | private string _homepage;
66 | public string Homepage
67 | {
68 | get { return _homepage; }
69 | set
70 | {
71 | _homepage = value;
72 | }
73 | }
74 |
75 | public override string ToString()
76 | {
77 | return CompanyName;
78 | }
79 |
80 | }
81 | }
82 |
--------------------------------------------------------------------------------
/SampleWebApplication/Customer.cs:
--------------------------------------------------------------------------------
1 | using System.Collections.Generic;
2 |
3 | namespace SampleWebApplication
4 | {
5 | public class Customer
6 | {
7 | private string _firstName;
8 | public string FirstName
9 | {
10 | get { return _firstName; }
11 | set
12 | {
13 | _firstName = value;
14 | }
15 | }
16 |
17 | private string _lastName;
18 | public string LastName
19 | {
20 | get { return _lastName; }
21 | set
22 | {
23 | _lastName = value;
24 | }
25 | }
26 |
27 | private string _streetAddress;
28 | public string StreetAddress
29 | {
30 | get { return _streetAddress; }
31 | set
32 | {
33 | _streetAddress = value;
34 | }
35 | }
36 |
37 | private string _city;
38 | public string City
39 | {
40 | get { return _city; }
41 | set
42 | {
43 | _city = value;
44 | }
45 | }
46 |
47 | private string _state;
48 | public string State
49 | {
50 | get { return _state; }
51 | set
52 | {
53 | _state = value;
54 | }
55 | }
56 |
57 | private string _zip;
58 | public string Zip
59 | {
60 | get { return _zip; }
61 | set
62 | {
63 | _zip = value;
64 | }
65 | }
66 |
67 | private Company _company;
68 | public Company Company { get; set; }
69 |
70 | private IList _companies;
71 | public IList Companies {get;set;}
72 |
73 |
74 |
75 | }
76 | }
77 |
--------------------------------------------------------------------------------
/SampleWebApplication/CustomerFakeLookup.aspx:
--------------------------------------------------------------------------------
1 | <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="CustomerFakeLookup.aspx.cs" Inherits="SampleWebApplication.CustomerFakeLookup" %>
2 |
3 | <%@ Register src="Menu.ascx" tagname="Menu" tagprefix="uc1" %>
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
27 |
28 |
29 |
--------------------------------------------------------------------------------
/SampleWebApplication/CustomerFakeLookup.aspx.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using Foundation.ObjectHydrator.Generators;
4 |
5 |
6 | namespace SampleWebApplication
7 | {
8 | public partial class CustomerFakeLookup : System.Web.UI.Page
9 | {
10 | protected void Page_Load(object sender, EventArgs e)
11 | {
12 |
13 | }
14 |
15 | protected void Button1_Click(object sender, EventArgs e)
16 | {
17 | Foundation.ObjectHydrator.Hydrator hydrator = new Foundation.ObjectHydrator.Hydrator()
18 | .With(x => x.Company, new FromListGetSingleGenerator((IList)Application["companies"]))
19 | .With(x => x.LastName, txtLastName.Text);
20 | GridView1.DataSource = hydrator.GetList(30);
21 | GridView1.DataBind();
22 | }
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/SampleWebApplication/CustomerFakeLookup.aspx.designer.cs:
--------------------------------------------------------------------------------
1 | //------------------------------------------------------------------------------
2 | //
3 | // This code was generated by a tool.
4 | // Runtime Version:2.0.50727.4016
5 | //
6 | // Changes to this file may cause incorrect behavior and will be lost if
7 | // the code is regenerated.
8 | //
9 | //------------------------------------------------------------------------------
10 |
11 | namespace SampleWebApplication {
12 |
13 |
14 | public partial class CustomerFakeLookup {
15 |
16 | ///
17 | /// form1 control.
18 | ///
19 | ///
20 | /// Auto-generated field.
21 | /// To modify move field declaration from designer file to code-behind file.
22 | ///
23 | protected global::System.Web.UI.HtmlControls.HtmlForm form1;
24 |
25 | ///
26 | /// Menu1 control.
27 | ///
28 | ///
29 | /// Auto-generated field.
30 | /// To modify move field declaration from designer file to code-behind file.
31 | ///
32 | protected global::SampleWebApplication.Menu Menu1;
33 |
34 | ///
35 | /// txtLastName control.
36 | ///
37 | ///
38 | /// Auto-generated field.
39 | /// To modify move field declaration from designer file to code-behind file.
40 | ///
41 | protected global::System.Web.UI.WebControls.TextBox txtLastName;
42 |
43 | ///
44 | /// Button1 control.
45 | ///
46 | ///
47 | /// Auto-generated field.
48 | /// To modify move field declaration from designer file to code-behind file.
49 | ///
50 | protected global::System.Web.UI.WebControls.Button Button1;
51 |
52 | ///
53 | /// GridView1 control.
54 | ///
55 | ///
56 | /// Auto-generated field.
57 | /// To modify move field declaration from designer file to code-behind file.
58 | ///
59 | protected global::System.Web.UI.WebControls.GridView GridView1;
60 | }
61 | }
62 |
--------------------------------------------------------------------------------
/SampleWebApplication/CustomerRealLookUp.aspx:
--------------------------------------------------------------------------------
1 | <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="CustomerRealLookUp.aspx.cs" Inherits="SampleWebApplication.CustomerRealLookUp" %>
2 |
3 | <%@ Register src="Menu.ascx" tagname="Menu" tagprefix="uc1" %>
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
25 |
26 |
27 |
--------------------------------------------------------------------------------
/SampleWebApplication/CustomerRealLookUp.aspx.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace SampleWebApplication
4 | {
5 | public partial class CustomerRealLookUp : System.Web.UI.Page
6 | {
7 | protected void Page_Load(object sender, EventArgs e)
8 | {
9 |
10 | }
11 |
12 | protected void Search_Click(object sender, EventArgs e)
13 | {
14 | CustomerRepository custrepos = new CustomerRepository();
15 | GridView1.DataSource = custrepos.RealSearchByLastName(txtLastName.Text);
16 | GridView1.DataBind();
17 | }
18 | }
19 | }
20 |
--------------------------------------------------------------------------------
/SampleWebApplication/CustomerRealLookUp.aspx.designer.cs:
--------------------------------------------------------------------------------
1 | //------------------------------------------------------------------------------
2 | //
3 | // This code was generated by a tool.
4 | // Runtime Version:2.0.50727.4016
5 | //
6 | // Changes to this file may cause incorrect behavior and will be lost if
7 | // the code is regenerated.
8 | //
9 | //------------------------------------------------------------------------------
10 |
11 | namespace SampleWebApplication {
12 |
13 |
14 | public partial class CustomerRealLookUp {
15 |
16 | ///
17 | /// form1 control.
18 | ///
19 | ///
20 | /// Auto-generated field.
21 | /// To modify move field declaration from designer file to code-behind file.
22 | ///
23 | protected global::System.Web.UI.HtmlControls.HtmlForm form1;
24 |
25 | ///
26 | /// Menu1 control.
27 | ///
28 | ///
29 | /// Auto-generated field.
30 | /// To modify move field declaration from designer file to code-behind file.
31 | ///
32 | protected global::SampleWebApplication.Menu Menu1;
33 |
34 | ///
35 | /// txtLastName control.
36 | ///
37 | ///
38 | /// Auto-generated field.
39 | /// To modify move field declaration from designer file to code-behind file.
40 | ///
41 | protected global::System.Web.UI.WebControls.TextBox txtLastName;
42 |
43 | ///
44 | /// Search control.
45 | ///
46 | ///
47 | /// Auto-generated field.
48 | /// To modify move field declaration from designer file to code-behind file.
49 | ///
50 | protected global::System.Web.UI.WebControls.Button Search;
51 |
52 | ///
53 | /// GridView1 control.
54 | ///
55 | ///
56 | /// Auto-generated field.
57 | /// To modify move field declaration from designer file to code-behind file.
58 | ///
59 | protected global::System.Web.UI.WebControls.GridView GridView1;
60 | }
61 | }
62 |
--------------------------------------------------------------------------------
/SampleWebApplication/CustomerRepository.cs:
--------------------------------------------------------------------------------
1 | using System.Collections.Generic;
2 | using System.Linq;
3 | using System.Web;
4 |
5 | namespace SampleWebApplication
6 | {
7 | public class CustomerRepository
8 | {
9 | public IEnumerable GetAllCustomers()
10 | {
11 | IList customers = (IList)HttpContext.Current.Application["customers"];
12 | var custlist = from p in customers orderby p.LastName select p;
13 | return custlist;
14 | }
15 |
16 | public IEnumerable RealSearchByLastName(string searchbylastname)
17 | {
18 | IList customers = (IList)HttpContext.Current.Application["customers"];
19 | var custlist = from p in customers where p.LastName.ToLower().Contains(searchbylastname.ToLower()) orderby p.FirstName select p;
20 | return custlist;
21 | }
22 |
23 | public void SaveCustomer(Customer saveme)
24 | {
25 | IList customers = (IList)HttpContext.Current.Application["customers"];
26 | customers.Add(saveme);
27 | HttpContext.Current.Application.Lock();
28 | HttpContext.Current.Application["customers"] = customers;
29 | HttpContext.Current.Application.UnLock();
30 | }
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/SampleWebApplication/Default.aspx:
--------------------------------------------------------------------------------
1 | <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="SampleWebApplication._Default" %>
2 |
3 | <%@ Register src="Menu.ascx" tagname="Menu" tagprefix="uc1" %>
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
40 |
41 |
42 |
--------------------------------------------------------------------------------
/SampleWebApplication/Default.aspx.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace SampleWebApplication
4 | {
5 | public partial class _Default : System.Web.UI.Page
6 | {
7 | protected void Page_Load(object sender, EventArgs e)
8 | {
9 |
10 | }
11 | }
12 | }
13 |
--------------------------------------------------------------------------------
/SampleWebApplication/Default.aspx.designer.cs:
--------------------------------------------------------------------------------
1 | //------------------------------------------------------------------------------
2 | //
3 | // This code was generated by a tool.
4 | // Runtime Version:2.0.50727.4016
5 | //
6 | // Changes to this file may cause incorrect behavior and will be lost if
7 | // the code is regenerated.
8 | //
9 | //------------------------------------------------------------------------------
10 |
11 | namespace SampleWebApplication {
12 |
13 |
14 | public partial class _Default {
15 |
16 | ///
17 | /// form1 control.
18 | ///
19 | ///
20 | /// Auto-generated field.
21 | /// To modify move field declaration from designer file to code-behind file.
22 | ///
23 | protected global::System.Web.UI.HtmlControls.HtmlForm form1;
24 |
25 | ///
26 | /// Menu1 control.
27 | ///
28 | ///
29 | /// Auto-generated field.
30 | /// To modify move field declaration from designer file to code-behind file.
31 | ///
32 | protected global::SampleWebApplication.Menu Menu1;
33 |
34 | ///
35 | /// ObjectDataSource1 control.
36 | ///
37 | ///
38 | /// Auto-generated field.
39 | /// To modify move field declaration from designer file to code-behind file.
40 | ///
41 | protected global::System.Web.UI.WebControls.ObjectDataSource ObjectDataSource1;
42 |
43 | ///
44 | /// GridView1 control.
45 | ///
46 | ///
47 | /// Auto-generated field.
48 | /// To modify move field declaration from designer file to code-behind file.
49 | ///
50 | protected global::System.Web.UI.WebControls.GridView GridView1;
51 | }
52 | }
53 |
--------------------------------------------------------------------------------
/SampleWebApplication/Global.asax:
--------------------------------------------------------------------------------
1 | <%@ Application Codebehind="Global.asax.cs" Inherits="SampleWebApplication.Global" Language="C#" %>
2 |
--------------------------------------------------------------------------------
/SampleWebApplication/Global.asax.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using Foundation.ObjectHydrator;
4 |
5 | using Foundation.ObjectHydrator.Generators;
6 |
7 | namespace SampleWebApplication
8 | {
9 | public class Global : System.Web.HttpApplication
10 | {
11 |
12 | protected void Application_Start(object sender, EventArgs e)
13 | {
14 | //Create a list of companies and tuck them away for later use
15 | Hydrator hydrator2=new Hydrator();
16 | IList comps = hydrator2.GetList(10);
17 | Application["companies"] = comps;
18 |
19 | //Create our customer database using one of the companies created above as the Company property of the customer.
20 | //Whoa.
21 | int listSize = 4;
22 | var args = new object[] { listSize };
23 | //Hydrator hydrator = new Hydrator()
24 |
25 | // .FromList("Company", System.Linq.Enumerable.Cast