Пример #1
0
 public override object CreateInstance(ETypeCreationOptions options, object template)
 {
     if (options.HasFlag(ETypeCreationOptions.MultiplicativeNeutral) ||
         options.HasFlag(ETypeCreationOptions.NonZero))
     {
         if (template == null)
         {
             return(Unsigned.One);
         }
         else
         {
             var unsigned = (Unsigned)template;
             return(Unsigned.FromUInt(1, unsigned.Size));
         }
     }
     else
     {
         if (template == null)
         {
             return(Unsigned.Zero);
         }
         else
         {
             var unsigned = (Unsigned)template;
             return(Unsigned.FromUInt(0, unsigned.Size));
         }
     }
 }
Пример #2
0
 public override object CreateInstance(ETypeCreationOptions options, object template)
 {
     if (options.HasFlag(ETypeCreationOptions.MultiplicativeNeutral) ||
         options.HasFlag(ETypeCreationOptions.NonZero))
     {
         if (template == null)
         {
             return Signed.One;
         }
         else
         {
             var signed = (Signed)template;
             return Signed.FromInt(1, signed.Size);
         }
     }
     else
     {
         if (template == null)
         {
             return Signed.Zero;
         }
         else
         {
             var signed = (Signed)template;
             return Signed.FromInt(0, signed.Size);
         }
     }
 }
 public override object CreateInstance(ETypeCreationOptions options, object template)
 {
     if (options.HasFlag(ETypeCreationOptions.MultiplicativeNeutral) ||
         options.HasFlag(ETypeCreationOptions.NonZero))
         return (ushort)1;
     else
         return (ushort)0;
 }
Пример #4
0
 public override object CreateInstance(ETypeCreationOptions options, object template)
 {
     if (options.HasFlag(ETypeCreationOptions.MultiplicativeNeutral) ||
         options.HasFlag(ETypeCreationOptions.NonZero))
     {
         return((ushort)1);
     }
     else
     {
         return((ushort)0);
     }
 }
Пример #5
0
 public override object CreateInstance(ETypeCreationOptions options, object template)
 {
     if (options.HasFlag(ETypeCreationOptions.MultiplicativeNeutral))
     {
         return(1.0);
     }
     else
     {
         return(0.0);
     }
 }
Пример #6
0
 public override object CreateInstance(ETypeCreationOptions options, object template)
 {
     if (options.HasFlag(ETypeCreationOptions.MultiplicativeNeutral))
     {
         if (template == null)
         {
             return UFix.One;
         }
         else
         {
             var ufix = (UFix)template;
             return UFix.FromDouble(1.0, ufix.Format.IntWidth, ufix.Format.FracWidth);
         }
     }
     else if (options.HasFlag(ETypeCreationOptions.NonZero))
     {
         if (template == null)
         {
             return UFix.One;
         }
         else
         {
             var ufix = (UFix)template;
             return UFix.FromUnsigned(Unsigned.FromUInt(1, ufix.Format.TotalWidth), ufix.Format.FracWidth);
         }
     }
     else
     {
         if (template == null)
         {
             return UFix.Zero;
         }
         else
         {
             var ufix = (UFix)template;
             return UFix.FromDouble(0.0, ufix.Format.IntWidth, ufix.Format.FracWidth);
         }
     }
 }
Пример #7
0
 public override object CreateInstance(ETypeCreationOptions options, object template)
 {
     if (options.HasFlag(ETypeCreationOptions.MultiplicativeNeutral))
     {
         if (template == null)
         {
             return(SFix.One);
         }
         else
         {
             var sfix = (SFix)template;
             return(SFix.FromDouble(1.0, sfix.Format.IntWidth, sfix.Format.FracWidth));
         }
     }
     else if (options.HasFlag(ETypeCreationOptions.NonZero))
     {
         if (template == null)
         {
             return(SFix.One);
         }
         else
         {
             var sfix = (SFix)template;
             return(SFix.FromSigned(Signed.FromInt(1, sfix.Format.TotalWidth), sfix.Format.FracWidth));
         }
     }
     else
     {
         if (template == null)
         {
             return(SFix.Zero);
         }
         else
         {
             var sfix = (SFix)template;
             return(SFix.FromDouble(0.0, sfix.Format.IntWidth, sfix.Format.FracWidth));
         }
     }
 }
