示例#1
0
        public static object ConstructRubyTimestampYMD(IConstructor ctor, Node node)
        {
            ScalarNode scalar = node as ScalarNode;

            if (scalar == null)
            {
                throw new ConstructorException("Can only contruct timestamp from scalar node.");
            }

            Match match = SafeConstructor.YMD_REGEXP.Match(scalar.Value);

            if (match.Success)
            {
                int year_ymd  = int.Parse(match.Groups[1].Value);
                int month_ymd = int.Parse(match.Groups[2].Value);
                int day_ymd   = int.Parse(match.Groups[3].Value);

                RubyModule module;
                RubyScope  scope = ctor.Scope;
                if (scope.RubyContext.TryGetModule(scope.GlobalScope, "Date", out module))
                {
                    return(_New.Target(_New, scope.RubyContext, module, year_ymd, month_ymd, day_ymd));
                }
                else
                {
                    throw new ConstructorException("Date class not found.");
                }
            }
            throw new ConstructorException("Invalid tag:yaml.org,2002:timestamp#ymd value.");
        }
示例#2
0
        public IEntity GetDefaultMember()
        {
            IType defaultMemberAttribute = _typeSystemServices.Map(typeof(DefaultMemberAttribute));

            foreach (Attribute attribute in _typeDefinition.Attributes)
            {
                IConstructor tag = TypeSystemServices.GetEntity(attribute) as IConstructor;
                if (null != tag)
                {
                    if (defaultMemberAttribute == tag.DeclaringType)
                    {
                        StringLiteralExpression memberName = attribute.Arguments[0] as StringLiteralExpression;
                        if (null != memberName)
                        {
                            List buffer = new List();
                            Resolve(buffer, memberName.Value, EntityType.Any);
                            return(NameResolutionService.GetEntityFromList(buffer));
                        }
                    }
                }
            }
            if (null != BaseType)
            {
                return(BaseType.GetDefaultMember());
            }
            return(null);
        }
示例#3
0
        public Statement CreateSuperConstructorInvocation(IType baseType)
        {
            IConstructor defaultConstructor = _tss.GetDefaultConstructor(baseType);

            Debug.Assert(null != defaultConstructor);
            return(CreateSuperConstructorInvocation(defaultConstructor));
        }
示例#4
0
        private void lstShips_ItemMouseHover(object sender, ListViewItemMouseHoverEventArgs e)
        {
            var d = (IDesign)e.Item.Tag;

            txtName.Text      = d.Name;
            resCostMin.Amount = d.Cost[Resource.Minerals];
            resCostOrg.Amount = d.Cost[Resource.Organics];
            resCostRad.Amount = d.Cost[Resource.Radioactives];

            int present, queued;
            IEnumerable <IConstructor> sobjs;
            var emp = ConstructionQueue.Container.Owner;

            sobjs   = new IConstructor[] { ConstructionQueue.Container };
            present = CountPresentVehicles(sobjs, d.BaseName);
            queued  = CountQueuedVehicles(sobjs, d.BaseName);
            lblPresentLocal.Text = MakePresentQueuedString(present, queued);

            sobjs   = ConstructionQueue.Container.Sector.SpaceObjects.OfType <IConstructor>().OwnedBy(emp);;
            present = CountPresentVehicles(sobjs, d.BaseName);
            queued  = CountQueuedVehicles(sobjs, d.BaseName);
            lblPresentSector.Text = MakePresentQueuedString(present, queued);

            sobjs   = ConstructionQueue.Container.StarSystem.SpaceObjects.OfType <IConstructor>().OwnedBy(emp);
            present = CountPresentVehicles(sobjs, d.BaseName);
            queued  = CountQueuedVehicles(sobjs, d.BaseName);
            lblPresentSystem.Text = MakePresentQueuedString(present, queued);

            sobjs   = ConstructionQueue.Owner.OwnedSpaceObjects.OfType <IConstructor>();
            present = CountPresentVehicles(sobjs, d.BaseName);
            queued  = CountQueuedVehicles(sobjs, d.BaseName);
            lblPresentEmpire.Text = MakePresentQueuedString(present, queued);
        }
