GetValue() public method

public GetValue ( object onInstance ) : object
onInstance object
return object
        internal static void SetListChildResults <Parent>(List <Parent> parents, ModelDefinition modelDef,
                                                          FieldDefinition fieldDef, Type refType, IList childResults, FieldDefinition refField)
        {
            var           map = new Dictionary <object, List <object> >();
            List <object> refValues;

            foreach (var result in childResults)
            {
                var refValue = refField.GetValue(result);
                if (!map.TryGetValue(refValue, out refValues))
                {
                    map[refValue] = refValues = new List <object>();
                }
                refValues.Add(result);
            }

            var untypedApi = refType.CreateTypedApi();

            foreach (var result in parents)
            {
                var pkValue = modelDef.PrimaryKey.GetValue(result);
                if (map.TryGetValue(pkValue, out refValues))
                {
                    var castResults = untypedApi.Cast(refValues);
                    fieldDef.SetValueFn(result, castResults);
                }
            }
        }
        internal static void SetRefSelfChildResults <Parent>(List <Parent> parents, FieldDefinition fieldDef, ModelDefinition refModelDef, FieldDefinition refSelf, IList childResults)
        {
            var map = new Dictionary <object, object>();

            foreach (var result in childResults)
            {
                var pkValue = refModelDef.PrimaryKey.GetValue(result);
                map[pkValue] = result;
            }

            foreach (var result in parents)
            {
                var fkValue = refSelf.GetValue(result);
                if (fkValue != null && map.TryGetValue(fkValue, out var childResult))
                {
                    fieldDef.SetValueFn(result, childResult);
                }
            }
        }
Example #3
0
        protected object GetQuotedValueOrDbNull(FieldDefinition fieldDef, object objWithProperties)
        {
            var value = fieldDef.GetValue(objWithProperties);

            if (value == null)
            {
                return(DBNull.Value);
            }

            var unquotedVal = OrmLiteConfig.DialectProvider.GetQuotedValue(value, fieldDef.FieldType)
                              .TrimStart('\'').TrimEnd('\'');;

            if (string.IsNullOrEmpty(unquotedVal))
            {
                return(DBNull.Value);
            }

            return(unquotedVal);
        }
        internal static void SetRefFieldChildResults <Parent>(List <Parent> parents, ModelDefinition modelDef,
                                                              FieldDefinition fieldDef, FieldDefinition refField, IList childResults)
        {
            var map = new Dictionary <object, object>();

            foreach (var result in childResults)
            {
                var refValue = refField.GetValue(result);
                map[refValue] = result;
            }

            foreach (var result in parents)
            {
                var pkValue = modelDef.PrimaryKey.GetValue(result);
                if (map.TryGetValue(pkValue, out var childResult))
                {
                    fieldDef.SetValueFn(result, childResult);
                }
            }
        }
        protected virtual object GetQuotedValueOrDbNull <T>(FieldDefinition fieldDef, object obj)
        {
            var value = obj is T
                ? fieldDef.GetValue(obj)
                : GetAnonValue <T>(fieldDef, obj);

            if (value == null)
            {
                return(DBNull.Value);
            }

            var unquotedVal = OrmLiteConfig.DialectProvider.GetQuotedValue(value, fieldDef.FieldType)
                              .TrimStart('\'').TrimEnd('\'');;

            if (string.IsNullOrEmpty(unquotedVal))
            {
                return(DBNull.Value);
            }

            return(unquotedVal);
        }
 protected object GetValue <T>(FieldDefinition fieldDef, object obj)
 {
     return(obj is T
        ? fieldDef.GetValue(obj)
        : GetAnonValue <T>(fieldDef, obj));
 }
Example #7
0
 protected object GetValueOrDbNull(FieldDefinition fieldDef, object objWithProperties)
 {
     return(fieldDef.GetValue(objWithProperties) ?? DBNull.Value);
 }