Пример #8
0
        /// <summary>
        /// Creates a sample instance of the described type.
        /// </summary>
        /// <param name="options">creation options</param>
        public object GetSampleInstance(ETypeCreationOptions options = ETypeCreationOptions.AnyObject)
        {
            Contract.Requires(
                !(options.HasFlag(ETypeCreationOptions.AdditiveNeutral) && options.HasFlag(ETypeCreationOptions.MultiplicativeNeutral)) &&
                !(options.HasFlag(ETypeCreationOptions.AdditiveNeutral) && options.HasFlag(ETypeCreationOptions.NonZero)) &&
                !(options.HasFlag(ETypeCreationOptions.MultiplicativeNeutral) && options.HasFlag(ETypeCreationOptions.NonZero)));

            if (IsArtificial)
                throw new InvalidOperationException("Cannot construct a sample instance from an artificial type");

            if (options.HasFlag(ETypeCreationOptions.AdditiveNeutral) ||
                options.HasFlag(ETypeCreationOptions.MultiplicativeNeutral) ||
                options.HasFlag(ETypeCreationOptions.NonZero))
            {
                var atf = CILType.GetCustomOrInjectedAttribute<IAlgebraicTypeFactory>();
                return atf.CreateInstance(options, _sample);
            }

            if (_sample != null)
                return _sample;

            if (options.HasFlag(ETypeCreationOptions.ReturnNullIfUnavailable))
                return null;

            if (!options.HasFlag(ETypeCreationOptions.ForceCreation) && (IsConstrained || !IsStatic))
                throw new InvalidOperationException("Cannot construct sample instance from constrained incomplete or non-static type");

            object inst = Activator.CreateInstance(CILType);
            return inst;
        }
 public override object CreateInstance(ETypeCreationOptions options, object template)
 {
     if (options.HasFlag(ETypeCreationOptions.MultiplicativeNeutral))
         return 1.0;
     else
         return 0.0;
 }
Пример #10
0
        /// <summary>
        /// Creates a sample instance of the described type.
        /// </summary>
        /// <param name="options">creation options</param>
        public object GetSampleInstance(ETypeCreationOptions options = ETypeCreationOptions.AnyObject)
        {
            Contract.Requires(
                !(options.HasFlag(ETypeCreationOptions.AdditiveNeutral) && options.HasFlag(ETypeCreationOptions.MultiplicativeNeutral)) &&
                !(options.HasFlag(ETypeCreationOptions.AdditiveNeutral) && options.HasFlag(ETypeCreationOptions.NonZero)) &&
                !(options.HasFlag(ETypeCreationOptions.MultiplicativeNeutral) && options.HasFlag(ETypeCreationOptions.NonZero)));

            if (IsArtificial)
            {
                throw new InvalidOperationException("Cannot construct a sample instance from an artificial type");
            }

            if (options.HasFlag(ETypeCreationOptions.AdditiveNeutral) ||
                options.HasFlag(ETypeCreationOptions.MultiplicativeNeutral) ||
                options.HasFlag(ETypeCreationOptions.NonZero))
            {
                var atf = CILType.GetCustomOrInjectedAttribute <IAlgebraicTypeFactory>();
                return(atf.CreateInstance(options, _sample));
            }

            if (_sample != null)
            {
                return(_sample);
            }

            if (options.HasFlag(ETypeCreationOptions.ReturnNullIfUnavailable))
            {
                return(null);
            }

            if (!options.HasFlag(ETypeCreationOptions.ForceCreation) && (IsConstrained || !IsStatic))
            {
                throw new InvalidOperationException("Cannot construct sample instance from constrained incomplete or non-static type");
            }

            object inst = Activator.CreateInstance(CILType);

            return(inst);
        }