コード例 #1
0
        internal static unsafe NamedPropertyMetadata FromNative(NativeClient.IFabricPropertyMetadataResult nativeResult)
        {
            if (nativeResult == null)
            {
                return(null);
            }

            NamedPropertyMetadata returnValue = FromNative(*((NativeTypes.FABRIC_NAMED_PROPERTY_METADATA *)nativeResult.get_Metadata()));

            GC.KeepAlive(nativeResult);
            return(returnValue);
        }
コード例 #2
0
ファイル: NamedProperty.cs プロジェクト: zmyer/service-fabric
 internal NamedProperty(NamedPropertyMetadata metadata, object value)
 {
     this.Metadata      = metadata;
     this.value         = value;
     this.includesValue = true;
 }
コード例 #3
0
ファイル: NamedProperty.cs プロジェクト: zmyer/service-fabric
 internal NamedProperty(NamedPropertyMetadata metadata)
 {
     this.Metadata = metadata;
 }
コード例 #4
0
ファイル: NamedProperty.cs プロジェクト: zmyer/service-fabric
        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);
        }