當前位置: 首頁>>代碼示例>>C#>>正文


C# PropertyDefinition.IsIQueryable方法代碼示例

本文整理匯總了C#中Mono.Cecil.PropertyDefinition.IsIQueryable方法的典型用法代碼示例。如果您正苦於以下問題:C# PropertyDefinition.IsIQueryable方法的具體用法?C# PropertyDefinition.IsIQueryable怎麽用?C# PropertyDefinition.IsIQueryable使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Mono.Cecil.PropertyDefinition的用法示例。


在下文中一共展示了PropertyDefinition.IsIQueryable方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: WeaveProperty


//.........這裏部分代碼省略.........
                methodTable[typeId] = realmAccessors = Tuple.Create(getter, setter);
            }

            ReplaceGetter(prop, columnName, realmAccessors.Item1);
            ReplaceSetter(prop, backingField, columnName, realmAccessors.Item2);
        }
        else if (prop.IsIList())
        {
            var elementType = ((GenericInstanceType)prop.PropertyType).GenericArguments.Single();
            if (!elementType.Resolve().BaseType.IsSameAs(_references.RealmObject))
            {
                return WeaveResult.Warning($"SKIPPING {type.Name}.{columnName} because it is an IList but its generic type is not a RealmObject subclass, so will not persist.");
            }

            if (prop.SetMethod != null)
            {
                return WeaveResult.Error($"{type.Name}.{columnName} has a setter but its type is a IList which only supports getters.");
            }

            var concreteListConstructor = _references.System_Collections_Generic_ListOfT_Constructor.MakeHostInstanceGeneric(elementType);

            // weaves list getter which also sets backing to List<T>, forcing it to accept us setting it post-init
            var backingDef = backingField as FieldDefinition;
            if (backingDef != null)
            {
                backingDef.Attributes &= ~FieldAttributes.InitOnly;  // without a set; auto property has this flag we must clear
            }

            ReplaceListGetter(prop, backingField, columnName,
                              new GenericInstanceMethod(_references.RealmObject_GetListValue) { GenericArguments = { elementType } },
                              concreteListConstructor);
        }
        else if (prop.PropertyType.Resolve().BaseType.IsSameAs(_references.RealmObject))
        {
            // with casting in the _realmObject methods, should just work
            ReplaceGetter(prop, columnName,
                          new GenericInstanceMethod(_references.RealmObject_GetObjectValue) { GenericArguments = { prop.PropertyType } });
            ReplaceSetter(prop, backingField, columnName,
                          new GenericInstanceMethod(_references.RealmObject_SetObjectValue) { GenericArguments = { prop.PropertyType } });
        }
        else if (prop.IsIQueryable())
        {
            var backlinkAttribute = prop.CustomAttributes.FirstOrDefault(a => a.AttributeType.Name == "BacklinkAttribute");
            if (backlinkAttribute == null)
            {
                return WeaveResult.Skipped();
            }

            if (prop.SetMethod != null)
            {
                return WeaveResult.Error("Backlink properties must be read-only.");
            }

            var elementType = ((GenericInstanceType)prop.PropertyType).GenericArguments.Single();
            var inversePropertyName = (string)backlinkAttribute.ConstructorArguments[0].Value;
            var inverseProperty = elementType.Resolve().Properties.SingleOrDefault(p => p.Name == inversePropertyName);

            if (inverseProperty == null || (!inverseProperty.PropertyType.IsSameAs(type) && !inverseProperty.IsIList(type)))
            {
                return WeaveResult.Error($"The property '{elementType.Name}.{inversePropertyName}' does not constitute a link to '{type.Name}' as described by '{type.Name}.{prop.Name}'.");
            }

            var backingDef = backingField as FieldDefinition;
            if (backingDef != null)
            {
                backingDef.Attributes &= ~FieldAttributes.InitOnly; // without a set; auto property has this flag we must clear
            }

            ReplaceBacklinksGetter(prop, backingField, columnName, elementType);
        }
        else if (prop.SetMethod == null)
        {
            return WeaveResult.Skipped();
        }
        else if (prop.PropertyType.FullName == "System.DateTime")
        {
            return WeaveResult.Error($"Class '{type.Name}' field '{prop.Name}' is a DateTime which is not supported - use DateTimeOffset instead.");
        }
        else if (prop.PropertyType.FullName == "System.Nullable`1<System.DateTime>")
        {
            return WeaveResult.Error($"Class '{type.Name}' field '{prop.Name}' is a DateTime? which is not supported - use DateTimeOffset? instead.");
        }
        else
        {
            return WeaveResult.Error($"Class '{type.Name}' field '{columnName}' is a '{prop.PropertyType}' which is not yet supported.");
        }

        var preserveAttribute = new CustomAttribute(_references.PreserveAttribute_Constructor);
        prop.CustomAttributes.Add(preserveAttribute);

        var wovenPropertyAttribute = new CustomAttribute(_references.WovenPropertyAttribute_Constructor);
        prop.CustomAttributes.Add(wovenPropertyAttribute);

        Debug.WriteLine(string.Empty);

        var primaryKeyMsg = isPrimaryKey ? "[PrimaryKey]" : string.Empty;
        var indexedMsg = isIndexed ? "[Indexed]" : string.Empty;
        LogDebug($"Woven {type.Name}.{prop.Name} as a {prop.PropertyType.FullName} {primaryKeyMsg} {indexedMsg}.");
        return WeaveResult.Success(prop, backingField, isPrimaryKey);
    }
開發者ID:realm,項目名稱:realm-dotnet,代碼行數:101,代碼來源:ModuleWeaver.cs


注:本文中的Mono.Cecil.PropertyDefinition.IsIQueryable方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。