示例#5
0
        IType GetEnumeratorItemTypeFromAttribute(IType iteratorType)
        {
            // If iterator type is external get its attributes via reflection
            if (iteratorType is ExternalType)
            {
                return(GetExternalEnumeratorItemType(iteratorType));
            }

            // If iterator type is a generic constructed type, map its attribute from its definition
            GenericConstructedType constructedType = iteratorType as GenericConstructedType;

            if (constructedType != null)
            {
                return(constructedType.GenericMapping.Map(
                           GetEnumeratorItemTypeFromAttribute(constructedType.GenericDefinition)));
            }

            // If iterator type is internal get its attributes from its type definition
            AbstractInternalType internalType = (AbstractInternalType)iteratorType;
            IType enumeratorItemTypeAttribute = Map(typeof(EnumeratorItemTypeAttribute));

            foreach (Attribute attribute in internalType.TypeDefinition.Attributes)
            {
                IConstructor constructor = GetEntity(attribute) as IConstructor;
                if (null != constructor)
                {
                    if (constructor.DeclaringType == enumeratorItemTypeAttribute)
                    {
                        return(GetType(attribute.Arguments[0]));
                    }
                }
            }
            return(null);
        }
示例#6
0
 public string GetClass(string json)
 {
     _Input        = json;
     _Decompositor = Decompositor.Create().SetJSONString(json).Go();
     _Constructor  = Constructor.Create().SetDecompositor(_Decompositor).Construct();
     return(_Constructor.GetClass());
 }
        public static bool IsReturnTypeIObservable(IConstructor constructor)
        {
            try
            {
                var declaredType = constructor.ReturnType as IDeclaredType;
                if (declaredType == null)
                {
                    return false;
                }

                if (declaredType.Assembly == null)
                {
                    return false;
                }

                var typeElement = constructor.GetContainingType();
                if (typeElement == null)
                {
                    return false;
                }

                return typeElement.GetSuperTypes()
                    .Select(t => t.GetClrName().FullName)
                    .Any(n => n == Constants.ObservableInterfaceName);
            }
            catch (Exception exn)
            {
                Debug.WriteLine(exn);
                return false;
            }
        }
示例#8
0
            public object Construct(IConstructor ctor, string tag, Node node)
            {
                object result;

                _block.Yield(MutableString.Create(tag), ctor.ConstructPrimitive(node), out result);
                return(result);
            }
示例#9
0
 public static object ConstructYamlBool(IConstructor ctor, Node node) {
     bool result;
     if (TryConstructYamlBool(ctor, node, out result)) {
         return result;
     }
     return null;
 }
示例#10
0
        public Attribute CreateAttribute(IConstructor constructor, Expression arg)
        {
            Attribute attribute = CreateAttribute(constructor);

            attribute.Arguments.Add(arg);
            return(attribute);
        }
        public override bool IsAvailable(IUserDataHolder cache)
        {
            var testProjectProvider = ComponentResolver.GetComponent <ITestProjectProvider>(_dataProvider);

            _selectedElement      = _dataProvider.GetSelectedElement <IObjectCreationExpression>(false, false);
            _csharpMemberProvider = ComponentResolver.GetComponent <ICsharpMemberProvider>(_dataProvider);
            if (!(_selectedElement?.TypeReference?.Resolve().DeclaredElement is IClass c))
            {
                return(false);
            }

            var parameterCount = _selectedElement.ArgumentList?.Arguments.Count(x => x.Kind != ParameterKind.UNKNOWN);

            _constructor = c.Constructors.FirstOrDefault(x => !x.IsParameterless &&
                                                         x.Parameters.Count > parameterCount &&
                                                         x.Parameters.All(_csharpMemberProvider.IsAbstractOrInterface));
            if (_constructor == null)
            {
                return(false);
            }

            var isAvailable = testProjectProvider.IsTestProject(_dataProvider.PsiModule) && _selectedElement != null && _selectedElement.Arguments.Count == 0;

            if (isAvailable)
            {
                cache.PutKey(AnchorKey.FillWithMockContextActionKey);
            }

            return(isAvailable);
        }
 public IEnumerable <object> GenerateParameterValues(IConstructor constructor, IConstructorInstanceCreator instanceCreator)
 {
     foreach (IParameter parameter in constructor.Parameters)
     {
         yield return(instanceCreator.CreateInstance(parameter.Type));
     }
 }
