Dashing.Configuration.Map.GetPrimaryKeyValue C# (CSharp) Method

GetPrimaryKeyValue() public method

public GetPrimaryKeyValue ( object entity ) : object
entity object
return object
        public object GetPrimaryKeyValue(object entity) {
            if (this.nonGenericPrimaryKeyGetter == null) {
                lock (this.nonGenericPrimaryKeyGetterLock) {
                    if (this.nonGenericPrimaryKeyGetter == null) {
                        this.nonGenericPrimaryKeyGetter =
                            typeof(Map<>).MakeGenericType(this.Type)
                                         .GetMethods()
                                         .First(m => m.Name == "GetPrimaryKeyValue" && m.GetParameters().Any(p => p.ParameterType == this.Type));
                    }
                }
            }

            return this.nonGenericPrimaryKeyGetter.Invoke(this, new[] { entity });
        }
    }

Usage Example

Example #1
0
 public void NonGenericPrimaryKeyGetterWorks() {
     var map = new Map<Post>();
     map.Columns.Add("PostId", new Column<int> { IsPrimaryKey = true, Map = map, Name = "PostId" });
     map.PrimaryKey = map.Columns["PostId"];
     var post = new Post { PostId = 123 };
     Assert.Equal(post.PostId, map.GetPrimaryKeyValue((object)post));
 }
All Usage Examples Of Dashing.Configuration.Map::GetPrimaryKeyValue