public bool TryGetParam <T>(string key, out T value)
        {
            // try to find a parameter with matching name across the cookies, query parameters, request headers and extended properties
            if (QueryParams.TryGetValue(key, out var queryParamValue))
            {
                value = (T)queryParamValue;
                return(true);
            }

            if (RequestHeaders.TryGetValue(key, out var headerValue))
            {
                value = (T)headerValue;
                return(true);
            }

            if (Cookies.TryGetValue(key, out var cookieValue))
            {
                value = (T)cookieValue;
                return(true);
            }

            if (ExtendedProperties.TryGetValue(key, out var extendedValue))
            {
                value = (T)extendedValue;
                return(true);
            }

            // the parameter doesn't exist so return null/false
            value = default(T);
            return(false);
        }
        /// <summary>
        /// Returns the GenericProperty for this association.  This must be implemented by the inheriting class.
        /// </summary>
        /// <returns></returns>
        protected virtual string GetGenericProperty()
        {
            string genericProperty = String.Empty;

            object value;

            if (ExtendedProperties.TryGetValue(Configuration.Instance.GenericPropertyExtendedProperty, out value) && ((bool)value))
            {
                genericProperty = "<T>";
            }

            return(genericProperty);
        }
Exemplo n.º 3
0
        protected override string LoadDefaultValue()
        {
            object value;

            if (!ExtendedProperties.TryGetValue("CS_Default", out value) || String.IsNullOrEmpty(value.ToString()))
            {
                return(null);
            }

            string defaultValue = value.ToString();

            if (String.Equals(BaseSystemType, "System.Boolean", StringComparison.OrdinalIgnoreCase))
            {
                defaultValue = defaultValue.Contains("0") || defaultValue.ToLowerInvariant().Contains("false") ? Boolean.FalseString : Boolean.TrueString;
            }
            else if (String.Equals(BaseSystemType, "System.Single", StringComparison.OrdinalIgnoreCase) || String.Equals(BaseSystemType, "System.Int16", StringComparison.OrdinalIgnoreCase) || String.Equals(BaseSystemType, "System.Int32", StringComparison.OrdinalIgnoreCase) || String.Equals(BaseSystemType, "System.Int64", StringComparison.OrdinalIgnoreCase) || String.Equals(BaseSystemType, "System.Byte", StringComparison.OrdinalIgnoreCase) || String.Equals(BaseSystemType, "System.Decimal", StringComparison.OrdinalIgnoreCase) || String.Equals(BaseSystemType, "System.Double", StringComparison.OrdinalIgnoreCase))
            {
                defaultValue = defaultValue.Replace("(", "").Replace(")", "");
            }
            else if (defaultValue.ToLowerInvariant().Contains("null"))
            {
                defaultValue = null;
                //} else if (defaultValue.ToLowerInvariant().Contains("autoincrement")) { // Required for ef, need to look into special case it in the ef templates.
                //    defaultValue = null;
            }
            else if (defaultValue.ToLowerInvariant().Contains("newid"))
            {
                defaultValue = "newid()";
            }
            else if (defaultValue.ToLowerInvariant().Contains("getdate"))
            {
                defaultValue = "getdate()";
            }
            else if (!String.Equals(BaseSystemType, "System.String", StringComparison.OrdinalIgnoreCase) && defaultValue.StartsWith("\"") && defaultValue.EndsWith("\"") && defaultValue.Length > 2)
            {
                defaultValue = defaultValue.Substring(1, defaultValue.Length - 2);
            }

            return(defaultValue);
        }