示例#13
0
 /// <summary>Initializes a new instance of the <see cref="ConstructorDeclarationModel"/> class. </summary>
 /// <param name="constructorDeclaration">The constructor declaration. </param>
 public ConstructorDeclarationModel(IConstructorDeclaration constructorDeclaration)
     : base(null, constructorDeclaration)
 {
     if (constructorDeclaration.Initializer != null)
     {
         ThrownExceptions.Add(new ConstructorInitializerModel(this, constructorDeclaration.Initializer, this));
     }
     else
     {
         if (constructorDeclaration.DeclaredElement != null && constructorDeclaration.DeclaredElement.IsDefault)
         {
             var containingType = constructorDeclaration.DeclaredElement.GetContainingType();
             if (containingType != null)
             {
                 var baseClass = containingType.GetSuperTypes().FirstOrDefault(t => !t.IsInterfaceType());
                 if (baseClass != null)
                 {
                     var baseClassTypeElement = baseClass.GetTypeElement();
                     if (baseClassTypeElement != null)
                     {
                         IConstructor defaultBaseConstructor = baseClassTypeElement.Constructors.First(c => c.IsDefault);
                         if (defaultBaseConstructor != null)
                         {
                             ThrownExceptions.Add(new ConstructorInitializerModel(this, defaultBaseConstructor, this));
                         }
                     }
                 }
             }
         }
     }
 }
        private bool AddConstructor(IClass cl)
        {
            RDomConstructor constructor = CreateRDomConstructor(cl);

            triviaManager.StoreStringWhitespace(constructor, LanguageElement.ParameterEndDelimiter, "", "\r\n");
            triviaManager.StoreStringWhitespace(constructor, LanguageElement.ConstructorInitializerPrefix, "       ", "");
            var properties  = cl.Properties.Where(x => x.CanSet && x.CanGet);
            var assignments = new List <IAssignmentStatement>();

            assignments.Add(new RDomAssignmentStatement(
                                RDom.CSharp.ParseExpression("NeedsFormatting"),
                                RDom.CSharp.ParseExpression("true")));
            triviaManager.StoreStringWhitespace(assignments.First(), LanguageElement.EndOfLine, "", "\r\n");
            var altConstructorPairs = new List <Tuple <RDomParameter, RDomParameter, RDomArgument> >();

            foreach (var prop in properties)
            {
                RDomParameter param = CreateParameter(assignments, altConstructorPairs, prop);
                constructor.Parameters.AddOrMove(param);
            }
            constructor.StatementsAll.AddOrMoveRange(assignments);
            if (altConstructorPairs.Any())
            {
                IConstructor altConstructor = CreateAlternateConstructor(constructor, altConstructorPairs);
                cl.InsertAfterInitialFields(altConstructor);
            }
            return(true);
        }
示例#15
0
 public void LocateConstructor(IConstructor cp)
 {
     for (int i = 0; i < treeViewConstructors.Nodes.Count; i++)
     {
         TreeNodeConstructor tn = treeViewConstructors.Nodes[i] as TreeNodeConstructor;
         if (tn != null)
         {
             ConstructorPointer cp0 = tn.OwnerPointer as ConstructorPointer;
             if (cp0.IsSameMethod((IMethod)cp))
             {
                 cp0.CopyFrom(cp);
                 treeViewConstructors.SelectedNode = tn;
                 break;
             }
         }
         else
         {
             TreeNodeCustomConstructorPointer tn2 = treeViewConstructors.Nodes[i] as TreeNodeCustomConstructorPointer;
             if (tn2 != null)
             {
                 CustomConstructorPointer cp2 = tn2.OwnerPointer as CustomConstructorPointer;
                 if (cp2.IsSameMethod((IMethod)cp))
                 {
                     treeViewConstructors.SelectedNode = tn2;
                     break;
                 }
             }
         }
     }
 }
示例#16
0
        public override bool IsAvailable(IUserDataHolder cache)
        {
            var testProjectProvider = ComponentResolver.GetComponent <ITestProjectProvider>(_dataProvider);

            _parameterProvider = ComponentResolver.GetComponent <IParameterProvider>(_dataProvider);
            _selectedElement   = _dataProvider.GetSelectedElement <IObjectCreationExpression>(false, false);
            _block             = _dataProvider.GetSelectedElement <IBlock>();
            _classBody         = _dataProvider.GetSelectedElement <IClassBody>();
            _classDeclaration  = _classBody?.GetContainingTypeDeclaration() as IClassLikeDeclaration;

            if (_classDeclaration == null || _block == null || _selectedElement == null)
            {
                return(false);
            }

            if (!(_selectedElement.TypeReference?.Resolve().DeclaredElement is IClass c))
            {
                return(false);
            }

            _parameterNumber = _selectedElement.ArgumentList.Arguments.Count(x => x.Kind != ParameterKind.UNKNOWN);
            _constructor     = c.Constructors.ToArray().FirstOrDefault(x => !x.IsParameterless && x.Parameters.Count > _parameterNumber);
            if (_constructor == null)
            {
                return(false);
            }

            return(testProjectProvider.IsTestProject(_dataProvider.PsiModule));
        }
