本文整理汇总了C#中MemberPath类的典型用法代码示例。如果您正苦于以下问题:C# MemberPath类的具体用法?C# MemberPath怎么用?C# MemberPath使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
MemberPath类属于命名空间,在下文中一共展示了MemberPath类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CanBeModified
/// <summary>
/// Indicate if the referred member can be modified or not due to sealing.
/// </summary>
/// <param name="asset">The asset to modify</param>
/// <param name="path">The path to the member to modify</param>
/// <returns><value>true</value> if it can be modified</returns>
public bool CanBeModified(Asset asset, MemberPath path)
{
if (path.GetNodeOverrides(asset).Any(x => x.IsNew()))
return true;
var assetBase = asset.Base;
while (assetBase != null && assetBase.Asset != null)
{
var parent = assetBase.Asset;
var parentPath = path.Resolve(asset, parent).FirstOrDefault(); // if several paths exist in parent, they should be all equal (same object instance)
if (parentPath == null)
break;
var parentOverrides = parentPath.GetNodeOverrides(parent).ToList();
if (parentOverrides.LastOrDefault().IsSealed())
return false;
if (parentOverrides.Any(x => x.IsNew()))
break;
assetBase = parent.Base;
}
return true;
}
示例2: TestCanBeModifiedOrphan
public void TestCanBeModifiedOrphan()
{
// -------------------------------------------
// Check that CanBeModified is always true
// whatever are the values of the overrides
//
// For that set all the possible values of the overrides
// at two first level of fields and check the reset
//
// Field checked is orphan.MyClass.Value
//
// --------------------------------------------
Initialize();
var orphan = new TestAssetUpdate { MyClass = new MyClass() };
var testValues = new[] { OverrideType.Base, OverrideType.Sealed, OverrideType.New, OverrideType.Sealed | OverrideType.New };
var pathToValue = new MemberPath();
pathToValue.Push(memberMyClass);
pathToValue.Push(MemberValue);
foreach (var value1 in testValues)
{
orphan.SetOverride(memberMyClass, value1);
foreach (var value2 in testValues)
{
orphan.MyClass.SetOverride(MemberValue, value2);
Assert.IsTrue(assetUpdater.CanBeModified(orphan, pathToValue));
}
}
}
示例3: RefLoopAndMemberErrors
public void RefLoopAndMemberErrors()
{
var rootType = typeof(ErrorTypes.With<ErrorTypes.Parent>);
var valueProperty = rootType.GetProperty(nameof(ErrorTypes.With<ErrorTypes.Parent>.Value));
var parentType = typeof(ErrorTypes.Parent);
var childProperty = parentType.GetProperty(nameof(ErrorTypes.Parent.Child));
var parentProperty = typeof(ErrorTypes.Child).GetProperty(nameof(ErrorTypes.Child.Parent));
var path = new MemberPath(rootType)
.WithProperty(valueProperty);
var loopPath = path.WithProperty(childProperty)
.WithProperty(parentProperty)
.WithProperty(childProperty);
var referenceLoop = new ReferenceLoop(loopPath);
var refLoopErrors = ErrorBuilder.Start()
.CreateIfNull(rootType)
.Add(referenceLoop)
.Finnish();
var typeMustNotifyError = TypeMustNotifyError.GetOrCreate(parentType);
var typeErrors = new TypeErrors( parentType, typeMustNotifyError);
var memberErrors = new MemberErrors(path, typeErrors);
var notifyErrors = ErrorBuilder.Start()
.CreateIfNull(rootType)
.Add(memberErrors)
.Finnish();
var merged = ErrorBuilder.Merge(refLoopErrors, notifyErrors);
Assert.AreEqual(2, merged.Errors.Count);
Assert.AreEqual(8, merged.AllErrors.Count);
}
示例4: QueryRewriter
internal QueryRewriter(EdmType generatedType, ViewgenContext context, ViewGenMode typesGenerationMode)
{
Debug.Assert(typesGenerationMode != ViewGenMode.GenerateAllViews);
_typesGenerationMode = typesGenerationMode;
_context = context;
_generatedType = generatedType;
_domainMap = context.MemberMaps.LeftDomainMap;
_config = context.Config;
_identifiers = context.CqlIdentifiers;
_qp = new RewritingProcessor<Tile<FragmentQuery>>(new DefaultTileProcessor<FragmentQuery>(context.LeftFragmentQP));
_extentPath = new MemberPath(context.Extent);
_keyAttributes = new List<MemberPath>(MemberPath.GetKeyMembers(context.Extent, _domainMap));
// populate _fragmentQueries and _views
foreach (var leftCellWrapper in _context.AllWrappersForExtent)
{
var query = leftCellWrapper.FragmentQuery;
Tile<FragmentQuery> tile = CreateTile(query);
_fragmentQueries.Add(query);
_views.Add(tile);
}
Debug.Assert(_views.Count > 0);
AdjustMemberDomainsForUpdateViews();
// must be done after adjusting domains
_domainQuery = GetDomainQuery(FragmentQueries, generatedType);
_usedViews = new HashSet<FragmentQuery>();
}
示例5: WhenError
public void WhenError()
{
var rootType = typeof(ErrorTypes.With<ErrorTypes.Parent>);
var valueProperty = rootType.GetProperty(nameof(ErrorTypes.With<ErrorTypes.Parent>.Value));
var childProperty = typeof(ErrorTypes.Parent).GetProperty(nameof(ErrorTypes.Parent.Child));
var parentProperty = typeof(ErrorTypes.Child).GetProperty(nameof(ErrorTypes.Child.Parent));
var path = new MemberPath(rootType)
.WithProperty(valueProperty)
.WithProperty(childProperty)
.WithProperty(parentProperty)
.WithProperty(childProperty);
var referenceLoop = new ReferenceLoop(path);
var typeErrors = ErrorBuilder.Start()
.CreateIfNull(rootType)
.Add(referenceLoop)
.Finnish();
var errorBuilder = new StringBuilder();
errorBuilder.AppendNotSupported(typeErrors);
var expected = "The property Parent.Child of type Child is in a reference loop.\r\n" +
" - The loop is With<Parent>.Value.Child.Parent.Child...\r\n" +
"The property With<Parent>.Value of type Parent is not supported.\r\n" +
"The property Parent.Child of type Child is not supported.\r\n" +
"The property Child.Parent of type Parent is not supported.\r\n";
var actual = errorBuilder.ToString();
Assert.AreEqual(expected, actual);
Assert.AreEqual(1, typeErrors.Errors.Count);
Assert.AreEqual(7, typeErrors.AllErrors.Count);
}
示例6: ConstantProjectedSlot
/// <summary>
/// Creates a slot with constant value being <paramref name="value"/>.
/// </summary>
internal ConstantProjectedSlot(Constant value, MemberPath memberPath)
{
Debug.Assert(value != null);
Debug.Assert(value.IsNotNull() == false, "Cannot store NotNull in a slot - NotNull is only for conditions");
m_constant = value;
m_memberPath = memberPath;
}
示例7: DataVisitorBase
/// <summary>
/// Initializes a new instance of the <see cref="DataVisitorBase"/> class.
/// </summary>
/// <param name="typeDescriptorFactory">The type descriptor factory.</param>
/// <exception cref="ArgumentNullException">typeDescriptorFactory</exception>
protected DataVisitorBase(ITypeDescriptorFactory typeDescriptorFactory)
{
if (typeDescriptorFactory == null) throw new ArgumentNullException(nameof(typeDescriptorFactory));
TypeDescriptorFactory = typeDescriptorFactory;
CustomVisitors = new List<IDataCustomVisitor>();
context.DescriptorFactory = TypeDescriptorFactory;
context.Visitor = this;
CurrentPath = new MemberPath(16);
}
示例8: PopulateKeyConstraintsForEntitySet
// requires: this to correspond to a cell relation for an entityset (m_cellQuery.Extent)
// effects: Adds any key constraints present in this to constraints
private void PopulateKeyConstraintsForEntitySet(BasicSchemaConstraints constraints)
{
var prefix = new MemberPath(m_cellQuery.Extent);
var entityType = (EntityType)m_cellQuery.Extent.ElementType;
// Get all the keys for the entity type and create the key constraints
var keys = ExtentKey.GetKeysForEntityType(prefix, entityType);
AddKeyConstraints(keys, constraints);
}
示例9: CellQuery
// <summary>
// Copy Constructor
// </summary>
internal CellQuery(CellQuery source)
{
m_basicCellRelation = source.m_basicCellRelation;
m_boolExprs = source.m_boolExprs;
m_selectDistinct = source.m_selectDistinct;
m_extentMemberPath = source.m_extentMemberPath;
m_originalWhereClause = source.m_originalWhereClause;
m_projectedSlots = source.m_projectedSlots;
m_whereClause = source.m_whereClause;
}
示例10: GetKeysForEntityType
// effects: Determines all the keys (unique and primary for
// entityType) for entityType and returns a key. "prefix" gives the
// path of the extent or end of a relationship in a relationship set
// -- prefix is prepended to the entity's key fields to get the full memberpath
internal static List<ExtentKey> GetKeysForEntityType(MemberPath prefix, EntityType entityType)
{
// CHANGE_ADYA_MULTIPLE_KEYS: currently there is a single key only. Need to support
// keys inside complex types + unique keys
var key = GetPrimaryKeyForEntityType(prefix, entityType);
var keys = new List<ExtentKey>();
keys.Add(key);
return keys;
}
示例11: AsEsql
internal override StringBuilder AsEsql(StringBuilder builder, MemberPath outputMember, string blockAlias)
{
DebugCheck.NotNull(outputMember.LeafEdmMember);
var modelTypeUsage = Helper.GetModelTypeUsage(outputMember.LeafEdmMember);
var modelType = modelTypeUsage.EdmType;
// Some built-in constants
if (BuiltInTypeKind.PrimitiveType
== modelType.BuiltInTypeKind)
{
var primitiveTypeKind = ((PrimitiveType)modelType).PrimitiveTypeKind;
if (primitiveTypeKind == PrimitiveTypeKind.Boolean)
{
// This better be a boolean. Else we crash!
var val = (bool)m_scalar;
var value = StringUtil.FormatInvariant("{0}", val);
builder.Append(value);
return builder;
}
else if (primitiveTypeKind == PrimitiveTypeKind.String)
{
bool isUnicode;
if (!TypeHelpers.TryGetIsUnicode(modelTypeUsage, out isUnicode))
{
// If can't determine - use the safest option, assume unicode.
isUnicode = true;
}
if (isUnicode)
{
builder.Append('N');
}
AppendEscapedScalar(builder);
return builder;
}
}
else if (BuiltInTypeKind.EnumType
== modelType.BuiltInTypeKind)
{
// Enumerated type - we should be able to cast it
var enumMember = (EnumMember)m_scalar;
builder.Append(enumMember.Name);
return builder;
}
// Need to cast
builder.Append("CAST(");
AppendEscapedScalar(builder);
builder.Append(" AS ");
CqlWriter.AppendEscapedTypeName(builder, modelType);
builder.Append(')');
return builder;
}
示例12: PathString
public void PathString()
{
var path = new MemberPath(typeof(MemberPathTypes.With<MemberPathTypes.Parent>));
Assert.AreEqual("With<Parent>", path.PathString());
path = path.WithProperty(ChildProperty);
Assert.AreEqual("With<Parent>.Child", path.PathString());
path = path.WithProperty(ParentProperty);
Assert.AreEqual("With<Parent>.Child.Parent", path.PathString());
}
示例13: AsCqt
internal override DbExpression AsCqt(DbExpression row, MemberPath outputMember)
{
var cqt = m_memberPath.AsCqt(row);
TypeUsage outputMemberTypeUsage;
if (NeedToCastCqlValue(outputMember, out outputMemberTypeUsage))
{
cqt = cqt.CastTo(outputMemberTypeUsage);
}
return cqt;
}
示例14: IndexOf
/// <summary>
/// Returns a non-negative index of the <paramref name="member" /> if found, otherwise -1.
/// </summary>
internal int IndexOf(MemberPath member)
{
int index;
if (m_indexMap.TryGetValue(member, out index))
{
return index;
}
else
{
return -1;
}
}
示例15: GetPrimaryKeyForEntityType
// effects: Returns the key for entityType prefixed with prefix (for
// its memberPath)
internal static ExtentKey GetPrimaryKeyForEntityType(MemberPath prefix, EntityType entityType)
{
var keyFields = new List<MemberPath>();
foreach (var keyMember in entityType.KeyMembers)
{
Debug.Assert(keyMember != null, "Bogus key member in metadata");
keyFields.Add(new MemberPath(prefix, keyMember));
}
// Just have one key for now
var key = new ExtentKey(keyFields);
return key;
}