RouteParametersHelper.cs source code in C# .NET

Source code for the .NET framework in C#

                        

Code:

/ 4.0 / 4.0 / DEVDIV_TFS / Dev10 / Releases / RTMRel / ndp / fx / src / xsp / System / DynamicData / DynamicData / Util / RouteParametersHelper.cs / 1305376 / RouteParametersHelper.cs

                            using System.Collections.Generic; 
using System.Diagnostics;
using System.Web.UI.WebControls;

namespace System.Web.DynamicData.Util { 
    internal class RouteParametersHelper {
        private static Parameter CreateParameter(string name, string value, MetaColumn configurationColumn) { 
            var param = new Parameter() { 
                Name = name,
                DefaultValue = value 
            };
            DataSourceUtil.SetParameterTypeCodeAndDbType(param, configurationColumn);
            return param;
        } 

        internal static IEnumerable GetColumnParameters(MetaTable table, string columnName) { 
            if (String.IsNullOrEmpty(columnName)) { 
                // If no column is specified, we're setting the primary key from the query string
                return GetPrimaryKeyParameters(table); 
            } else {
                var column = table.GetColumn(columnName);
                var fkColumn = column as MetaForeignKeyColumn;
                if (fkColumn != null) { 
                    // Handle the case where we're setting one of our foreign keys from the query string
                    return GetForeignKeyParameters(fkColumn); 
                } else { 
                    // Handle other columns (e.g. booleans)
                    return GetRegularColumnParameters(column); 
                }
            }
        }
 
        internal static IEnumerable GetForeignKeyParameters(MetaForeignKeyColumn fkColumn) {
            Debug.Assert(fkColumn.ForeignKeyNames.Count == fkColumn.ParentTable.PrimaryKeyColumns.Count); 
            var result = new List(); 
            for (int i = 0; i < fkColumn.ForeignKeyNames.Count; i++) {
                string name = fkColumn.ForeignKeyNames[i]; 
                string value = Misc.GetRouteValue(name);

                MetaColumn parentTablePKColumn = fkColumn.ParentTable.PrimaryKeyColumns[i];
 
                var param = CreateParameter(name, value, parentTablePKColumn);
 
                result.Add(param); 
            }
            return result; 
        }

        internal static IEnumerable GetPrimaryKeyParameters(MetaTable table) {
            var result = new List(); 
            foreach (var primaryKeyColumn in table.PrimaryKeyColumns) {
                string name = primaryKeyColumn.Name; 
                string value = Misc.GetRouteValue(name); 

                var param = CreateParameter(name, value, primaryKeyColumn); 
                result.Add(param);
            }
            return result;
        } 

        internal static IEnumerable GetRegularColumnParameters(MetaColumn column) { 
            // Handle other columns (e.g. booleans) 
            string name = column.Name;
            string value = Misc.GetRouteValue(name); 

            var param = CreateParameter(name, value, column);

            return new List() { param }; 
        }
    } 
} 

// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
// Copyright (c) Microsoft Corporation. All rights reserved.
´╗┐using System.Collections.Generic; 
using System.Diagnostics;
using System.Web.UI.WebControls;

namespace System.Web.DynamicData.Util { 
    internal class RouteParametersHelper {
        private static Parameter CreateParameter(string name, string value, MetaColumn configurationColumn) { 
            var param = new Parameter() { 
                Name = name,
                DefaultValue = value 
            };
            DataSourceUtil.SetParameterTypeCodeAndDbType(param, configurationColumn);
            return param;
        } 

        internal static IEnumerable GetColumnParameters(MetaTable table, string columnName) { 
            if (String.IsNullOrEmpty(columnName)) { 
                // If no column is specified, we're setting the primary key from the query string
                return GetPrimaryKeyParameters(table); 
            } else {
                var column = table.GetColumn(columnName);
                var fkColumn = column as MetaForeignKeyColumn;
                if (fkColumn != null) { 
                    // Handle the case where we're setting one of our foreign keys from the query string
                    return GetForeignKeyParameters(fkColumn); 
                } else { 
                    // Handle other columns (e.g. booleans)
                    return GetRegularColumnParameters(column); 
                }
            }
        }
 
        internal static IEnumerable GetForeignKeyParameters(MetaForeignKeyColumn fkColumn) {
            Debug.Assert(fkColumn.ForeignKeyNames.Count == fkColumn.ParentTable.PrimaryKeyColumns.Count); 
            var result = new List(); 
            for (int i = 0; i < fkColumn.ForeignKeyNames.Count; i++) {
                string name = fkColumn.ForeignKeyNames[i]; 
                string value = Misc.GetRouteValue(name);

                MetaColumn parentTablePKColumn = fkColumn.ParentTable.PrimaryKeyColumns[i];
 
                var param = CreateParameter(name, value, parentTablePKColumn);
 
                result.Add(param); 
            }
            return result; 
        }

        internal static IEnumerable GetPrimaryKeyParameters(MetaTable table) {
            var result = new List(); 
            foreach (var primaryKeyColumn in table.PrimaryKeyColumns) {
                string name = primaryKeyColumn.Name; 
                string value = Misc.GetRouteValue(name); 

                var param = CreateParameter(name, value, primaryKeyColumn); 
                result.Add(param);
            }
            return result;
        } 

        internal static IEnumerable GetRegularColumnParameters(MetaColumn column) { 
            // Handle other columns (e.g. booleans) 
            string name = column.Name;
            string value = Misc.GetRouteValue(name); 

            var param = CreateParameter(name, value, column);

            return new List() { param }; 
        }
    } 
} 

// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
// Copyright (c) Microsoft Corporation. All rights reserved.

                        

Link Menu

Network programming in C#, Network Programming in VB.NET, Network Programming in .NET
This book is available now!
Buy at Amazon US or
Buy at Amazon UK