示例#17
0
        public MethodInvocationExpression CreateConstructorInvocation(IConstructor constructor, Expression arg1, Expression arg2)
        {
            MethodInvocationExpression mie = CreateConstructorInvocation(constructor, arg1);

            mie.Arguments.Add(arg2);
            return(mie);
        }
 public MockPokerHandConverter(
     IConstructor <IConvertedPokerPlayer> convertedPlayer,
     IConstructor <IConvertedPokerHand> convertedHand,
     IPokerRoundsConverter roundsConverter)
     : base(convertedPlayer, convertedHand, roundsConverter)
 {
 }
        protected override IMember CreateMappedMember(IMember source)
        {
            switch (source.EntityType)
            {
            case EntityType.Method:
                IMethod method = (IMethod)source;
                return(new GenericMappedMethod(TypeSystemServices, method, this));

            case EntityType.Constructor:
                IConstructor ctor = (IConstructor)source;
                return(new GenericMappedConstructor(TypeSystemServices, ctor, this));

            case EntityType.Field:
                IField field = (IField)source;
                return(new GenericMappedField(TypeSystemServices, field, this));

            case EntityType.Property:
                IProperty property = (IProperty)source;
                return(new GenericMappedProperty(TypeSystemServices, property, this));

            case EntityType.Event:
                IEvent evt = (IEvent)source;
                return(new GenericMappedEvent(TypeSystemServices, evt, this));

            default:
                return(source);
            }
        }
示例#20
0
        public PlayerPeekerService(IEventAggregator eventAggregator, IConstructor <IPlayerPeekerForm> playerPeekerFormMake)
        {
            _playerPeekerFormMake = playerPeekerFormMake;
            _eventAggregator      = eventAggregator;

            RegisterEvents();
        }
        protected override T DeserializeClass <T>(IConstructor ctor)
        {
            int instanceId = _reader.ReadInt();

            while (instanceId >= _instances.Count)
            {
                _instances.Add(new InstanceInfo());
            }

            InstanceInfo instanceInfo = _instances[instanceId];

            if (instanceInfo.IsInitialized)
            {
                return((T)instanceInfo.Instance);
            }
            else
            {
                var value = ctor.Construct() as T;

                instanceInfo.IsInitialized = true;
                instanceInfo.Instance      = value;
                _instances[instanceId]     = instanceInfo;

                if (value != null)
                {
                    DeserializeClass(value);
                }

                return(value);
            }
        }
示例#22
0
        public Attribute CreateAttribute(IConstructor constructor)
        {
            Attribute attribute = new Attribute();

            attribute.Name   = constructor.DeclaringType.FullName;
            attribute.Entity = constructor;
            return(attribute);
        }
示例#23
0
        public Statement CreateSuperConstructorInvocation(IConstructor defaultConstructor)
        {
            MethodInvocationExpression call = new MethodInvocationExpression(new SuperLiteralExpression());

            call.Target.Entity  = defaultConstructor;
            call.ExpressionType = _tss.VoidType;
            return(new ExpressionStatement(call));
        }
