Ejemplo n.º 1
0
        internal static unsafe NamedProperty FromNative(NativeClient.IFabricPropertyValueResult nativeResult, bool includesValue)
        {
            if (nativeResult == null)
            {
                return(null);
            }

            NativeTypes.FABRIC_NAMED_PROPERTY *nativeNamedProperty = (NativeTypes.FABRIC_NAMED_PROPERTY *)nativeResult.get_Property();

            if (nativeNamedProperty->Metadata == IntPtr.Zero)
            {
                AppTrace.TraceSource.WriteError("NamedProperty.GetValueInternal", "Property has no metadata");
                ReleaseAssert.Failfast(StringResources.Error_PropertyHasNoMetadata);
            }

            NativeTypes.FABRIC_NAMED_PROPERTY_METADATA *nativePropertyMetaData = (NativeTypes.FABRIC_NAMED_PROPERTY_METADATA *)nativeNamedProperty->Metadata;

            NamedPropertyMetadata namedPropertyMetadata = NamedPropertyMetadata.FromNative(*nativePropertyMetaData);

            if (nativeNamedProperty->Value == IntPtr.Zero)
            {
                includesValue = false;
            }

            NamedProperty returnValue = null;

            if (includesValue)
            {
                object value = null;

                switch (namedPropertyMetadata.TypeId)
                {
                case PropertyTypeId.Binary:
                    value = NativeTypes.FromNativeBytes(nativeNamedProperty->Value, (uint)namedPropertyMetadata.ValueSize);
                    break;

                case PropertyTypeId.Int64:
                    value = (Int64)(*((Int64 *)nativeNamedProperty->Value));
                    break;

                case PropertyTypeId.Double:
                    value = (double)(*((double *)nativeNamedProperty->Value));
                    break;

                case PropertyTypeId.String:
                    value = new string((char *)nativeNamedProperty->Value);
                    break;

                case PropertyTypeId.Guid:
                    value = (Guid)(*((Guid *)nativeNamedProperty->Value));
                    break;

                default:
                    AppTrace.TraceSource.WriteError("NamedProperty.GetValueInternal", "Unknown propertyTypeId: {0}", namedPropertyMetadata.TypeId);
                    throw new ArgumentException(string.Format(CultureInfo.CurrentCulture, StringResources.Error_PropertyTypeIDUnknown_Formatted, namedPropertyMetadata.TypeId));
                }

                returnValue = new NamedProperty(namedPropertyMetadata, value);
            }
            else
            {
                returnValue = new NamedProperty(namedPropertyMetadata);
            }

            GC.KeepAlive(nativeResult);
            return(returnValue);
        }
Ejemplo n.º 2
0
 private NamedProperty InternalGetProperty(int index)
 {
     NativeClient.IFabricPropertyValueResult nativeProperty = this.innerBatch.GetProperty((uint)index);
     return(NamedProperty.FromNative(nativeProperty, true /* includesValue */));
 }