/*--------------------------------------------------------------------------------------------*/ private static void ConfirmVciState <TEdge, TVert> (TEdge pEdge, Expression <Func <TVert, object> > pProperty) where TEdge : IWeaverEdge where TVert : IWeaverVertex { Type et = typeof(TEdge); Type vt = typeof(TVert); WeaverTitanUtil.GetAndVerifyElementAttribute <WeaverTitanEdgeAttribute> (et); WeaverTitanUtil.GetAndVerifyElementAttribute <WeaverTitanVertexAttribute> (vt); if (pEdge.OutVertexType != vt && pEdge.InVertexType != vt) { throw new WeaverException("Vertex type '" + vt.Name + "' is not valid for edge type '" + et.Name + "'."); } WeaverPropPair wpp = WeaverUtil.GetPropertyAttribute(pProperty); WeaverTitanPropertyAttribute att = WeaverTitanUtil.GetAndVerifyTitanPropertyAttribute(wpp); if (!att.HasTitanVertexCentricIndex(et)) { throw new WeaverException("Property '" + vt.Name + "." + wpp.Info.Name + "' does not have a " + "vertex-centric index for edge '" + et.Name + "'."); } }
/*--------------------------------------------------------------------------------------------*/ private void BuildProp(WeaverPropPair pProp) { string dbName = pProp.Attrib.DbName; if (vPropDbMap.ContainsKey(dbName)) { WeaverPropPair wpp = vPropDbMap[dbName]; //Duplicate DbNames are ignored if they come from the same declaring type. This occurs //for WeaverElement.Id, for example, or a common Vertex base class. Type t = wpp.Info.DeclaringType; Type expectT = pProp.Info.DeclaringType; if (t == expectT) { return; } //Sometimes, a property can be shared by a generic base class. For example: base class //EdgeBase<Person, Knows, T> contains a "MyNumber" property. The condition below will //prevent exceptions when multiple subclasses (like CandyEdge : EdgeBase<Candy>) //all try to register the same shared "MyNumber" property. if (t.Namespace == expectT.Namespace && t.Name == expectT.Name) { return; } throw new WeaverException("Duplicate property DbName found: '" + dbName + "'."); } vPropDbMap.Add(dbName, pProp); }
/*--------------------------------------------------------------------------------------------*/ private IWeaverPathPipeEnd MakePropertyKey <T>(string pElement, Expression <Func <T, object> > pProp, IWeaverVarAlias pGroupVar = null) where T : IWeaverElement { WeaverPropPair wpp = WeaverUtil.GetPropertyAttribute(pProp); WeaverTitanPropertyAttribute att = WeaverTitanUtil.GetAndVerifyTitanPropertyAttribute(wpp); Type pt = wpp.Info.PropertyType; AddCustom("makeType()"); AddCustom("dataType(" + WeaverTitanPropertyAttribute.GetTitanTypeName(pt) + ".class)"); AddCustom("name(" + Path.Query.AddParam(new WeaverQueryVal(att.DbName)) + ")"); AddCustom("unique(OUT)"); //WeaverConfig enforces unique property DbNames if (pGroupVar != null) { AddCustom("group(" + pGroupVar.Name + ")"); } if (att.TitanIndex) { AddCustom("indexed(" + pElement + ".class)"); } if (att.TitanElasticIndex) { AddCustom("indexed('search'," + pElement + ".class)"); } return(AddCustom("makePropertyKey()")); }
public void GetPropertyAttribute() { WeaverPropPair result = WeaverUtil.GetPropertyAttribute <Person>(x => x.Age); Assert.NotNull(result, "Result should be filled."); Assert.AreEqual("Age", result.Info.Name, "Incorrect result PropertyInfo.Name."); }
/*--------------------------------------------------------------------------------------------*/ public static WeaverTitanPropertyAttribute GetAndVerifyTitanPropertyAttribute( WeaverPropPair pPair, bool pIgnoreNonTitan = false) { WeaverTitanPropertyAttribute a = (pPair.Attrib as WeaverTitanPropertyAttribute); if (!pIgnoreNonTitan && a == null) { throw new WeaverException("Property '" + pPair.Info.Name + "' must have a " + typeof(WeaverTitanPropertyAttribute).Name + "."); } return(a); }