示例#24
0
        public ConstructorInitializerModel(
            ConstructorDeclarationModel analyzeUnit,
            IConstructor constructor,
            ConstructorDeclarationModel containingBlock)
            : base(
                analyzeUnit,
#if R2017_1
                analyzeUnit.Node.TypeName
        public object CreateInstance(Type @class)
        {
            IConstructor         constructor = ConstructorProvider.ProvideConstructor(@class);
            IEnumerable <object> values      = ParametersGenerator.GenerateParameterValues(constructor, this);
            object instance = ConstructorInvoker.InvokeConstructor(constructor, values);

            return(instance);
        }
示例#26
0
 public void CrearManual(IConstructor _IConstructor)
 {
     _IConstructor.Reset();
     _IConstructor.AsignarAsientos(2);
     _IConstructor.AsignarMotor("V8");
     _IConstructor.AsignarComputadoraDeViaje();
     _IConstructor.AsignarGPS();
 }
示例#27
0
 public static bool TryConstructYamlBool(IConstructor ctor, Node node, out bool result)
 {
     if (BOOL_VALUES.TryGetValue(ctor.ConstructScalar(node).ToString(), out result))
     {
         return(true);
     }
     return(false);
 }
示例#28
0
        public MethodInvocationExpression CreateConstructorInvocation(IConstructor constructor, Expression arg)
        {
            MethodInvocationExpression mie = CreateConstructorInvocation(constructor);

            mie.LexicalInfo = arg.LexicalInfo;
            mie.Arguments.Add(arg);
            return(mie);
        }
示例#29
0
 public void CrearAuto(IConstructor _IConstructor)
 {
     _IConstructor.Reset();
     _IConstructor.AsignarAsientos(4);
     _IConstructor.AsignarMotor("V11");
     _IConstructor.AsignarComputadoraDeViaje();
     _IConstructor.AsignarGPS();
 }
        public void CopyFrom(IConstructor cp)
        {
            CustomConstructorPointer ccp = cp as CustomConstructorPointer;

            if (ccp != null)
            {
            }
        }
 public FakeHandHistoriesViewModel(
     IConstructor <IHandHistoryViewModel> handHistoryViewModelMake,
     IItemsPagesManager <IHandHistoryViewModel> itemsPagesManager,
     IHandHistoriesFilter handHistoriesFilter)
     : base(handHistoryViewModelMake, itemsPagesManager, handHistoriesFilter)
 {
     InterceptOnSetMethods = false;
 }
示例#32
0
        public static Range ConstructRubyRange(IConstructor /*!*/ ctor, Node node)
        {
            object     begin      = null;
            object     end        = null;
            bool       excludeEnd = false;
            ScalarNode scalar     = node as ScalarNode;

            if (scalar != null)
            {
                string value = scalar.Value;
                int    dotsIdx;
                if ((dotsIdx = value.IndexOf("...")) != -1)
                {
                    begin      = ParseObject(ctor, value.Substring(0, dotsIdx));
                    end        = ParseObject(ctor, value.Substring(dotsIdx + 3));
                    excludeEnd = true;
                }
                else if ((dotsIdx = value.IndexOf("..")) != -1)
                {
                    begin = ParseObject(ctor, value.Substring(0, dotsIdx));
                    end   = ParseObject(ctor, value.Substring(dotsIdx + 2));
                }
                else
                {
                    throw new ConstructorException("Invalid Range: " + value);
                }
            }
            else
            {
                MappingNode mapping = node as MappingNode;
                if (mapping == null)
                {
                    throw new ConstructorException("Invalid Range: " + node);
                }
                foreach (KeyValuePair <Node, Node> n in mapping.Nodes)
                {
                    string key = ctor.ConstructScalar(n.Key).ToString();
                    switch (key)
                    {
                    case "begin":
                        begin = ctor.ConstructObject(n.Value);
                        break;

                    case "end":
                        end = ctor.ConstructObject(n.Value);
                        break;

                    case "excl":
                        TryConstructYamlBool(ctor, n.Value, out excludeEnd);
                        break;

                    default:
                        throw new ConstructorException(string.Format("'{0}' is not allowed as an instance variable name for class Range", key));
                    }
                }
            }
            return(new Range(ctor.Scope.RubyContext, begin, end, excludeEnd));
        }
 public BoundObjectCreationExpression(
     IType type,
     IConstructor boundConstructor,
     List<BoundExpression> boundParameter,
     ObjectCreationExpressionSyntax expressionSyntax)
     : base(expressionSyntax, type)
 {
     BoundConstructor = boundConstructor;
     BoundParameter = boundParameter;
 }
 public override void Initialize(CompilerContext context)
 {
     base.Initialize(context);
     Type type = typeof(UnityRuntimeServices.MemberValueTypeChange);
     this._valueTypeChangeConstructor = this.get_TypeSystemServices().Map(type.GetConstructors()[0]);
     this._valueTypeChangeType = this.get_TypeSystemServices().Map(typeof(UnityRuntimeServices.ValueTypeChange));
     Type type2 = typeof(UnityRuntimeServices.SliceValueTypeChange);
     this._sliceValueTypeChangeConstructor = this.get_TypeSystemServices().Map(type2.GetConstructors()[0]);
     this._propagateChanges = this.get_TypeSystemServices().Map(new __ProcessAssignmentToDuckMembers_Initialize$callable0$25_95__(UnityRuntimeServices.PropagateValueTypeChanges).Method);
 }
 public MethodInvocationExpression CreateConstructorInvocation(IConstructor ctor, params Expression[] args)
 {
     MethodInvocationExpression expression = this.get_CodeBuilder().CreateConstructorInvocation(ctor);
     int index = 0;
     Expression[] expressionArray = args;
     int length = expressionArray.Length;
     while (index < length)
     {
         expression.get_Arguments().Add(expressionArray[index]);
         index++;
     }
     return expression;
 }
        public static bool IsContructor(IObjectCreationExpression creationExpression, out IConstructor constructor)
        {
            constructor = null;

            try
            {
                if (creationExpression.Reference == null)
                {
                    return false;
                }

                var resolveResult = creationExpression.Reference.Resolve();
                constructor = resolveResult.DeclaredElement as IConstructor;

                return constructor != null;
            }
            catch (Exception exn)
            {
                Debug.WriteLine(exn);
                return false;
            }
        }
示例#37
0
 public Attribute CreateAttribute(IConstructor constructor, Expression arg)
 {
     var attribute = CreateAttribute(constructor);
     attribute.Arguments.Add(arg);
     return attribute;
 }
示例#38
0
 public MethodInvocationExpression CreateConstructorInvocation(IConstructor constructor)
 {
     MethodInvocationExpression mie = new MethodInvocationExpression();
     mie.Target = new ReferenceExpression(constructor.DeclaringType.FullName);
     mie.Target.Entity = constructor;
     mie.ExpressionType = constructor.DeclaringType;
     return mie;
 }
示例#39
0
 public MethodInvocationExpression CreateConstructorInvocation(IConstructor constructor, Expression arg)
 {
     MethodInvocationExpression mie = CreateConstructorInvocation(constructor);
     mie.LexicalInfo = arg.LexicalInfo;
     mie.Arguments.Add(arg);
     return mie;
 }
示例#40
0
 void BindConstructorInvocation(MethodInvocationExpression node, IConstructor ctor)
 {
     // rebind the target now we know
     // it is a constructor call
     Bind(node.Target, ctor);
     BindExpressionType(node.Target, ctor.Type);
     BindExpressionType(node, ctor.DeclaringType);
 }
示例#41
0
 public RaiseStatement RaiseException(LexicalInfo lexicalInfo, IConstructor exceptionConstructor, params Expression[] args)
 {
     Debug.Assert(TypeSystemServices.IsValidException(exceptionConstructor.DeclaringType));
     return new RaiseStatement(lexicalInfo, CreateConstructorInvocation(lexicalInfo, exceptionConstructor, args));
 }
示例#42
0
        /// <summary>
        /// Retrieves the ConstructorInfo for a constructor as mapped on a generic type.
        /// </summary>
        private ConstructorInfo GetMappedConstructorInfo(IType targetType, IConstructor source)
        {
            ConstructorInfo ci = GetConstructorInfo(source);
            if (!ci.DeclaringType.IsGenericTypeDefinition)
            {
                // HACK: .NET Reflection doesn't allow calling
                // TypeBuilder.GetConstructor(Type, ConstructorInfo) on types that aren't generic
                // definitions, so we have to manually find the corresponding ConstructorInfo on the
                // declaring type's definition before mapping it
                Type definition = ci.DeclaringType.GetGenericTypeDefinition();
                ci = Array.Find<ConstructorInfo>(
                    definition.GetConstructors(),
                    delegate(ConstructorInfo other) { return other.MetadataToken == ci.MetadataToken; });
            }

            return TypeBuilder.GetConstructor(GetSystemType(targetType), ci);
        }
示例#43
0
 public static byte[] ConstructYamlBinary(IConstructor ctor, Node node) {
     string val = ctor.ConstructScalar(node).ToString().Replace("\r", "").Replace("\n", "");
     return Convert.FromBase64String(val);
 }
示例#44
0
 public static object ConstructSpecializedSequence(IConstructor ctor, string pref, Node node) {
     RubyArray result = null;
     try {
         result = (RubyArray)Type.GetType(pref).GetConstructor(Type.EmptyTypes).Invoke(null);
     } catch (Exception e) {
         throw new ConstructorException("Can't construct a sequence from class: " + pref, e);
     }
     foreach (object x in ctor.ConstructSequence(node)) {
         result.Add(x);
     }
     return result;
 }
示例#45
0
        ConstructorInfo GetConstructorInfo(IConstructor entity)
        {
            // If constructor is external, get its existing ConstructorInfo
            ExternalConstructor external = entity as ExternalConstructor;
            if (null != external)
            {
                return external.ConstructorInfo;
            }

            // If constructor is mapped from a generic type, get its ConstructorInfo on the constructed type
            GenericMappedConstructor mapped = entity as GenericMappedConstructor;
            if (mapped != null)
            {
                return TypeBuilder.GetConstructor(GetSystemType(mapped.DeclaringType), GetConstructorInfo((IConstructor)mapped.SourceMember));
            }

            // If constructor is internal, get its MethodBuilder
            return GetConstructorBuilder(((InternalMethod)entity).Method);
        }
示例#46
0
 public static object ConstructSpecializedMap(IConstructor ctor, string pref, Node node) {
     Hash result = null;
     try {
         result = (Hash)Type.GetType(pref).GetConstructor(Type.EmptyTypes).Invoke(null);
     } catch (Exception e) {
         throw new ConstructorException("Can't construct a mapping from class: " + pref, e);
     }
     foreach (KeyValuePair<object, object> e in ctor.ConstructMapping(node)) {
         result.Add(e.Key, e.Value);
     }
     return result;
 }
示例#47
0
 public static object ConstructYamlOmap(IConstructor ctor, Node node) {
     return ctor.ConstructPairs(node);
 }
示例#48
0
 public static bool TryConstructYamlBool(IConstructor ctor, Node node, out bool result) {            
     if (BOOL_VALUES.TryGetValue(ctor.ConstructScalar(node).ToString(), out result)) {
         return true;
     }
     return false;
 }
示例#49
0
        public static object ConstructCliObject(IConstructor ctor, string pref, Node node) {
            // TODO: should this use serialization or some more standard CLR mechanism?
            //       (it is very ad-hoc)
            // TODO: use DLR APIs instead of reflection
            try {
                Type type = Type.GetType(pref);
                object result = type.GetConstructor(Type.EmptyTypes).Invoke(null);

                foreach (KeyValuePair<object, object> e in ctor.ConstructMapping(node)) {
                    string name = e.Key.ToString();
                    name = "" + char.ToUpper(name[0]) + name.Substring(1);
                    PropertyInfo prop = type.GetProperty(name);

                    prop.SetValue(result, Convert.ChangeType(e.Value, prop.PropertyType), null);
                }
                return result;

            } catch (Exception e) {
                throw new ConstructorException("Can't construct a CLI object from class: " + pref, e);
            }
        }
示例#50
0
 public static object ConstructYamlNull(IConstructor ctor, Node node) {
     return null;
 }
示例#51
0
 public Attribute CreateAttribute(IConstructor constructor)
 {
     return new Attribute { Name = constructor.DeclaringType.FullName, Entity = constructor };
 }
示例#52
0
 public static object constructUndefined(IConstructor ctor, Node node) {
     throw new ConstructorException("could not determine a constructor for the tag: " + node.Tag);
 }
示例#53
0
 public MethodInvocationExpression CreateConstructorInvocation(IConstructor constructor, Expression arg1, Expression arg2)
 {
     MethodInvocationExpression mie = CreateConstructorInvocation(constructor, arg1);
     mie.Arguments.Add(arg2);
     return mie;
 }
示例#54
0
        public static object ConstructYamlTimestampYMD(IConstructor ctor, Node node) {
            ScalarNode scalar = node as ScalarNode;
            if (scalar == null) {
                throw new ConstructorException("can only contruct timestamp from scalar node");
            }

            Match match = YMD_REGEXP.Match(scalar.Value);
            if (match.Success) {
                int year_ymd = int.Parse(match.Groups[1].Value);
                int month_ymd = int.Parse(match.Groups[2].Value);
                int day_ymd = int.Parse(match.Groups[3].Value);

                return new DateTime(year_ymd, month_ymd, day_ymd);
            }
            throw new ConstructorException("Invalid tag:yaml.org,2002:timestamp#ymd value.");
        }
示例#55
0
 public MethodInvocationExpression CreateConstructorInvocation(LexicalInfo lexicalInfo, IConstructor constructor, params Expression[] args)
 {
     MethodInvocationExpression mie = CreateConstructorInvocation(constructor);
     mie.LexicalInfo = lexicalInfo;
     mie.Arguments.AddRange(args);
     return mie;
 }
示例#56
0
        public static object ConstructYamlTimestamp(IConstructor ctor, Node node) {
            ScalarNode scalar = node as ScalarNode;
            if (scalar == null) {
                throw new ConstructorException("can only contruct timestamp from scalar node");
            }
            
            Match match = TIMESTAMP_REGEXP.Match(scalar.Value);

            if (!match.Success) {
                return ctor.ConstructPrivateType(node);
            }

            string year_s = match.Groups[1].Value;
            string month_s = match.Groups[2].Value;
            string day_s = match.Groups[3].Value;
            string hour_s = match.Groups[4].Value;
            string min_s = match.Groups[5].Value;
            string sec_s = match.Groups[6].Value;
            string fract_s = match.Groups[7].Value;
            string utc = match.Groups[8].Value;
            string timezoneh_s = match.Groups[9].Value;
            string timezonem_s = match.Groups[10].Value;

            bool isUtc = utc == "Z" || utc == "z";

            DateTime dt = new DateTime(
                year_s != "" ? int.Parse(year_s) : 0,
                month_s != "" ? int.Parse(month_s) : 1,
                day_s != "" ? int.Parse(day_s) : 1,
                hour_s != "" ? int.Parse(hour_s) : 0,
                min_s != "" ? int.Parse(min_s) : 0,
                sec_s != "" ? int.Parse(sec_s) : 0,
                isUtc? DateTimeKind.Utc : DateTimeKind.Local
            );

            if (!string.IsNullOrEmpty(fract_s)) {
                long fract = int.Parse(fract_s);
                if (fract > 0) {
                    while (fract < 1000000) {
                        fract *= 10;
                    }
                    dt = dt.AddTicks(fract);
                }
            }

            if (!isUtc) {
                if (timezoneh_s != "" || timezonem_s != "") {
                    int zone = 0;
                    int sign = +1;
                    if (timezoneh_s != "") {
                        if (timezoneh_s.StartsWith("-")) {
                            sign = -1;
                        }
                        zone += int.Parse(timezoneh_s.Substring(1)) * 3600000;
                    }
                    if (timezonem_s != "") {
                        zone += int.Parse(timezonem_s) * 60000;
                    }
                    double utcOffset = TimeZone.CurrentTimeZone.GetUtcOffset(dt).TotalMilliseconds;
                    dt = dt.AddMilliseconds(utcOffset - sign * zone);
                }
            }
            return dt;
        }
示例#57
0
 public ExpressionStatement CreateSuperConstructorInvocation(IConstructor defaultConstructor)
 {
     var call = new MethodInvocationExpression(new SuperLiteralExpression());
     call.Target.Entity = defaultConstructor;
     call.ExpressionType = TypeSystemServices.VoidType;
     return new ExpressionStatement(call);
 }
示例#58
0
        public static object ConstructYamlInt(IConstructor ctor, Node node) {
            string value = ctor.ConstructScalar(node).ToString().Replace("_","").Replace(",","");
            int sign = +1;
            char first = value[0];
            if(first == '-') {
                sign = -1;
                value = value.Substring(1);
            } else if(first == '+') {
                value = value.Substring(1);
            }
            int @base = 10;
            if (value == "0") {
                return 0;
            } else if (value.StartsWith("0b")) {
                value = value.Substring(2);
                @base = 2;
            } else if (value.StartsWith("0x")) {
                value = value.Substring(2);
                @base = 16;
            } else if (value.StartsWith("0")) {
                value = value.Substring(1);
                @base = 8;
            } else if (value.IndexOf(':') != -1) {
                string[] digits = value.Split(':');
                int bes = 1;
                int val = 0;
                for (int i = 0, j = digits.Length; i < j; i++) {
                    val += (int.Parse(digits[(j - i) - 1]) * bes);
                    bes *= 60;
                }
                return sign*val;
            }

            try {
                // LiteralParser.ParseInteger delegate handles parsing & conversion to BigInteger (if needed)
                return LiteralParser.ParseInteger(sign, value, @base);
            } catch (Exception e) {
                throw new ConstructorException(string.Format("Could not parse integer value: '{0}' (sign {1}, base {2})", value, sign, @base), e);
            }
        }
        /// <summary>
        /// Obtains a reflection wrapper for a constructor.
        /// </summary>
        /// <param name="target">The constructor, or null if none.</param>
        /// <returns>The reflection wrapper, or null if none.</returns>
        public StaticConstructorWrapper Wrap(IConstructor target)
        {
            if (target == null)
                return null;

            StaticDeclaredTypeWrapper declaringType = MakeDeclaredTypeWithoutSubstitution(target.GetContainingType());
            return new StaticConstructorWrapper(this, target, declaringType);
        }
示例#60
0
 public static object ConstructYamlFloat(IConstructor ctor, Node node) {
     string value = ctor.ConstructScalar(node).ToString().Replace("_", "").Replace(",", "");
     int sign = +1;
     char first = value[0];
     if (first == '-') {
         sign = -1;
         value = value.Substring(1);
     } else if (first == '+') {
         value = value.Substring(1);
     }
     string valLower = value.ToLower();
     if (valLower == ".inf") {
         return sign == -1 ? double.NegativeInfinity : double.PositiveInfinity;
     } else if (valLower == ".nan") {
         return double.NaN;
     } else if (value.IndexOf(':') != -1) {
         string[] digits = value.Split(':');
         int bes = 1;
         double val = 0.0;
         for (int i = 0, j = digits.Length; i < j; i++) {
             val += (double.Parse(digits[(j - i) - 1]) * bes);
             bes *= 60;
         }
         return sign * val;
     } else {
         return sign * double.Parse(value);
     }
 }